예제 #1
0
파일: MainForm.cs 프로젝트: fengwd/GNFS
        private void btnPurgeRough_Click(object sender, EventArgs e)
        {
            int before = _gnfs.CurrentRelationsProgress.RoughRelations.Count;

            _gnfs.CurrentRelationsProgress.PurgePrimeRoughRelations();

            int after = _gnfs.CurrentRelationsProgress.RoughRelations.Count;

            int quantityRemoved = before - after;

            Logging.LogMessage($"Purged {quantityRemoved} rough relations whom were prime.");

            PrintCurrentCounts();
        }
예제 #2
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (!IsWorking)
            {
                SetAsProcessing();
                //ControlBridge.SetControlEnabledState(btnCreate, false);

                n          = BigInteger.Parse(tbN.Text);
                degree     = int.Parse(tbDegree.Text);
                polyBase   = BigInteger.Parse(tbBase.Text);
                primeBound = BigInteger.Parse(tbBound.Text);

                int relationQuantity   = int.Parse(tbRelationQuantity.Text);
                int relationValueRange = int.Parse(tbRelationValueRange.Text);

                //Logging.OutputFilename = DirectoryLocations.GetUniqueNameFromN(n) + ".LOG.txt";
                //Logging.CreateLogFileIfNotExists();

                Logging.LogMessage($"[New factorization job creation initialization for N = {DirectoryLocations.GetUniqueNameFromN(n)}...]");

                CancellationToken token = cancellationTokenSource.Token;
                new Thread(() =>
                {
                    GNFS localGnfs =
                        GnfsUiBridge.CreateGnfs
                        (
                            token,                              // CancellationToken
                            n,                                  // Semi-prime to factor N = P*Q
                            polyBase,                           // Polynomial base (value for x)
                            degree,                             // Polynomial Degree
                            primeBound,                         //  BigInteger
                            relationQuantity,                   // Total # of relations to collect before proceeding.
                            relationValueRange                  //
                        );



                    SetGnfs(this, localGnfs);
                    HaultAllProcessing();
                    ControlBridge.SetControlEnabledState(panelFunctions, true);
                    Logging.LogMessage($"[New factorization job initialization complete]");
                    Logging.LogMessage($"NOTE: You should save your progress now.");
                }).Start();
            }
        }
예제 #3
0
        private void btnFindSquares_Click(object sender, EventArgs e)
        {
            if (!IsWorking)
            {
                SetAsProcessing();

                Logging.LogMessage("[Find square root task starting up...]");

                GNFS localGnfs          = gnfs;
                CancellationToken token = cancellationTokenSource.Token;
                new Thread(() =>
                {
                    GNFS resultGnfs = GnfsUiBridge.FindSquares(token, localGnfs);

                    SetGnfs(this, resultGnfs);
                    HaultAllProcessing();
                    Logging.LogMessage("[Find square root task complete]");
                }).Start();
            }
        }
예제 #4
0
파일: MainForm.cs 프로젝트: fengwd/GNFS
        private void btnMatrix_Click(object sender, EventArgs e)
        {
            if (!IsWorking)
            {
                SetAsProcessing();

                Logging.LogMessage("[Matrix solve task starting up...]");

                GNFS localGnfs          = _gnfs;
                CancellationToken token = _cancellationTokenSource.Token;
                new Thread(() =>
                {
                    GNFS resultGnfs = GnfsUiBridge.MatrixSolveGaussian(token, localGnfs);

                    SetGnfs(this, resultGnfs);
                    HaultAllProcessing();
                    Logging.LogMessage("[Matrix solve task complete]");
                }).Start();
            }
        }
