Esempio n. 1
0
        public SVDRecommender(DataModel dataModel, Factorizer factorizer, CandidateItemsStrategy candidateItemsStrategy, PersistenceStrategy persistenceStrategy)
            : base(dataModel, candidateItemsStrategy)
        {
            Action refreshRunnable = null;

            this.factorizer          = factorizer;
            this.persistenceStrategy = persistenceStrategy;
            try
            {
                this.factorization = persistenceStrategy.load();
            }
            catch (IOException exception)
            {
                throw new TasteException("Error loading factorization", exception);
            }
            if (this.factorization == null)
            {
                this.train();
            }
            if (refreshRunnable == null)
            {
                refreshRunnable = () => this.train();
            }
            this.refreshHelper = new RefreshHelper(refreshRunnable);
            this.refreshHelper.addDependency(this.getDataModel());
            this.refreshHelper.addDependency(factorizer);
            this.refreshHelper.addDependency(candidateItemsStrategy);
        }
Esempio n. 2
0
        public void SmallestMultiple_Values()
        {
            var fact = new Factorizer();

            Assert.Equal(2520, fact.SmallestMultiple(1, 10));
            Assert.Equal(232792560, fact.SmallestMultiple(1, 20));
        }
Esempio n. 3
0
        public void AtikinSieve_Values()
        {
            var fact = new Factorizer();

            Assert.Equal(new long[] { 2, 3, 5, 7 }, fact.AtikinSieve(10));
            Assert.Equal(new long[] { 2, 3, 5, 7, 11, 13, 17, 19 }, fact.AtikinSieve(20));
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var configurator                  = new Configurator();
            var exceptionHandler              = new ExceptionHandler();
            var expressionReader              = new JsonExpressionReader();
            var algorithmReader               = new JsonAlgorithmReader();
            var calculator                    = new Factorizer();
            var divider                       = new GornersDividor();
            var writer                        = new MathMlWriter();
            var drawerDataInitializer         = new DrawerDataInitializer();
            var drawer                        = new Drawer();
            var userAlgorithmStrategyProvider = new UserAlgorithmStrategyProvider();

            configurator.Configure(exceptionHandler);

            var factors        = expressionReader.Read(configurator.InputExpressionFile);
            var algorithm      = algorithmReader.Read(configurator.InputAlgorithmExpressionFile);
            var grephicDataSet = algorithmReader.Read(configurator.InputGraphicDataSetExpressionFile);

            var decomposed = calculator.Execute(factors, divider, algorithm, userAlgorithmStrategyProvider);

            writer.Write(decomposed, configurator.OutpuExpressiontFile);

            var drawerData = drawerDataInitializer.GetDrawerData(grephicDataSet, userAlgorithmStrategyProvider);

            //var drawerData = drawerDataInitializer.GetDrawerData(factors, start, end, step);
            drawer.Draw(drawerData);
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            long n = Convert.ToInt64(Console.ReadLine());

            Factorizer factorizer       = new Factorizer(new MillerRabin(40), new QuantumOrderFinder());
            Dictionary <long, long> res = factorizer.Run(n);

            foreach (KeyValuePair <long, long> kvp in res)
            {
                Console.WriteLine(kvp.Key.ToString() + ": " + kvp.Value.ToString());
            }
        }
