Skip to content
Quantum Defense

Home / Learn / Foundations / Lesson 4

Part I, Foundations · Lesson 4

Shor's algorithm: why RSA and elliptic curves fall

By Kyeson Blake Utley15 min read1 interactiveNo math required
The short version

If you keep multiplying a number by itself and only keep the remainder, the answers eventually repeat in a loop, like a song's chorus. The length of that loop is a clue that unlocks the secret primes inside an RSA key. Ordinary computers would take forever to find the loop for real keys. A big quantum computer can hear the rhythm almost immediately.

You'll learn to

  • Explain how factoring reduces to finding the period of a repeating sequence.
  • Walk through Shor's method on a small number, including the cases where you must pick again.
  • Describe, without equations, what the quantum part does and why it's fast.
  • Explain why Shor's algorithm breaks elliptic-curve cryptography too, and why bigger keys don't save us.

In 1994, Peter Shor, then at AT&T, found something that turned quantum computing from a physics curiosity into a security problem. He showed that a quantum computer could factor large numbers and compute discrete logarithms in polynomial time, meaning efficiently, with effort that grows gently as numbers get bigger.

From the public-key lesson you know what that means: RSA, Diffie-Hellman, DSA and elliptic-curve cryptography (ECDH, ECDSA, Ed25519) all fall. RSA: retiring after a long and distinguished career.

The surprising part is that most of Shor's algorithm is ordinary arithmetic you can do on paper. Only one step needs a quantum computer. Let's find it.

The big idea: factoring is secretly about rhythm

Take a number N you want to factor, say 15. Pick any smaller number a, say 7. Now compute powers of 7 and keep only the remainder after dividing by 15 ("mod 15"):

x012345678
7x mod 1517413174131

The sequence repeats: 1, 7, 4, 13, then 1, 7, 4, 13 again, forever. The length of the loop is called the period, written r. Here r = 4.

This always happens. For any a that shares no factor with N, the powers of a mod N eventually cycle back to 1 and repeat. Number theorists had known this for centuries. What Shor noticed is how much the period gives away.

From rhythm to factors

If r is even, take a to the power r/2. Here that's 72 = 49, which is 4 mod 15. Now look at the numbers either side of it: 3 and 5. Compute the greatest common divisor (gcd) of each with 15. The gcd is the largest number dividing both, and computers find it almost instantly, even for huge numbers, using Euclid's algorithm.

  • gcd(3, 15) = 3
  • gcd(5, 15) = 5

And 15 = 3 × 5. Factored. The same recipe works for numbers of any size: if you can find the period, you can factor.

Play with different N and a values. You'll hit three kinds of outcome:

  • Success: an even period, and the gcd step splits N.
  • Bad luck: the period is odd, or ar/2 turns out to be −1 mod N (that is, N − 1). Then the trick gives only the useless factors 1 and N. You just pick another a and try again. For typical N most choices work, so a few tries are enough.
  • Freak luck: your a already shares a factor with N, and the very first gcd hands you the answer. For a real 2048-bit key, this essentially never happens.

The quantum part: hearing the rhythm

So why can't an ordinary computer just do this? Because finding the period is the hard step. In the widget, we found r by computing powers one after another until we got back to 1. For real RSA numbers, the period can be about as large as N itself, a number hundreds of digits long. Counting to it is hopeless. No known classical method finds such periods efficiently.

A quantum computer attacks the problem differently. In outline:

  1. Superpose. Put a register of qubits into a superposition of many values of x at once.
  2. Compute. Run the arithmetic ax mod N on that superposition. The result is a quantum state in which the repeating pattern is woven into the amplitudes.
  3. Transform. Apply the quantum Fourier transform, which uses interference to make amplitudes pile up on values related to the period and cancel elsewhere.
  4. Measure, then tidy up classically. The measurement gives a number that reveals r with good probability, after some ordinary arithmetic. If it doesn't, run again.

