Exemple #1
0
        public static PointAffine Double(PointAffine P)
        {
            if (P.y == 0)
            {
                return(new PointAffine(0, 1, 0, P.E));
            }
            BigInteger temp = (2 * P.y) % P.E.n;

            if (temp < 0)
            {
                temp += P.E.n;
            }
            BigInteger inv;
            BigInteger d;

            Algorithms.ExtendedEuclidAlgorithm(temp, P.E.n, out inv, out d);
            if (d > 1 && d < P.E.n)
            {
                return(new PointAffine(0, 0, temp, P.E));    //делитель найден, можно прекращать вычисления
            }
            BigInteger lambda = (3 * P.x * P.x + P.E.a) * inv;
            BigInteger x      = (lambda * lambda - 2 * P.x) % P.E.n;
            BigInteger y      = (lambda * (P.x - x) - P.y) % P.E.n;

            return(new PointAffine(x, y, 1, P.E));
        }
Exemple #2
0
        public static BigInteger GetFactorAffine(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 PointAffine(x, y, E);

            if (g > 1 && g < n)
            {
                return(g);
            }
            //STEP 1
            var P1     = P as IPoint;
            var result = StageOneAffine(ref P1, n, B1);

            if (result > 1 || result == 0)
            {
                return(result);
            }

            //STEP 2
            P      = P1 as PointAffine;
            result = StageTwoAffine(ref P1, n, B1, B2);

            return(result);
        }//first & second stage
Exemple #3
0
        public static PointAffine operator *(BigInteger k, PointAffine P)
        {
            PointAffine R = new PointAffine(0, 1, 0, P.E);

            if (P.IsInfinite())
            {
                return(R);
            }
            while (k > 0)
            {
                if (P.z > 1)    //делитель найден, можно прекращать вычисления
                {
                    return(P);
                }
                if (k % 2 == 1)
                {
                    R = P + R;
                }
                k /= 2;
                P  = Double(P);//P = P + P;
            }
            return(R);
        }