Beispiel #1
0
        private void BuildPointLists()
        {
            bool       stop = false;
            BigInteger x = 0, y = 0, y2 = 0, z = 0;

            xl = new List <BigInteger>();
            yl = new List <BigInteger>();
            while (!stop)
            {
                for (int i = 0; i < NumberPts; i++)
                {
                    if (bw.CancellationPending)
                    {
                        return;
                    }
                    while (!stop)
                    {
                        if (bw.CancellationPending)
                        {
                            return;
                        }
                        x = hcr.RandomRange(1, p1);
                        z = ecs.Weierstrass(x);
                        if (z != 0)
                        {
                            y = hcr.SquareRootModPrime(z, ecs.P);
                            BigInteger test = (y * y) % ecs.P;
                            y2 = (y * y) % ecs.P;
                            if (y != 0 && z == y2)
                            {
                                stop = true;
                            }
                        }
                    }
                    xl.Add(x);
                    yl.Add(y);
                }
            }
        }
Beispiel #2
0
        private void Recurse(BigInteger p, List <BigInteger> A, ref List <BigInteger> root)
        {
            int               count = 0, degreeA = A.Count - 1, degreeB = 0;
            BigInteger        exp = 0, p1 = p - 1, D = 0, a = 0, b = 0, c = 0, e = 0;
            List <BigInteger> B = null, d = null;
            List <BigInteger> q = null, r = null, u = null;

            exp = p1 / 2;
            if (degreeA != 0)
            {
                if (degreeA == 1)
                {
                    if (A[0] != 0)
                    {
                        a = Maths.GetInverse(A[1], p);
                        b = A[0];
                        b = -b;
                        b = Maths.MulMod(b, a, p);
                        root.Add(b);
                    }
                }
                else if (degreeA == 2)
                {
                    a = Maths.MulMod(A[1], A[1], p);
                    b = Maths.MulMod(A[0], A[2], p);
                    c = Maths.MulMod(b, 4, p);
                    D = Maths.SubMod(a, c, p);
                    e = hcr.SquareRootModPrime(D, p);
                    BigInteger test = (e * e) % p;
                    if (e == 1)
                    {
                        return;
                    }
                    a = Maths.MulMod(A[2], 2, p);
                    D = Maths.GetInverse(a, p);
                    if (D == 0)
                    {
                        a = -a;
                        a = Maths.AddMod(a, p, p);
                        D = Maths.GetInverse(a, p);
                    }
                    a = Maths.SubMod(e, A[1], p);
                    root.Add(Maths.MulMod(a, D, p));
                    A[1] = -A[1];
                    e    = -e;
                    a    = Maths.AddMod(A[1], e, p);
                    root.Add(Maths.MulMod(a, D, p));
                }
                else
                {
                    do
                    {
                        count++;
                        a = hcr.RandomRange(0, p1);
                        u = new List <BigInteger>();
                        u.Add(a);
                        u.Add(1);
                        PolyPowMod(p, exp, u, A, ref d);
                        if (d.Count - 1 != 0)
                        {
                            d[0] = Maths.SubMod(d[0], 1, p);
                            B    = PolyGCDMod(p, d, A);
                            if (B.Count == 1 && B[0] == 1)
                            {
                                return;
                            }
                            degreeB = B.Count - 1;
                        }
                    }while (count < 16 && degreeB == 0 || degreeB == degreeA);
                    if (count == 16)
                    {
                        return;
                    }
                    Recurse(p, B, ref root);
                    PolyDivMod(p, A, B, ref q, ref r);
                    Recurse(p, q, ref root);
                }
            }
        }