RSA: the lock anyone can close but only you can open
In the padlock icon of a website, in software updates proving they're genuine, and in signed messages
What problem does it solve?
How can two strangers share a secret over an internet that everyone can eavesdrop on?
The big idea
Use arithmetic on a clock: numbers wrap around after n, like hours after 12. Raising a message to a power e on a huge clock scrambles it in a way that's easy to do and seemingly impossible to undo. Unless you know the secret: n was made by multiplying two giant primes p and q, and knowing them lets you compute a magic power d that exactly unscrambles. Anyone can multiply primes; nobody knows a fast way, on ordinary computers, to split a 600-digit n back into p and q.
How it works, step by step
- 1. Pick two secret primes, e.g. p = 61 and q = 53, and publish n = pq = 3233.
- 2. Compute φ = (p − 1)(q − 1) = 3120, choose e = 17 and publish it; secretly find d = 2753, because 17 × 2753 = 46801 = 15 × 3120 + 1.
- 3. To send the message m = 65, anyone computes c = 65¹⁷ mod 3233 = 2790.
- 4. You decrypt with 2790²⁷⁵³ mod 3233 = 65. Only d undoes e, and finding d requires knowing p and q.
The key formula
- the public 'clock size', a product of two secret primes
- the public exponent, the lock everyone can use
- the private exponent, the key only you have
- keep only the remainder after dividing by n: clock arithmetic
How fast is it?
Raising to huge powers is fast with 'repeated squaring': about log₂ e squarings, not e multiplications. Breaking it by factoring is believed to be infeasibly slow for 2048-bit keys; the record is RSA-250, an 829-bit number factored in 2020 with thousands of computer-years. Honest note: most websites now agree on secret keys using elliptic-curve methods, with RSA often used for the certificate signatures that prove who the site is. A big enough quantum computer running Shor's algorithm would break RSA.
Try it yourself
- Compute 7² mod 10, 7³ mod 10, 7⁴ mod 10… What pattern appears? (Clock arithmetic always cycles.)
- Factor 3233 by hand. Now imagine doing it for a number with 617 digits.
Fun fact
Rivest, Shamir and Adleman published RSA in 1977, but Clifford Cocks at Britain's GCHQ had discovered essentially the same thing in 1973. It stayed classified until 1997.