Пример #1
0
 public (BigInteger, BigInteger, BigInteger) AlicePass()
 {
     p = NumberTheoryUtils.RandomPrimeInRange(10, 10000000000000000);
     g = NumberTheoryUtils.GetGroupGenerator(p, true);
     a = NumberTheoryUtils.RandomIntegerInRange(10, 10000000000000000);
     A = BigInteger.ModPow(g, a, p);
     return(g, p, A);
 }
Пример #2
0
        public static (BigInteger, BigInteger, BigInteger, BigInteger) GetElgamalKeys()
        {
            var p = NumberTheoryUtils.RandomPrime(1);
            var g = NumberTheoryUtils.GetGroupGenerator(p, isPrime: true);
            var x = NumberTheoryUtils.RandomIntegerInRange(1, p);
            var y = BigInteger.ModPow(g, x, p);

            return(p, g, x, y);
        }
Пример #3
0
        public (BigInteger, BigInteger) Sign(byte[] M)
        {
            var m = GetDigest(M);
            var k = NumberTheoryUtils.RandomPrimeInRange(1, p - 1);
            var r = BigInteger.ModPow(g, k, p);
            var s = ((m - x * r) * k.ModInverse(p - 1)).EuclidianMod(p - 1);

            Check(M, (r, s));
            return(r, s);
        }
Пример #4
0
        public static (BigInteger, BigInteger, BigInteger) GetRsaKeys()
        {
            var p   = NumberTheoryUtils.RandomPrime();
            var q   = NumberTheoryUtils.RandomPrime();
            var n   = p * q;
            var phi = (p - 1) * (q - 1);
            var e   = NumberTheoryUtils.RandomIntegerInRange(2, phi);

            while (BigInteger.GreatestCommonDivisor(e, phi) != 1)
            {
                e = NumberTheoryUtils.RandomIntegerInRange(2, phi);
            }

            var d = e.ModInverse(phi, isCoPrime: true);

            return(n, e, d);
        }