RSA/Intuative
The algorithm is based on a Fermat's little theorem
- a(p−1) ≡ 1 (mod p)
p prime, a & p coprime.
So, if we choose d such that
- ed ≡ 1 (mod p − 1)
i.e.
- ed − 1 = k(p−1)
Then for a message m
- med ≡ med ≡ m(ed−1) ⋅ m1 ≡ mk(p−1)m ≡ 1km ≡ m (mod p)
So a message that is encrypted by raising m to e can be decrypted by raising the result to d.
In order to provide security, RSA actually calulates
- n = pq
(p, q prime) and then d such that
- ed ≡ 1 (mod (p−1)(q−1))
so
- ed − 1 = k(p−1)(q−1)
We can then continue to calculate
- med ≡ med ≡ m(ed−1)m ≡ mk(p−1)(q−1)m ≡ 1k(q−1)m ≡ m (mod p)
And likewise for q
- med ≡ med ≡ m(ed−1)m ≡ mk(p−1)(q−1)m ≡ 1k(p−1)m ≡ m (mod q)
Now if a ≡ b (mod p) and a ≡ b (mod q) then a ≡ b (mod pq), p, q coprime.
so
- med ≡ m (mod pq)
An attacker would need to factor n into p and q in order to determine d, and this is a hard problem.
Note that while an attacker could easily calculate f as
- ef ≡ 1 (mod n − 1)
that
- mef ≡ mk(n−1)m ≠ m (mod n)
because n is not prime.