Maths●●●●●Difficulty 4 of 5

How does RSA turn two prime numbers into a lock anyone can close but only you can open?

Multiply two primes and publish the answer: the whole internet can lock messages for you, and only the two primes unlock them.

▶ Start the story

RSA works because some arithmetic is easy forwards and brutally hard backwards. Your private key is a pair of large prime numbers chosen at random and kept secret. Your public key is built from their product. Multiplying two primes takes a computer no time at all, but recovering them from the product is the "factoring problem", and the security of RSA is tied to how hard it is.

The lock itself is clock arithmetic. On a 12-hour clock, 8 hours after 7 o'clock is 3, not 15: numbers wrap around. RSA does the same with a giant clock of size n, the product of the primes. To lock a message, you turn it into a number and raise it to a public power e, keeping only the remainder on the clock. To unlock it, you raise the result to a secret power d, and the original number comes back. Anyone can do the first step. Without d, undoing it is infeasible.

A clock face numbered 0 to 11, with arrows showing that counting past 11 wraps around to 0.
Clock arithmetic: numbers wrap around. RSA does its locking and unlocking on a clock whose size is the product of two primes.Photo: Spindled, English Wikipedia · CC BY-SA 3.0

And d is easy to compute only if you know the two primes. In a classroom example, the primes 61 and 53 give n = 3233, the public power is 17 and the secret one is 413. The message 65 locks into 2790, and 2790 unlocks back into 65. With primes this small, anyone could factor 3233 and steal the key. Real keys use numbers hundreds of digits long: factoring a 250-digit RSA number in 2020 took about 2,700 CPU-years.

The idea was made public in 1977 by Ron Rivest, Adi Shamir and Leonard Adleman, after a sleepless night in which Rivest wrote much of the paper by daybreak. The guarantee rests on a gamble: no fast way to factor large numbers is known, but no one has proven that none exists.

RSA with toy numbers
  1. Step 1: Pick two primes

    61 and 53, kept secret.

  2. Step 2: Multiply them

    n = 3233: the size of the clock, made public.

  3. Step 3: Choose the powers

    Public e = 17, secret d = 413, which undoes it.

  4. Step 4: Lock

    65 to the 17th power on the clock gives 2790.

  5. Step 5: Unlock

    2790 to the 413th power gives 65 back.

Quiz me

0/3

  1. 1.Why can you safely publish an RSA public key?
  2. 2.In the toy example with n = 3233, why does raising 65 to the power 17 and then the result to the power 413 bring back 65?
  3. 3.What could break RSA in the future?

Recap

Easy to multiply, hard to factor: the public key is the product, the private key is knowing the primes.

Surprising fact · Factoring a single 250-digit RSA number in 2020 took about 2,700 CPU-years.

Sources (5)

No source, no claim. Every fact in this lesson (29 claims) cites at least one of these.

  1. [1]RSA cryptosystem · Wikipedia
  2. [2]Modular arithmetic · Wikipedia
  3. [3]Fermat's little theorem · Wikipedia
  4. [4]RSA Factoring Challenge · Wikipedia
  5. [5]Integer factorization · Wikipedia
More lessons in ➗ Maths (3) See all maths lessons →

One more light on your map.

Get one lesson like this every day, about the things you love. Free, in two or five minutes.

Get the share card for this lesson ↗