Shor's Factoring Algorithm
In 1994, Peter Shor wrote an algorithm that sent shockwaves through the cryptography world. It can factor large numbers — the basis of RSA encryption — exponentially faster than any known classical method. When large-scale quantum computers arrive, Shor's algorithm could render much of today's internet encryption obsolete.
Why Does Factoring Matter?
RSA encryption — used to secure HTTPS, banking, email, and more — is based on one simple mathematical fact: multiplying two large prime numbers is easy, but factoring their product is practically impossible for classical computers.
RSA uses numbers with thousands of digits. The best classical algorithm (General Number Field Sieve) runs in roughly e^(n^(1/3)) time — super-polynomial, effectively intractable for large n. Shor's algorithm runs in O((log n)³) — polynomial time. That's an exponential speedup.
How Shor's Algorithm Works (Conceptually)
Shor's algorithm reduces factoring to a different problem: finding the period of a modular arithmetic function. Here's the high-level flow:
The Role of the Quantum Fourier Transform
The Quantum Fourier Transform (QFT) is the engine of Shor's algorithm. It transforms a superposition of the periodic function f(x) = aˣ mod N into a superposition that has large amplitudes exactly at integer multiples of N/r (where r is the period). Measuring this gives you N/r, and simple arithmetic recovers r.
The classical Fast Fourier Transform (FFT) does the same thing but takes O(n·2ⁿ) operations for n bits. The QFT does it in O(n²) operations — exponentially faster.
We cover the QFT in detail in the next article.
Impact on Cryptography
What Shor's can break
- RSA — used in HTTPS, TLS, SSH
- Elliptic Curve Cryptography (ECC) — used in Bitcoin, modern TLS
- Diffie-Hellman key exchange — used for secure session keys
What Shor's cannot break
- Symmetric encryption (AES) — Grover's gives √N speedup, but AES-256 remains secure with 128-bit effective security
- Post-quantum cryptography (PQC) — New algorithms like CRYSTALS-Kyber and CRYSTALS-Dilithium are designed to resist both classical and quantum attacks
- Hash functions (SHA-3) — Largely unaffected; Grover's only marginally weakens them
Where Are We Today?
Shor's algorithm requires a fault-tolerant quantum computer with thousands to millions of logical qubits. Today's NISQ-era machines have:
- 100–1,000 physical qubits (with high error rates)
- The largest number factored with a quantum computer (using Shor's) so far: 21 = 3 × 7 (2012, IBM)
- Estimates suggest factoring 2048-bit RSA would need ~4,000 logical qubits with full error correction — likely millions of physical qubits
We're still years or decades from this capability. But the direction is clear, and the cryptography community isn't waiting.
Frequently Asked Questions
Should I be worried about Shor's algorithm right now?
For most people — not immediately. Current quantum computers can't run Shor's on real encryption keys. However, "harvest now, decrypt later" attacks are a real concern: adversaries may be recording encrypted traffic today, planning to decrypt it once quantum computers are powerful enough. Sensitive long-lived data (government, medical) should migrate to post-quantum cryptography soon.
Does Shor's algorithm work on all factoring problems?
Yes — it factors any integer N (that isn't prime or a prime power) in polynomial time. The quantum period-finding subroutine works for any such N. The classical reduction from factoring to period-finding has been known since the 1970s; Shor's insight was the quantum speedup for the period-finding part.
Can quantum computers break Bitcoin?
In principle, Shor's algorithm could attack Bitcoin's elliptic curve cryptography (used to sign transactions). However, this would require quantum computers far beyond current capability. Bitcoin also uses hash functions (SHA-256) that are more resistant. The Bitcoin community could upgrade its cryptography if needed — though coordination would be difficult.
Frequently Asked Questions
What will I learn here?
This page covers the core concepts and techniques you need to understand the topic and progress confidently to the next lesson.
How should I use this page?
Start with the overview, then follow the section links to deepen your understanding. Use the table of contents on the right to jump to specific sections.
What should I read next?
Use the navigation below to continue to the next lesson or explore related topics.