예제 #5
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            if (!IsWorking)
            {
                SetAsProcessing();
                //ControlBridge.SetControlEnabledState(btnCreate, false);

                n = BigInteger.Parse(tbN.Text);

                //Logging.OutputFilename = DirectoryLocations.GetUniqueNameFromN(n) + ".LOG.txt";
                //Logging.CreateLogFileIfNotExists();

                string jsonFilename = Path.Combine(DirectoryLocations.GetSaveLocation(n), "GNFS.json");
                Logging.LogMessage($"[Loading factorization progress from \"{jsonFilename}\"...]");

                CancellationToken token = cancellationTokenSource.Token;
                new Thread(() =>
                {
                    GNFS localGnfs = GnfsUiBridge.LoadGnfs(n);
                    SetGnfs(this, localGnfs);
                    HaultAllProcessing();
                    ControlBridge.SetControlEnabledState(panelFunctions, true);
                    Logging.LogMessage();
                    Logging.LogMessage("Counts/Quantities:");
                    Logging.LogMessage();
                    Logging.LogMessage($"Algebraic Factor Base (Quantity):\t{localGnfs.PrimeFactorBase.AlgebraicFactorBase.Count}");
                    Logging.LogMessage($"Rational Factor Base (Quantity):\t{localGnfs.PrimeFactorBase.RationalFactorBase.Count}");
                    Logging.LogMessage($"Quadratic Factor Base (Quantity):\t{localGnfs.PrimeFactorBase.QuadraticFactorBase.Count}");
                    Logging.LogMessage();
                    Logging.LogMessage($"Algebraic Factor Pairs (Quantity):\t{localGnfs.AlgebraicFactorPairCollection.Count}");
                    Logging.LogMessage($"Rational Factor Pairs (Quantity):\t{localGnfs.RationalFactorPairCollection.Count}");
                    Logging.LogMessage($"Quadratic Factor Pairs (Quantity):\t{localGnfs.QuadraticFactorPairCollection.Count}");
                    Logging.LogMessage();
                    Logging.LogMessage($"     Smooth Relations (Quantity):\t{localGnfs.CurrentRelationsProgress.SmoothRelationsCounter}");
                    Logging.LogMessage($"      Rough Relations (Quantity):\t{localGnfs.CurrentRelationsProgress.RoughRelations.Count}");
                    Logging.LogMessage($"       Free Relations (Quantity):\t{localGnfs.CurrentRelationsProgress.FreeRelationsCounter}");
                    Logging.LogMessage();
                    Logging.LogMessage("[Loading factorization progress complete]");
                }).Start();
            }
        }
예제 #6
0
파일: MainForm.cs 프로젝트: fengwd/GNFS
        private void btnLoad_Click(object sender, EventArgs e)
        {
            if (!IsWorking)
            {
                SetAsProcessing();

                BigInteger n = N;

                string jsonFilename = Path.Combine(DirectoryLocations.GetSaveLocation(n), DirectoryLocations.SaveFilename);
                Logging.LogMessage($"[Loading factorization progress from \"{jsonFilename}\"...]");

                CancellationToken token = _cancellationTokenSource.Token;

                new Thread(() =>
                {
                    GNFS localGnfs = GnfsUiBridge.LoadGnfs(n);
                    SetGnfs(this, localGnfs);
                    HaultAllProcessing();
                    ControlBridge.SetControlEnabledState(panelFunctions, true);
                    Logging.LogMessage();
                    Logging.LogMessage("Counts/Quantities:");
                    Logging.LogMessage();
                    Logging.LogMessage($"Algebraic Factor Base (MaxValue):\t{localGnfs.PrimeFactorBase.AlgebraicFactorBaseMax}");
                    Logging.LogMessage($"Rational Factor Base (MaxValue):\t{localGnfs.PrimeFactorBase.RationalFactorBaseMax}");
                    Logging.LogMessage($"Quadratic Factor Base (MaxValue):\t{localGnfs.PrimeFactorBase.QuadraticFactorBaseMax}");
                    Logging.LogMessage();
                    Logging.LogMessage($"Algebraic Factor Pairs (Quantity):\t{localGnfs.AlgebraicFactorPairCollection.Count}");
                    Logging.LogMessage($"Rational Factor Pairs (Quantity):\t{localGnfs.RationalFactorPairCollection.Count}");
                    Logging.LogMessage($"Quadratic Factor Pairs (Quantity):\t{localGnfs.QuadraticFactorPairCollection.Count}");
                    Logging.LogMessage();
                    Logging.LogMessage($"     Smooth Relations (Quantity):\t{localGnfs.CurrentRelationsProgress.SmoothRelationsCounter}");
                    Logging.LogMessage($"      Rough Relations (Quantity):\t{localGnfs.CurrentRelationsProgress.RoughRelations.Count}");
                    Logging.LogMessage($"       Free Relations (Quantity):\t{localGnfs.CurrentRelationsProgress.FreeRelationsCounter}");
                    Logging.LogMessage();
                    Logging.LogMessage("[Loading factorization progress complete]");
                    PrintCurrentCounts();
                    RefreshLoadSaveButtonState();
                }).Start();
            }
        }
