← Iris

1 Key Generation
Preset prime pairs
Compute the modulus
n = p × q = ? × ? = ?
Compute Euler's totient
φ(n) = (p−1) × (q−1) = ? × ? = ?
Choose public exponent (coprime to φ(n))
e = ?
Compute private exponent via extended Euclidean algorithm
d = e−1 mod φ(n) = ?
Verify: e × d mod φ(n) = 1
? × ? mod ? = ? = ?
2 Encryption
Message to encrypt
3 Decryption

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.