예제 #1
0
 private long GetModularMultiplicativeInverse(long exponent, long modulus)
 {
     var res = GCD.EuclidExtended(exponent, modulus);
     if (res.D != 1)
         throw new InvalidOperationException("The greatest common divisor is not 1");
 
     return (res.X % modulus + modulus) % modulus;
 }
예제 #2
0
        public void EuclidExtendedTest()
        {
            const int a = 816;
            const int b = 2260;

            var result = GCD.EuclidExtended(a, b);

            const long expectedResult = 4;

            Assert.IsTrue(result.D == expectedResult, "Euclidean extended algorithm has incorrect result");
        }