RSA Cryptography
Public-key cryptography made visible. Pick two prime numbers, watch the key generation math unfold step by step, then encrypt and decrypt a message — seeing every modular exponentiation along the way.
n = p × q = ? × ? = ?
φ(n) = (p−1) × (q−1) = ? × ? = ?
e = ?
d = e−1 mod φ(n) = ?
? × ? mod ? = ? = ?
Why does this work?
The Trapdoor
Multiplying two primes is easy: 61 × 53 = 3233. But given only 3233, finding which two primes produced it is much harder. RSA's security rests on this asymmetry — multiplication is a one-way function. With real RSA keys (2048+ bits), factoring the modulus is computationally infeasible.
Euler's Theorem
The magic identity is me⋅d ≡ m (mod n), which holds whenever e⋅d ≡ 1 (mod φ(n)). Euler's theorem guarantees this: for any m coprime to n, mφ(n) ≡ 1 (mod n). Since e⋅d = 1 + k⋅φ(n), raising m to that power gives back m.
Public ≠ Private
Anyone can encrypt with the public key (e, n) — you can publish it freely. Only the holder of the private key (d, n) can decrypt. You never transmit the private key. This solves the ancient key-distribution problem: two parties can communicate securely without ever sharing a secret in advance.
Why small primes here?
This demo uses 2–3 digit primes so you can see every multiplication. Real RSA uses primes with 300+ digits each, making n roughly 600 digits long. The math is identical — the scale is what provides security.