We use essential cookies to run the site (session, security, and your theme/language preferences). With your permission we also load embedded third-party content, such as YouTube videos. Cookie Policy
Shor's Algorithm
When factoring stops being hard
Author(s):Elier Rodríguez García
Index
Introduction
Every time you see the little padlock in your browser, you are trusting a strange asymmetry. A computer can multiply two enormous prime numbers together in a blink. But hand it the product and ask it to find those two primes again, and the fastest known classical methods would run for longer than the age of the universe on a number a few hundred digits long.
That one-way street is the heart of RSA, the encryption that protects bank logins, messages and software updates. Multiplying is the easy direction; factoring is the hard one, and the whole edifice assumes no one can do it quickly.
In 1994 a mathematician named Peter Shor found a crack. Not in the math of RSA itself, but in the machine: he showed that a quantum computer could factor large numbers efficiently — turning the universe-melting problem into an afternoon's work. The lock isn't broken yet, but the key now exists on paper.
Find the Period
Shor's real magic is a reduction: factoring a number N becomes finding the period of a simple repeating sequence. Pick a random base a and look at the powers a1,a2,a3,… all taken mod N. This sequence always eventually repeats, and the length of that cycle — the period r — almost always hands you a factor of N.
Try it below. Watching the sequence cycle is easy — you just read off when it returns to 1. But notice: classically you might have to step through a vast number of terms before the pattern reveals itself. Shor's quantum step finds that period all at once using the quantum Fourier transform, sidestepping the slow march. Once you have r, a little ordinary arithmetic with gcd pops out the primes.
The Real Complexity
So how hard is factoring, really — and what does Shor change?
Classically, the best known algorithm (the general number field sieve) runs in sub-exponential but super-polynomial time. Double the key length and the work explodes; that is exactly why 2048-bit RSA keys are considered safe today.
Verifying a factorization is trivial: multiply the factors back and check. That easy-to-check / hard-to-find gap is the signature of problems near P vs NP — though factoring is not believed to be NP-complete.
Shor's algorithm (Peter Shor, 1994) runs in roughly O((log N)² · log log N) quantum operations — polynomial in the number of digits. This places FACTORING inside BQP, the class of problems a quantum computer can solve efficiently.
The engine is the quantum Fourier transform. The slow part of factoring is finding the period r of axmodN; classically that hides among exponentially many values. The QFT computes the period of a superposition over all inputs at once, then makes r the overwhelmingly likely measurement outcome.
The punchline: Shor doesn't prove factoring is easy in general — it proves it is easy for a quantum computer. It is the headline reason anyone is building one, and the reason cryptographers are already racing to replace RSA.
Where It Matters
Shor's algorithm is not an academic curiosity — it is a countdown clock under modern cryptography:
RSA and the discrete log: the same period-finding trick also cracks the discrete logarithm, which means Diffie-Hellman key exchange and elliptic-curve cryptography (ECC) fall too. Almost all of today's public-key crypto rests on one of these.
"Harvest now, decrypt later": adversaries can record encrypted traffic today and decrypt it once a large enough quantum computer exists. Long-lived secrets are already at risk.
Post-quantum cryptography: in 2024 NIST standardized new algorithms (lattice-based schemes like ML-KEM) that resist both classical and quantum attacks. The global migration is underway.
A reason to build quantum machines: factoring a militarily useful key would need millions of high-quality qubits — far beyond today's hardware — but Shor turned "why build a quantum computer?" into an obvious answer.
The same hardness that protects you, explored elsewhere through factoring and the discrete logarithm, is precisely what Shor's algorithm dissolves.
Conclusion
Shor's algorithm is a rare thing: a single idea that redrew the map of what is computationally hard. By reducing factoring to finding a hidden period, and then finding that period with the quantum Fourier transform, it pulled one of cryptography's load-bearing problems from "practically impossible" down to "polynomial time" — for a machine we are still learning to build.
The lesson lingers even before the hardware arrives. "Hard" is never absolute; it is always hard for a given model of computation. Change the machine and the whole landscape shifts. Whether you meet it through P vs NP or the discrete logarithm, the same humbling truth holds: today's unbreakable lock may simply be waiting for tomorrow's key.
Comments
Loading comments...