Simple working example of public private key encryption
- Crypto Primer
- Cryptography/A Basic Public Key Example
- Toni Beardon - Public Key Cryptography
- Extended GCD algorithm (Extended Euclidean Algorithm)
- StackExchange - How does asymmetric encryption work?
int p = 17; // 1st large prime (larger)
int q = 13; // 2nd large prime
int pubKey1 = p*q;
int pubKey2 = 11;// < pubKey1 - 65537 is commonly used
int privKey = CalculateExtendedEuclideanAlgorithm(pubKey2, (p - 1) * (q - 1));
var cipherText = BigInteger.Pow(input, pubKey2) % pubKey1;
var plainText = (char)(BigInteger.Pow(cipherText, privKey) % pubKey1);