Factoring and Cryptography
The most celebrated application of quantum computing is Shor's algorithm: a quantum procedure that factors large integers in polynomial time. RSA — the cryptographic backbone of most encrypted internet traffic — derives its security from the fact that no efficient classical algorithm for factoring is known. Understanding why factoring breaks RSA, and why quantum computers can factor efficiently, is the conceptual foundation for everything that follows in this module.
RSA in one paragraph
RSA key generation works like this. Choose two large primes and (each hundreds of digits long) and form their product
The public key consists of and a small exponent . The private key is , computed from , , and using Euler's theorem:
To encrypt a message one computes ; to decrypt, the key holder computes . The security claim is simple: knowing but not and makes computing , and therefore , computationally infeasible.
Why factoring is the hard part
Given and it takes a single multiplication to produce . Given only , recovering and is the integer factorisation problem. No classical algorithm is known to solve it in time polynomial in the number of bits of .
The best classical algorithm, the General Number Field Sieve, runs in sub-exponential time roughly
for a small constant . For a 2048-bit this is astronomically large. RSA therefore rests on the computational hardness assumption: factoring is hard when is the product of two comparable-sized primes.
Enter Shor's algorithm
In 1994, Peter Shor showed that a quantum computer can factor in time polynomial in — essentially elementary gate operations with some polylogarithmic overhead. That is an exponential speedup over the best known classical method.
Shor's algorithm does not directly factor . Instead it solves a related problem called order-finding (also called period-finding): given integers and with , find the smallest positive integer such that
The integer is called the order of modulo . Once is known, a simple classical calculation reveals the factors of with high probability.
The reduction from factoring to order-finding is entirely classical — the quantum part is order-finding itself, accomplished via the Quantum Fourier Transform (QFT), which is the subject of the next several lessons.
From order to factors
Here is the classical post-processing step, included now so the full picture is clear.
Suppose we have found the order of some randomly chosen . If is even and , then
Because divides the left side but neither factor on the right is divisible by (by our assumptions), the greatest common divisors
are non-trivial divisors of , i.e., either or . Both GCDs are computed in time by the Euclidean algorithm.
A random has at least a chance of yielding an even with the required property, where is the number of distinct prime factors of . For (two primes) this means success probability at least ; repeating a handful of times gives overwhelming confidence.
Why classical computers cannot keep up
The exponential gap between (Shor) and the sub-exponential GNFS is decisive in the long run. Doubling the bit length of approximately doubles the cost of Shor's algorithm but increases the GNFS cost by a far larger factor. This means that, as quantum hardware scales, longer RSA keys provide only a temporary fix.
Post-quantum cryptography addresses this by replacing RSA with problems believed to be hard even for quantum computers — lattice problems, hash-based signatures, and others. But those are outside this module. Our goal is to understand how Shor's quantum speedup works from the inside, starting with the Quantum Fourier Transform.
Roadmap for this module
The lessons ahead build Shor's algorithm layer by layer:
- The Quantum Fourier Transform (QFT) — the engine that detects periodicity in a quantum superposition.
- Quantum Phase Estimation (QPE) — uses the QFT to read out an eigenvalue of a unitary operator.
- Modular exponentiation — how to implement as a quantum circuit.
- Full Shor's algorithm — putting QPE and modular exponentiation together to find .
By the end you will have written and run all the key sub-circuits on small instances such as .
Sign in on the full site to ask questions and join the discussion.