Esempio n. 6
0
        public static async Task <Step2Result> Do(ResPq resPq, Int256 newNonce, MtProtoPlainTransport transport)
        {
            var pqBts = resPq.Pq.ToArrayUnsafe();

            Helpers.Assert(pqBts.Length <= 8, "auth step2: pq is too big");
            var pq = new BigInteger(1, pqBts);

            var(pLong, qLong) = Factorizer.Factorize((ulong)pq.LongValue);
            var p = new BigInteger(pLong);
            var q = new BigInteger(qLong);

            var pqInnerData = new PqInnerData.DefaultTag(
                pq: resPq.Pq,
                p: p.ToByteArrayUnsigned().ToBytesUnsafe(),
                q: q.ToByteArrayUnsigned().ToBytesUnsafe(),
                nonce: resPq.Nonce,
                serverNonce: resPq.ServerNonce,
                newNonce: newNonce
                );
            var pqInnerDataBts = Serialize((PqInnerData)pqInnerData);

            var fingerprint = resPq.ServerPublicKeyFingerprints.TryFind(x => x == TgServerRsaKey.Fingerprint)
                              ?? throw Helpers.FailedAssertion(
                                        $"auth step2: can not find a key for fingerprints: {string.Join(", ", resPq.ServerPublicKeyFingerprints.Select(x => x.ToString("x16")))}"
                                        );
            var cipherText = Rsa.Encrypt(TgServerRsaKey.Key, pqInnerDataBts);

            var resp = await transport.Call(new ReqDhParams(
                                                nonce : pqInnerData.Nonce,
                                                serverNonce : pqInnerData.ServerNonce,
                                                p : pqInnerData.P,
                                                q : pqInnerData.Q,
                                                publicKeyFingerprint : fingerprint,
                                                encryptedData : cipherText.ToBytesUnsafe()
                                                )).ConfigureAwait(false);

            var res = resp.Match(
                okTag: x => x,
                failTag: _ => throw Helpers.FailedAssertion("auth step2: server_DH_params_fail")
                );

            Helpers.Assert(res.Nonce == pqInnerData.Nonce, "auth step2: invalid nonce");
            Helpers.Assert(res.ServerNonce == pqInnerData.ServerNonce, "auth step2: invalid server nonce");

            return(new Step2Result(res, newNonce));
        }
Esempio n. 7
0
    public void Run()
    {
        BeforeProcessing();

        long number = 0L;
        try
        {
            number = long.Parse(NumberTextBox.Text);
        }
        catch
        {
            try
            {
                // evaluate expression and display result and continue
                string result = Calculator.Evaluate(NumberTextBox.Text);
                number = (long)Math.Round((double.Parse(result)));
                NumberTextBox.Text = number.ToString();

                NumberTextBox.SelectionStart = NumberTextBox.Text.Length;
                NumberTextBox.SelectionLength = 0;
                NumberTextBox.Refresh();
            }
            catch
            {
                // force calcellation programmatically
                number = -1L;
                Stop();
            }
        }

        m_factorizer = new Factorizer(this, number);
        if (m_factorizer != null)
        {
            m_worker_thread = new Thread(new ThreadStart(m_factorizer.Run));
            m_worker_thread.Priority = ThreadPriority.Lowest;
            m_worker_thread.IsBackground = true;
            m_worker_thread.Start();
        }
    }
Esempio n. 8
0
 private void MainForm_Load(object sender, EventArgs e)
 {
     m_factorizer = null;
     m_worker_thread = null;
 }
Esempio n. 9
0
 public SVDRecommender(DataModel dataModel, Factorizer factorizer, CandidateItemsStrategy candidateItemsStrategy)
     : this(dataModel, factorizer, candidateItemsStrategy, getDefaultPersistenceStrategy())
 {
 }
Esempio n. 10
0
 public SVDRecommender(DataModel dataModel, Factorizer factorizer, PersistenceStrategy persistenceStrategy)
     : this(dataModel, factorizer, AbstractRecommender.getDefaultCandidateItemsStrategy(), persistenceStrategy)
 {
 }
Esempio n. 11
0
 public void Initialize()
 {
     testObject = (new Factorizer());
 }
Esempio n. 12
0
 public static Dictionary <long, Factorization> Of(IEnumerable <long> numbers)
 {
     return(Factorizer.Factorize(numbers));
 }
Esempio n. 13
0
 public static Factorization Of(long number)
 {
     return(Factorizer.Factorize(number));
 }
 public static void Init(IPrimeChecker primeChecker, IOrderFinder orderFinder)
 {
     factorizer = new Factorizer(primeChecker, orderFinder);
 }