C#C
C#4y ago
koopa

❔ RSA Encryption Algorithm Problems

public static BigInteger modInv(BigInteger a, BigInteger b)
        {
            BigInteger g;
            BigInteger x;
            BigInteger _;
            (g, x, _) = egcd(a, b);
            return mod(x, b);
        }
        public static BigInteger mod(BigInteger x, BigInteger m)
        {
            return (x % m + m) % m;
        }

        public static BigInteger RSAEncryption(BigInteger plaintext, BigInteger pubD, BigInteger n)
        {

            BigInteger rtrn = mod(Pow(plaintext, pubD), n);
            return rtrn;
        }

        public static BigInteger RSADecryption(BigInteger ciphertext, BigInteger privD, BigInteger n)
        {

            BigInteger rtrn = mod(Pow(ciphertext, privD), n);
            return rtrn;
        }


        public static BigInteger Pow(BigInteger value, BigInteger exponent)
        {
            BigInteger originalValue = value;
            while (exponent-- > 1)
                value = BigInteger.Multiply(value, originalValue);
            return value;
        }
     
    }
Was this page helpful?