예제 #7
0
파일: FindSquares.cs 프로젝트: be4/GNFS
        public static GNFS FindSquares(CancellationToken cancelToken, GNFS gnfs)
        {
            if (cancelToken.IsCancellationRequested)
            {
                return(gnfs);
            }

            Logging.LogMessage();
            Logging.LogMessage($"# of solution sets: {gnfs.CurrentRelationsProgress.FreeRelations.Count}");
            Logging.LogMessage();

            BigInteger polyBase = gnfs.PolynomialBase;

            List <List <Relation> > freeRelations = gnfs.CurrentRelationsProgress.FreeRelations;

            // Below randomly selects a solution set to try and find a square root of the polynomial in.

            // Each time this step is stopped and restarted, it will try a different solution set.
            // Previous used sets are tracked with the List<int> triedFreeRelationIndices

            if (triedFreeRelationIndices.Count == freeRelations.Count)             // If we have exhausted our solution sets, alert the user. Number wont factor for some reason.
            {
                Logging.LogMessage("ERROR: ALL RELATION SETS HAVE BEEN TRIED...?");
                Logging.LogMessage($"If the number of solution sets ({freeRelations.Count}) is low, you may need to sieve some more and then re-run the matrix solving step.");
                Logging.LogMessage("If there are many solution sets, and you have tried them all without finding non-trivial factors, then something is wrong...");
                Logging.LogMessage();
                return(gnfs);
            }

            int freeRelationIndex = 0;

            do
            {
                freeRelationIndex = StaticRandom.Next(0, freeRelations.Count);
            }while (triedFreeRelationIndices.Contains(freeRelationIndex));

            triedFreeRelationIndices.Add(freeRelationIndex);                             // Add current selection to our list

            List <Relation> selectedRelationSet = freeRelations[freeRelationIndex];      // Get the solution set

            SquareFinder squareRootFinder = new SquareFinder(gnfs, selectedRelationSet); // If you want to solve for a new solution set, create a new instance

            Logging.LogMessage($"Selected solution set # {freeRelationIndex + 1}");
            Logging.LogMessage();
            Logging.LogMessage($"Selected set (a,b) pairs (count: {selectedRelationSet.Count}): {string.Join(" ", selectedRelationSet.Select(rel => $"({rel.A},{rel.B})"))}");
            Logging.LogMessage();
            Logging.LogMessage();
            Logging.LogMessage();
            Logging.LogMessage($"ƒ'(m)     = {squareRootFinder.PolynomialDerivative}");
            Logging.LogMessage($"ƒ'(m)^2   = {squareRootFinder.PolynomialDerivativeSquared}");
            Logging.LogMessage();
            Logging.LogMessage("Calculating Rational Square Root.");
            Logging.LogMessage("Please wait...");

            squareRootFinder.CalculateRationalSide();

            Logging.LogMessage("Completed.");
            Logging.LogMessage();
            Logging.LogMessage($"γ²        = {squareRootFinder.RationalProduct} IsSquare? {squareRootFinder.RationalProduct.IsSquare()}");
            Logging.LogMessage($"(γ  · ƒ'(m))^2 = {squareRootFinder.RationalSquare} IsSquare? {squareRootFinder.RationalSquare.IsSquare()}");
            Logging.LogMessage();
            Logging.LogMessage();
            Logging.LogMessage("Calculating Algebraic Square Root.");
            Logging.LogMessage("Please wait...");

            Tuple <BigInteger, BigInteger> foundFactors = squareRootFinder.CalculateAlgebraicSide(cancelToken);
            BigInteger P = foundFactors.Item1;
            BigInteger Q = foundFactors.Item2;

            if (cancelToken.IsCancellationRequested && P == 1 && Q == 1)
            {
                Logging.LogMessage("Square root search aborted!");
                return(gnfs);
            }

            Logging.LogMessage("Completed.");
            Logging.LogMessage();
            Logging.LogMessage();

            if (P != 1 || Q != 1)
            {
                Logging.LogMessage("NON-TRIVIAL FACTORS FOUND!");
                Logging.LogMessage();
            }

            IPolynomial S           = squareRootFinder.S;
            IPolynomial SRingSquare = squareRootFinder.SRingSquare;

            BigInteger prodS = SRingSquare.Evaluate(polyBase);

            IPolynomial reducedS = Polynomial.Modulus(S, gnfs.N);

            BigInteger totalProdS    = squareRootFinder.TotalS.Evaluate(polyBase) * squareRootFinder.PolynomialDerivative;
            BigInteger totalProdModN = totalProdS % gnfs.N;
            BigInteger prodSmodN     = prodS % gnfs.N;

            List <BigInteger> algebraicNumberFieldSquareRoots = squareRootFinder.AlgebraicResults;

            BigInteger rationalSquareRoot  = squareRootFinder.RationalSquareRootResidue;
            BigInteger algebraicSquareRoot = squareRootFinder.AlgebraicSquareRootResidue;


            Logging.LogMessage($"∏ Sᵢ =");
            Logging.LogMessage($"{squareRootFinder.TotalS}");
            Logging.LogMessage();
            Logging.LogMessage($"∏ Sᵢ (mod ƒ) =");
            Logging.LogMessage($"{reducedS}");
            Logging.LogMessage();
            Logging.LogMessage("Polynomial ring:");
            Logging.LogMessage($"({string.Join(") * (", squareRootFinder.PolynomialRing.Select(ply => ply.ToString()))})");
            Logging.LogMessage();
            Logging.LogMessage("Primes:");
            Logging.LogMessage($"{string.Join(" * ", squareRootFinder.AlgebraicPrimes)}");             // .RelationsSet.Select(rel => rel.B).Distinct().OrderBy(relB => relB))
            Logging.LogMessage();
            Logging.LogMessage();
            Logging.LogMessage($"X² / ƒ(m) = {squareRootFinder.AlgebraicProductModF}  IsSquare? {squareRootFinder.AlgebraicProductModF.IsSquare()}");
            Logging.LogMessage();
            Logging.LogMessage($"");
            Logging.LogMessage($"AlgebraicPrimes: {squareRootFinder.AlgebraicPrimes.FormatString(false)}");
            Logging.LogMessage($"AlgebraicResults: {squareRootFinder.AlgebraicResults.FormatString(false)}");
            Logging.LogMessage($"");
            Logging.LogMessage($"*****************************");
            Logging.LogMessage($"");
            Logging.LogMessage($"AlgebraicSquareRootResidue: {squareRootFinder.AlgebraicSquareRootResidue}");
            Logging.LogMessage($"");
            Logging.LogMessage($"AlgebraicNumberFieldSquareRoots: {algebraicNumberFieldSquareRoots.FormatString(false)}");
            Logging.LogMessage($"");
            Logging.LogMessage($" RationalSquareRoot : {rationalSquareRoot}");
            Logging.LogMessage($" AlgebraicSquareRoot: {algebraicSquareRoot} ");
            Logging.LogMessage($"");
            Logging.LogMessage($"*****************************");
            Logging.LogMessage($"S (x)       = {prodSmodN}  IsSquare? {prodSmodN.IsSquare()}");
            Logging.LogMessage();
            Logging.LogMessage("Roots of S(x):");
            Logging.LogMessage($"{{{string.Join(", ", squareRootFinder.RootsOfS.Select(tup => (tup.Item2 > 1) ? $"{tup.Item1}/{tup.Item2}" : $"{tup.Item1}"))}}}");
예제 #8
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     Logging.LogMessage("[Save progress task began...]");
     Serialization.Save.All(gnfs);
     Logging.LogMessage("[Save progress task successfully completed]");
 }
예제 #9
0
 private void btnCancel_Click(object sender, EventArgs e)
 {
     HaultAllProcessing();
     Logging.LogMessage($"Processing thread CANCELED.");
 }