public int Decrypt(int p, int q, int C, int e) { long n = p * q; // Get phi(n) // Call Euclidean Extended to get d NumberTheory calc = new NumberTheory(); long d = calc.GetMultiplicativeInverse(e, calc.Phi(p, q)); // Get M = C^d mod d int M = (int)calc.FastPower(C, d, n); return(M); }