}//first & second stage public static BigInteger GetFactorProjective(BigInteger n, int B1, int B2) { BigInteger x, y, g; var E = EllipticCurveWeierstrass.GenerateCurveRandom(n, out x, out y, out g, false); var P = new PointProjective(x, y, E); if (g > 1 && g < n) { return(g); } //STEP 1 var P1 = P as IPoint; var result = StageOneEdwardsProjective(ref P1, n, B1); if (result > 1 || result == 0) { return(result); } //STEP 2 result = StageTwoEdwardsProjective(ref P1, n, B1, B2); return(result); }//projective
public static PointProjective operator *(BigInteger k, PointProjective P) { PointProjective R = new PointProjective(0, 1, 0, P.E); if (P.IsInfinite()) { return(R); } while (k > 0) { if (k % 2 == 1) { R += P; } k /= 2; P = Double(P); } return(R); }
public static PointProjective Double(PointProjective P)//5M + 6S + 1*a + 7add + 3*2 + 1*3 { if (P.IsInfinite()) { return(new PointProjective(0, 1, 0, P.E)); } BigInteger XX = P.x * P.x; BigInteger ZZ = P.z * P.z; BigInteger w = P.E.a * ZZ + 3 * XX; BigInteger s = 2 * P.y * P.z; BigInteger ss = s * s; BigInteger sss = s * ss; BigInteger R = P.y * s; BigInteger RR = R * R; BigInteger B = (P.x + R) * (P.x + R) - XX - RR; BigInteger h = w * w - 2 * B; BigInteger x = (h * s) % P.E.n; BigInteger y = (w * (B - h) - 2 * RR) % P.E.n; BigInteger z = sss % P.E.n; return(new PointProjective(x, y, z, P.E)); }