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); }
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 }); }