Exemplo n.º 1
0
        public RSA(BigInt p, BigInt q)
        {
            if (p.Sign < 0 || q.Sign < 0)
            {
                throw new Exception("Numbers must be positive");
            }
            if (!BigInt.IsItSimple(p) || !BigInt.IsItSimple(q))
            {
                throw new Exception("Numbers must be simple");
            }
            n = p * q;
            var fi = (p - new BigInt("1")) * (q - new BigInt("1"));

            e = fi - new BigInt("1");
            while (!(BigInt.IsItSimple(e) && BigInt.Gcd(e, fi, out var x, out var y) == new BigInt("1")))
            {
                e -= new BigInt("2");
            }
            d = BigInt.GetInverseElementModulo(e, fi);
        }