Correctness is Euler's theorem
ed ≡ 1 (mod φ(n)) makes m^{ed} ≡ m (mod n), which is why decryption returns the message.
Generate n = pq, choose e coprime to φ(n), compute d = e⁻¹ mod φ(n). Encryption is m^e mod n and decryption c^d mod n. Every step is a theorem from this course, and the security is one unproved assumption.
Core ideas
RSA uses six results from this course and adds one assumption. Naming both lists is the honest way to present it.
ed ≡ 1 (mod φ(n)) makes m^{ed} ≡ m (mod n), which is why decryption returns the message.
Knowing φ(n) = (p−1)(q−1) together with n = pq gives p and q immediately. So φ(n) is as secret as the factorisation.
No proof exists that factoring is hard, and no proof exists that breaking RSA requires factoring. Both are believed and neither is established.
The material
Key generation, the correctness proof, the attacks, and the honest caveats.
Every step is a lesson from this course: primality testing from “Fermat's Little Theorem and Euler's Theorem”, the totient formula from “Fermat's Little Theorem and Euler's Theorem”, coprimality from “Greatest Common Divisor”, and the modular inverse from “Bézout's Identity and Modular Inverses”.
With the message encoded as an integer m with 0 ≤ m < n, encryption is c = m^e mod n and decryption is m = c^d mod n. Both are single modular exponentiations, computed by “Modular Exponentiation”'s algorithm.
For 0 ≤ m < n, (m^e)^d ≡ m (mod n).
ed ≡ 1 (mod φ(n)) means ed = 1 + kφ(n) for some integer k, so m^{ed} = m · (m^{φ(n)})^k.
If gcd(m, n) = 1, Euler's theorem gives m^{φ(n)} ≡ 1 (mod n), so m^{ed} ≡ m.
If gcd(m, n) ≠ 1 the argument still works via the Chinese remainder theorem: modulo p, either p | m and both sides are 0, or Fermat gives m^{p−1} ≡ 1 and m^{ed} ≡ m. The same holds modulo q, and since p and q are coprime the congruence holds modulo n.
□
Four of this course's theorems appear in that proof. RSA is not an application of number theory so much as an assembly of it.
An attacker sees n and e. To find d they need φ(n), and computing φ(n) from n is equivalent to factoring n: knowing n = pq and φ(n) = (p−1)(q−1) gives p + q = n − φ(n) + 1, and with pq = n that is a quadratic whose roots are p and q.
So RSA is secure only if factoring large numbers is hard. That is believed and not proved. The best known general algorithm, the number field sieve, is sub-exponential but not polynomial; the largest RSA modulus factored publicly is 829 bits, which took thousands of core-years.
Two further caveats, both important. Nobody has proved that breaking RSA requires factoring — there might be an easier attack on the exponentiation itself. And Shor's algorithm factors in polynomial time on a quantum computer, so RSA is broken outright if a large enough one is ever built.
The lab on this page factors the modulus it just generated, by trial division, in microseconds — and recovers the private exponent. Nothing about the method resists that; only the SIZE of the primes does. Real keys use primes of about 1024 bits each, where the same trial division would outlast the universe.
One last honest note: textbook RSA as described here is not secure to deploy. It is deterministic, so identical messages produce identical ciphertexts and an attacker can test guesses; small messages with small e can be recovered by taking an ordinary integer root. Real systems use randomised padding (OAEP) for exactly these reasons. The mathematics here is right and the engineering is not present.
Interactive
Small enough to check by hand
Method
Each step is a theorem from this course.
n = pq. They must be distinct, or φ(n) = p(p−1) rather than (p−1)² and n is a square, trivially factorable.
Multiplicativity of φ from “Fermat's Little Theorem and Euler's Theorem”. This value must never be published.
gcd(e, φ(n)) = 1 by “Greatest Common Divisor”, and d = e⁻¹ mod φ(n) by “Bézout's Identity and Modular Inverses”. e need not be prime, only coprime; 65537 is the usual choice because a prime is coprime to φ(n) unless it divides it, one check, and 2¹⁶ + 1 has two set bits, so m^e costs sixteen squarings and one multiplication.
By “Modular Exponentiation”'s square and multiply, which is what makes 2048-bit exponents practical.
Every step, with the theorem that licenses it.
The public key (143, 7) is enough to encrypt and useless for decrypting — unless you factor 143, which takes one division by 11. That is the whole security story, and the only thing that changes at 2048 bits is how long that division takes.
Build a key from p = 17, q = 23, encrypt a small message, decrypt it, and then factor n to recover d. With e = 3 you should find n = 391, φ(n) = 352 and d = 235. Doing the attack yourself is what makes the security argument concrete rather than asserted.
Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.
No recommendations yet for this lesson.