Project: End-to-End Shor
Shor's algorithm is the headline result of quantum computing: it factors an -bit integer in time polynomial in , breaking RSA in principle. Yet most of the algorithm is classical. The only quantum step is order finding — and everything around it is number theory you can run on a laptop. This capstone assembles the full pipeline and asks you to write the classical glue that turns a measured period into a factor.
The reduction: factoring to order finding
Pick an integer coprime to (if you already have a factor). Define the order as the smallest positive integer with
If is even, then is a square root of . Provided , it is a nontrivial square root, and
so divides the product but neither factor alone. Therefore gives a nontrivial factor of .
What the quantum part contributes
The order is the period of the function . Quantum phase estimation applied to the modular-multiplication unitary measures a phase for a random , and continued fractions recover from that estimate. This is the only piece that needs a quantum computer; for a full register of the simulator could run it, but at the scale of cryptographic it is classically intractable — which is the whole point.
The worked instance ,
The order of modulo is , because
Since is even, compute . As , this run succeeds, and
We have factored .
Try it
Implement factorFromPeriod(N, a, r) for the worked instance. Handle the two failure conditions by
returning 0, otherwise return the smaller recovered factor. The grader checks you return
for , , .
Sign in on the full site to ask questions and join the discussion.