Exemplo n.º 1
0
        public static bool MillerRabinPass(BigInteger iWitness, BigInteger iNum)
        {
            BigInteger d = iNum - 1;
            int        s = d.CountBinaryTrailingZeros();

            d >>= s;
            BigInteger iWitnessPowModN = iWitness.ModPow(d, iNum);

            if (iWitnessPowModN == 1)
            {
                return(true);
            }
            for (int i = 0; i < s - 1; i++)
            {
                if (iWitnessPowModN == iNum - 1)
                {
                    return(true);
                }
                iWitnessPowModN = iWitnessPowModN.ModPow(2, iNum);
            }
            if (iWitnessPowModN == iNum - 1)
            {
                return(true);
            }
            return(false);
        }