コード例 #1
0
        public static List <BigInteger> GetPrimeFactors(BigInteger p)
        {
            var list = new List <BigInteger>();

            if (p % 2 == 0)
            {
                list.Add(2);
                while (p % 2 == 0)
                {
                    p = p / 2;
                }
            }
            for (int i = 3; i <= BigIntegerExtension.Sqrt(p) + 1; i = i + 2)
            {
                if (p % i == 0)
                {
                    list.Add(i);
                    while (p % i == 0)
                    {
                        p = p / i;
                    }
                }
            }
            if (p > 2)
            {
                list.Add(p);
            }
            return(list);
        }
コード例 #2
0
        public static BigInteger SolveLinearEquatation(DLPInput input, BigInteger logatithmicExpression, BigInteger a, BigInteger b)
        {
            var mod = input.order;
            var gcd = BigInteger.GreatestCommonDivisor(a, mod);

            if (gcd == -1)
            {
                return((b * a.ModInverse(mod)).ModPositive(mod));
            }
            else
            {
                //return 1;
                Console.WriteLine(gcd);
                BigInteger u, v;
                BigIntegerExtension.ExtendedGcd(a, mod, out u, out v);
                var reducedMOD = mod / gcd;
                var x0         = ((b / gcd) * u).ModPositive(reducedMOD);
                for (BigInteger j = 0; j < gcd; j++)
                {
                    var x = x0 + j * reducedMOD;
                    // Console.WriteLine(x);
                    if (BigInteger.ModPow(input.g, x, input.p) == logatithmicExpression)
                    {
                        return(x);
                    }
                }
            }
            return(-1);
        }