We have two key pairs (the public key pair and the private key pairs) such that they are mathematically related.
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.
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.
Choose two prime numbers: 2, 7 [p, q]
n = 2 x 7 [p.q]
Calculate Euler’s Totient (Φ) = 6 [(p-1)(q-1)]
Choose e such that:
1 < e < Φ(n)
e is co-prime with n, Φ(n)
e comes out to be 5
Choose d such that:
d.e mod Φ(n) = 1
d comes out to be 5, 11, 17, 23, ……
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.