RSA
Wikipedia · RSA (cryptosystem) · CC BY-SA 4.0
RSA is an asymmetric cipher: the encryption key (public) and decryption key (private) are different. Anyone can encrypt a message with the public key, but only the private key holder can decrypt it. Security rests on the difficulty of factoring the product of two large primes. The math works because of Euler's theorem: med mod n = m when ed = 1 mod phi(n).
Key generation
Pick two large primes p and q. Compute n = pq and phi(n) = (p-1)(q-1). Pick e coprime to phi(n) (commonly 65537). Compute d = e-1 mod phi(n) using the extended Euclidean algorithm. Public key: (e, n). Private key: d. Discard p, q, phi(n).
Encrypt and decrypt
To encrypt message m: compute c = me mod n. To decrypt ciphertext c: compute m = cd mod n. This works because med mod n = m (by Euler's theorem, since ed = 1 mod phi(n)).
Why it works: Euler's theorem
Euler's theorem states: if gcd(m, n) = 1, then mphi(n) mod n = 1. Since ed = 1 mod phi(n), we can write ed = 1 + k*phi(n) for some integer k. Then med = m1 + k*phi(n) = m * (mphi(n))k = m * 1k = m (mod n). The security relies on the fact that computing phi(n) requires factoring n = pq, which is hard for large primes.
Neighbors
Cross-references
- 🔗 Judson Ch. 6 — rings: RSA uses modular arithmetic in Z/nZ
- # Number Theory Ch.4 — RSA correctness is a direct corollary of Euler's theorem
- ⚙ Algorithms Ch.2 — fast modular exponentiation is the algorithmic heart
- 🔀 Theory of Computation Ch.8 — RSA security assumes integer factorization is not in P
Foundations (Wikipedia)