We have two key pairs (the public key pair and the private key pairs) such that they are mathematically related.

Example:

Encryption

Suppose we want to encrypt 2. The cipher text would be (2^5) mod 14 (2 ^ e mod n), which is 4*.*

(2 ^ 5) % 14
32 % 14
4

Now, I can send 4 over the wire.

Decryption

The plain text for the cipher text 4 would be (4^11) mod 14 (4^d mod n), which would turn back to 2.

(4 ^ 11) % 14
4194304 % 14
2

Easy, right? The actual fun is in generating these key pairs.

Key Pair Generation

  1. Choose two prime numbers: 2, 7 [p, q]

  2. n = 2 x 7 [p.q]

  3. Calculate Euler’s Totient (Φ) = 6 [(p-1)(q-1)]

  4. Choose e such that:

  5. Choose d such that:

Euler’s Totient

Euler's Totient function (φ(n)) counts the number of integers between 1 and n that are coprime to n. Two numbers are coprime if their greatest common divisor (GCD) is 1.