Kolton Ndoj

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. 1. Pick two secret primes, e.g. p = 61 and q = 53, and publish n = pq = 3233.
  2. 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. 3. To send the message m = 65, anyone computes c = 65¹⁷ mod 3233 = 2790.
  4. 4. You decrypt with 2790²⁷⁵³ mod 3233 = 65. Only d undoes e, and finding d requires knowing p and q.

The key formula

c=me mod n,m=cd mod n,ed≡1(mod(p−1)(q−1))c = m^{e} \bmod n,\qquad m = c^{d} \bmod n,\qquad ed \equiv 1 \pmod{(p-1)(q-1)}
n=pqn=pq
the public 'clock size', a product of two secret primes
ee
the public exponent, the lock everyone can use
dd
the private exponent, the key only you have
 mod n\bmod n
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

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.

Related

Open it in the Math Lab →

Security · Stretch