示例#1
0
        private static void Test3Inner(int multipleCount)
        {
            const int d                      = 8;
            const int fieldOrder             = 13;
            var       projectiveEdwardsCurve = new ProjectiveEdwardsCurve(d, fieldOrder);
            var       pointsFactory          = new PointsFactory(projectiveEdwardsCurve);

            var initialPoint = pointsFactory.CreatePoint(6, 12, 2);
            var point1       = pointsFactory.CreatePoint(6, 12, 2);

            var calculator = new ProjectiveEdwardsCurvePointCalculator();

            for (var i = 0; i < multipleCount - 1; i++)
            {
                point1 = calculator.Sum(point1, initialPoint);
            }

            var point2 = calculator.Mult(multipleCount, initialPoint);

            if (point1.Equals(point2))
            {
                Console.Write(".");
                return;
            }

            throw new ArithmeticException("Точки, полученные сложением и умножение, отличаются при multipleCount = "
                                          + multipleCount);
        }
示例#2
0
        private static void Test4()
        {
            BigInteger fieldOrder = BigInteger.Parse("73928303") * BigInteger.Parse("73928293");
            BigInteger x          = 3;
            BigInteger y          = 2;
            BigInteger z          = 1;

            var d = ((x * x * z * z + y * y * z * z - z * z * z * z) * (x * x * y * y).Inverse(fieldOrder)).Mod(fieldOrder);

            const int multipleCount = 73928303;

            var projectiveEdwardsCurve = new ProjectiveEdwardsCurve(d, fieldOrder);
            var pointsFactory          = new PointsFactory(projectiveEdwardsCurve);

            var calculator   = new ProjectiveEdwardsCurvePointCalculator();
            var initialPoint = pointsFactory.CreatePoint(x, y, z);
            var point1       = pointsFactory.CreatePoint(x, y, z);

            for (var i = 0; i < multipleCount - 1; i++)
            {
                point1 = calculator.Sum(point1, initialPoint);

                var gcd = BigInteger.GreatestCommonDivisor(point1.ParameterZ, fieldOrder);
                if (gcd != BigInteger.One)
                {
                    Console.WriteLine("divider = " + gcd);
                    return;
                }

                //  Console.WriteLine(point1);
                //  Console.WriteLine(point1.ToEdwardsCurvePoint());
            }
        }
示例#3
0
        private static void Test2()
        {
            const int d          = 8;
            const int fieldOrder = 13;

            var projectiveEdwardsCurve = new ProjectiveEdwardsCurve(d, fieldOrder);
            var pointsFactory          = new PointsFactory(projectiveEdwardsCurve);

            var point1 = pointsFactory.CreatePoint(6, 12, 2);
            var point2 = projectiveEdwardsCurve.NeitralPoint;

            var calculator = new ProjectiveEdwardsCurvePointCalculator();

            var sum = calculator.Sum(point1, point2);

            Console.WriteLine(sum);
            Console.WriteLine(sum.ToEdwardsCurvePoint());
        }
示例#4
0
        /// <summary> Тест на корректность суммирования </summary>
        private static void Test1()
        {
            var d          = 8;
            var fieldOrder = 13;

            var projectiveEdwardsCurve = new ProjectiveEdwardsCurve(d, fieldOrder);
            var pointsFactory          = new PointsFactory(projectiveEdwardsCurve);

            var point1 = pointsFactory.CreatePoint(3, 6, 1);
            var point2 = pointsFactory.CreatePoint(6, 3, 1);

            var calculator = new ProjectiveEdwardsCurvePointCalculator();

            var sum = calculator.Sum(point1, point2);

            Console.WriteLine(sum);
            Console.WriteLine(sum.ToEdwardsCurvePoint());
        }
示例#5
0
        private static void Test5()
        {
            BigInteger fieldOrder = BigInteger.Parse("73928303") * BigInteger.Parse("73928293");
            BigInteger x          = 3;
            BigInteger y          = 2;
            BigInteger z          = 1;

            var d = ((x * x * z * z + y * y * z * z - z * z * z * z) * (x * x * y * y).Inverse(fieldOrder)).Mod(fieldOrder);

            var projectiveEdwardsCurve = new ProjectiveEdwardsCurve(d, fieldOrder);
            var pointsFactory          = new PointsFactory(projectiveEdwardsCurve);

            var calculator = new ProjectiveEdwardsCurvePointCalculator();
            var point1     = pointsFactory.CreatePoint(x, y, z);

            var        b1 = 73928303;
            BigInteger p  = 2;

            while (p < b1)
            {
                var pr = p;
                while (pr < b1)
                {
                    point1 = calculator.Mult(p, point1);

                    var gcd = BigInteger.GreatestCommonDivisor(point1.ParameterZ, fieldOrder);
                    if (gcd != BigInteger.One)
                    {
                        Console.WriteLine("divider = " + gcd);
                        return;
                    }

                    pr *= p;
                }
                p = BigIntegerExtensions.NextPrimaryMillerRabin(p);
            }
        }
        public LenstraFactorizationResult GetDividerWithCancel(BigInteger n, Random random, CancellationToken token)
        {
            var startTime = DateTime.Now;

            BigInteger x, y, z, d;

            do
            {
                x = BigIntegerExtensions.GetNextRandom(random, n);
                y = BigIntegerExtensions.GetNextRandom(random, n);
                z = BigIntegerExtensions.GetNextRandom(random, n);
                d = ((x * x * z * z + y * y * z * z - z * z * z * z) * (x * x * y * y).Inverse(n)).Mod(n);
            } while (d == 1 || d == 0);

            var           projectiveEdwardsCurve = new ProjectiveEdwardsCurve(d, n);
            PointsFactory pointsFactory;

            try
            {
                pointsFactory = new PointsFactory(projectiveEdwardsCurve);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine("d = " + d);
                Console.WriteLine("x = " + x);
                Console.WriteLine("y = " + y);
                Console.WriteLine("z = " + z);
                throw;
            }

            var calculator = new ProjectiveEdwardsCurvePointCalculator();
            var point1     = pointsFactory.CreatePoint(x, y, z);

            BigInteger p         = 2;
            BigInteger step      = 1;
            long       iteration = 0;

            while (p < B1 && !token.IsCancellationRequested)
            {
                var pr = p;
                while (pr < B1 && !token.IsCancellationRequested)
                {
                    point1 = calculator.Mult(p, point1);

//                    if (iteration++ % step != 0)
//                    {
//                        pr *= p;
//                        continue;
//                    }

                    pr *= p;
                    if (point1.ParameterX == BigInteger.Zero)
                    {
                        continue;
                    }

                    // вычисляем НОД только через каждые step итераций, т.к. НОД уменьшает производительность
                    // пока это не будет реализовано
                    var gcd = BigInteger.GreatestCommonDivisor(point1.ParameterX, n);
                    if (gcd != BigInteger.One)
                    {
                        return(new LenstraFactorizationResult
                        {
                            EllepticCurve = projectiveEdwardsCurve,
                            TargetNumber = n,
                            Divider = gcd,
                            WastedTime = DateTime.Now - startTime,
                            EndType = EEndType.RunToComplete
                        });
                    }
                }

                p = BigIntegerExtensions.NextPrimaryMillerRabin(p);
            }

            return(new LenstraFactorizationResult
            {
                EllepticCurve = projectiveEdwardsCurve,
                TargetNumber = n,
                WastedTime = DateTime.Now - startTime,
                EndType = token.IsCancellationRequested ? EEndType.Cancelled : EEndType.RunToComplete
            });
        }