예제 #1
0
        static void MyQuadraticsTest()
        {
            BigInteger   N        = 9028325;
            int          B        = 35;
            SieveRequest sievereq = new SieveRequest();

            QuadraticSieve.InitSievingRequest(N, B, x => x * x - N, sievereq);
            QuadraticSieve.SegmentSievingRequest((int)N.Sqrt() + 1, B << 5, sievereq);
            SievingData sievedat = new SievingData();

            QuadraticSieve.Sieve(sievereq, sievedat);
            SieveResult sieveres = new SieveResult();

            QuadraticSieve.CreateFormattedSievingResult(sievereq, sievedat, sieveres);
            printarr(sieveres.V);
            printarr(sieveres.SmoothRelations);
            Console.WriteLine();
            SolveRequest solvereq = new SolveRequest();

            QuadraticSieve.InitSolveRequest(sievereq.B, sieveres.V.Count, solvereq);
            QuadraticSieve.AddDataToSolveRequest(sieveres, solvereq);
            printarr(solvereq.Coefficients);
            Console.WriteLine();
            QuadraticSieve.Gaussian(solvereq);
            printarr(solvereq.Coefficients);
            Console.WriteLine("First free = " + solvereq.FirstFree);
        }
예제 #2
0
 public static void Gaussian(SolveRequest solvereq)
 {
     for (int i = 0; i < Math.Min(solvereq.B, solvereq.L); i++)
     {
         if (solvereq.Coefficients[i][i] == 0)
         {
             for (int j = i + 1; j < solvereq.B; j++)
             {
                 if (solvereq.Coefficients[j][i] == 1)
                 {
                     BinaryVector tmp = solvereq.Coefficients[j];
                     solvereq.Coefficients[j] = solvereq.Coefficients[i];
                     solvereq.Coefficients[i] = tmp;
                     break;
                 }
             }
         }
         if (solvereq.Coefficients[i][i] == 1)
         {
             solvereq.FirstFree = i;
             for (int j = 0; j < solvereq.B; j++)
             {
                 if (j != i)
                 {
                     if (solvereq.Coefficients[j][i] == 1)
                     {
                         BinaryVector.FastAdd(solvereq.Coefficients[j], solvereq.Coefficients[i]);
                     }
                 }
             }
         }
     }
 }
예제 #3
0
 static void Main(string[] args)
 {
     QuadraticSieve.primeSupply = new derpy();
     BigInteger N = 90283;
     int B = 14;
     SieveRequest sievereq = new SieveRequest();
     QuadraticSieve.InitSievingRequest(N, B, x => x * x - N, sievereq);
     QuadraticSieve.SegmentSievingRequest(0, 60, sievereq);
     SievingData sievedat = new SievingData();
     QuadraticSieve.EvaluatePoly(sievereq, sievedat);
     QuadraticSieve.Sieve(sievereq, sievedat);
     SieveResult sieveres = new SieveResult();
     QuadraticSieve.CreateFormattedSievingResult(sievereq, sievedat, sieveres);
     printarr(sieveres.V);
     printarr(sieveres.SmoothRelations);
     Console.WriteLine();
     SolveRequest solvereq = new SolveRequest();
     QuadraticSieve.InitSolveRequest(sievereq.B, sieveres.V.Count, solvereq);
     QuadraticSieve.AddDataToSolveRequest(sieveres, solvereq);
     printarr(solvereq.Coefficients);
     Console.WriteLine();
     QuadraticSieve.Gaussian(solvereq);
     printarr(solvereq.Coefficients);
     Console.ReadLine();
 }
예제 #4
0
 public static void AddDataToSolveRequest(SieveResult data, SolveRequest solvereq)
 {
     //transpose matrix, add it to the coefficients (making sure to offset by startIdx of data)
     solvereq.V.AddRange(solvereq.V);
     for (int i = 0; i < data.V.Count; i++)
     {
         for (int j = 0; j < data.SourceRequest.B; j++)
         {
             solvereq.Coefficients[j][i + solvereq.V.Count] = data.SmoothRelations[i][j];
         }
     }
 }
예제 #5
0
 public static void InitSolveRequest(int rows, int columns, SolveRequest solvereq)
 {
     solvereq.B            = rows;
     solvereq.L            = columns;
     solvereq.Coefficients = new BinaryVector[rows];
     solvereq.V            = new List <BigInteger>();
     solvereq.FirstFree    = 0;
     for (int i = 0; i < rows; i++)
     {
         solvereq.Coefficients[i] = new BinaryVector(columns);
     }
 }
예제 #6
0
        /// <summary>
        /// Finds the null space of a matrix in row echelon form
        /// </summary>
        /// <param name="rowEchelon">A SolveRequest, which has already been converted to row echelon form</param>
        /// <param name="solveres">Where the null space will be stored</param>
        public static void BackSubsitution(SolveRequest rowEchelon, SolveResult solveres)
        {

        }
예제 #7
0
 /// <summary>
 /// Performs gaussian elimination to reduce a matrix to row echelon form
 /// </summary>
 /// <param name="solvereq">The SolveRequest to reduce</param>
 public static void Gaussian(SolveRequest solvereq)
 {
     for (int i = 0; i < Math.Min(solvereq.B, solvereq.L); i++)
     {
         if (solvereq.Coefficients[i][i] == 0)
         {
             for (int j = i + 1; j < solvereq.B; j++)
             {
                 if (solvereq.Coefficients[j][i] == 1)
                 {
                     BinaryVector tmp = solvereq.Coefficients[j];
                     solvereq.Coefficients[j] = solvereq.Coefficients[i];
                     solvereq.Coefficients[i] = tmp;
                 }
             }
         }
         for (int j = i + 1; j < solvereq.B; j++)
         {
             if (solvereq.Coefficients[j][i] == 1)
             {
                 BinaryVector.FastAdd(solvereq.Coefficients[j], solvereq.Coefficients[i]);
             }
         }
     }
 }
예제 #8
0
 /// <summary>
 /// Takes a SieveResult object, and adds the data to a SolveRequest object
 /// </summary>
 /// <param name="solvereq">The SieveRequest to add the data to</param>
 /// <param name="data">The data to add</param>
 public static void AddDataToSolveRequest(SieveResult data, SolveRequest solvereq)
 {
     for (int i = 0; i < data.V.Count; i++)
     {
         for (int j = 0; j < data.SourceRequest.B; j++)
         {
             solvereq.Coefficients[j][i + data.SourceRequest.StartIdx] = data.SmoothRelations[i][j];
         }
     }
 }
예제 #9
0
 /// <summary>
 /// Initializes a SolveRequest object
 /// </summary>
 /// <param name="rows">The capacity to initialize the SolveRequest to (rows)</param>
 /// <param name="columns">The capacity to initialize the SolveRequest to (columns)</param>
 /// <param name="solvereq">The SolveRequest to initialize</param>
 public static void InitSolveRequest(int rows, int columns, SolveRequest solvereq)
 {
     solvereq.B = rows;
     solvereq.L = columns;
     solvereq.Coefficients = new BinaryVector[rows];
     for (int i = 0; i < rows; i++)
     {
         solvereq.Coefficients[i] = new BinaryVector(columns);
     }
 }
예제 #10
0
 public static void BackSubsitution(SolveRequest rowEchelon, SolveResult solveres)
 {
 }