public static void BruteForce(CurvePoint g, BigInteger iterations) { Console.WriteLine($"G: {g.Point}"); var p = new Point(g.Point.XCoordinate, g.Point.YCoordinate); var m = g.Curve.CalculateMultiplication(g.Point, iterations); for (var i = new BigInteger(2); i <= iterations; i++) { p = g.Curve.CalculateAddition(p, g.Point); var right = g.Curve.CalculateRightSideOfEquality(p); var ys = right.FindModularSquareRoots(g.Curve.Modulo); var on1 = g.Curve.IsOnCurve(new Point(p.XCoordinate, ys.Item1)); var on2 = g.Curve.IsOnCurve(new Point(p.XCoordinate, ys.Item2)); Console.WriteLine($"Y1: {on1}, Y2: {on2}, Original: {ys.Item1 == p.YCoordinate}, {ys.Item2 == p.YCoordinate}"); } Console.WriteLine($"Multiplication: {m}"); }
public CurvePoint MulOnScalar(BigInteger scalar) { if (scalar % ECDSA.Curve.n == 0 || IsZero) { return(new CurvePoint(true)); } if (scalar < 0) { return(Neg().MulOnScalar(-scalar)); } var point = new CurvePoint(x, y); var result = new CurvePoint(true); foreach (var bit in GetNextBit(scalar)) { if (bit == 1) { result += point; } point += point; } return(result); }