A good analogy is a prism. Sunlight looks white, but a prism splits it into the colors hidden inside. The Fourier transform is a prism for rhythms: it takes a signal and reveals its frequencies. A quantum computer can apply that prism to a pattern far too long to ever write down, then measure the strongest frequency.

Note what it doesn't do. It doesn't try every factor in parallel and pick the right one. As we saw in the last lesson, that wouldn't work. It uses interference to extract one global property, the period, from a pattern it never reads out in full.

Elliptic curves fall too

Shor's 1994 paper solved two problems: factoring and discrete logarithms. The discrete logarithm problem behind Diffie-Hellman also hides a periodic structure, and the same period-finding machinery extracts it. Variants of the algorithm do the same for the elliptic-curve version.

So the damage is total for today's public-key cryptography:

AlgorithmUsed forHard problemShor's algorithm
RSAEncryption, signatures, certificatesFactoringBreaks it
Diffie-Hellman, DSAKey exchange, signaturesDiscrete logarithmBreaks it
ECDH, ECDSA, Ed25519, X25519Key exchange, signatures (TLS, messaging, cryptocurrencies)Elliptic-curve discrete logarithmBreaks it
AES, SHA-256Symmetric encryption, hashingNo such structureDoesn't apply (see Grover)

Elliptic curves' small keys were a classical advantage, not a quantum shield.

Why bigger keys don't save us

Against classical attacks, the standard response to progress is "use a bigger key." The work to break RSA classically grows far faster than the work to use it, so a modest key-size increase buys an enormous security margin.

Shor's algorithm breaks that bargain. Its cost grows only polynomially with key size. Doubling an RSA key makes the quantum attacker's job harder, but only by a modest factor, the same kind of factor by which it makes your own job harder. There's no key size that is comfortable for you and hopeless for a quantum attacker. The only real fix is to switch to different math, the post-quantum algorithms that the practitioner track covers.

How far away is this?

Running Shor's algorithm against RSA-2048 needs a large, error-corrected quantum computer. The published estimates keep shrinking:

  • 2019: Gidney and Ekerå estimated about 8 hours with about 20 million noisy qubits.
  • May 2025: Gidney estimated under a week with fewer than one million noisy qubits.

Both are engineering estimates, not predictions of when such a machine will exist. Nobody has built one. But the direction of travel matters: better algorithms and error correction keep lowering the bar while hardware climbs toward it.

Go deeper: why the gcd trick works

If ar ≡ 1 (mod N) and r is even, let y = ar/2 mod N. Then y2 − 1 ≡ 0, so (y − 1)(y + 1) is a multiple of N.

y − 1 can't be a multiple of N, because r is the smallest power giving 1. If y + 1 isn't a multiple of N either (that's the "not −1" check), then N's prime factors must be split between the two brackets. So gcd(y − 1, N) and gcd(y + 1, N) are proper factors.

Shor's paper shows that for a random a, the odds of avoiding both bad cases are good, so a few repetitions suffice. The widget's summary line counts, for small N, exactly what fraction of choices work.

Summary

  • Peter Shor (1994) showed a large quantum computer can factor and compute discrete logarithms efficiently.
  • Factoring reduces to finding the period of ax mod N; the rest is ordinary arithmetic with gcd.
  • Some choices of a fail (odd period, or ar/2 ≡ −1 mod N); you simply pick another.
  • The quantum Fourier transform uses interference to reveal the period without listing the sequence.
  • RSA, Diffie-Hellman, DSA and all elliptic-curve schemes fall; bigger keys only add modest cost for the attacker.
  • Estimates for breaking RSA-2048 dropped from about 20 million noisy qubits in about 8 hours (2019) to under one million in under a week (2025).

Questions

Get five of six right to mark the lesson complete. They also feed the final exam.

Sources

CourseQuantum Defense
Sheet4 of 18
PartI · Foundations
Rev.18 Oct 2026
Sources4 cited
Found an error?Send a correction