示例#1
0
 public static BigInteger GenerateRandomCoprime(BigInteger other)
 {
     for (var i = 0; i < 100; ++i)
     {
         var result = GenetateRandomPrime(2, other - 1, MillerRabin);
         if (Algos.EuclidExtended(other, result, out BigInteger temp1, out BigInteger temp2) == 1)
         {
             return(result);
         }
     }
     return(65537);
 }
示例#2
0
        static public BigInteger Inverse(BigInteger n, BigInteger m)
        {
            if (n < 0)
            {
                return(m - Inverse(-n, m));
            }
            var gcd = Algos.EuclidExtended(n, m, out BigInteger x, out BigInteger y);

            if ((n * x + m * y) % m != gcd || gcd != 1)
            {
                throw new InvalidProgramException("Inverse don't exist");
            }
            return(x % m);
        }