Skip to main content

12.10 Shor’s factoring algorithm

Source: Ideas from Computational Physics (Landau, Páez, Bordeianu), §12.10. Original wording — no Amod15 / Qiskit dump. Continues 12.9b. Labs: 12.10b.

RSA-style cryptology leans on the hardness of factoring large integers. Shor’s algorithm finds nontrivial factors of NN in (believed) polynomial time on a fault-tolerant quantum computer by reducing factoring to period finding.

Classical outline​

  1. Pick random 1<r<N1<r<N.
  2. K=gcd⁡(r,N)K=\gcd(r,N); if K≠1K\neq 1, KK is a factor — done.
  3. Find the smallest period TT of f(x)=rx mod Nf(x)=r^x\bmod N.
  4. If TT is odd or rT/2≡−1(modN)r^{T/2}\equiv-1\pmod N, retry with a new rr.
  5. Else gcd⁡(rT/2±1, N)\gcd(r^{T/2}\pm 1,\,N) yields nontrivial factors.

Example toy: N=15N=15. A successful run might draw r=8r=8, read phase 0.250.25 ⇒ T=4T=4, then recover factors 3 and 5.

Modular multiplication unitary​

A unitary UU (for rr coprime to NN) multiplies the computational register by rr mod NN. Eigenstates ∣uS⟩|u_S\rangle carry eigenvalues e2πiS/Te^{2\pi i S/T}; estimating that phase reveals S/TS/T. Pick U∣y⟩U|y\rangle and the T=1/ϕT=1/\phi reading among lookalikes in the guided card below.

Phase estimation​

For unitary U∣u⟩=e2πiϕ∣u⟩U|u\rangle=e^{2\pi i\phi}|u\rangle, a tt-qubit control register plus Hadamards and controlled-U2jU^{2^j} kicks phases onto the controls. An inverse QFT then reads an integer s≈2tϕs\approx 2^t\phi, so ϕ≈s/2t\phi\approx s/2^t.

Figure 12.13 — phase estimation.

Period finding → factors​

Prepare the target register in ∣1⟩=1T∑S∣uS⟩|1\rangle=\frac1{\sqrt T}\sum_S|u_S\rangle. Phase estimation samples ϕ=S/T\phi=S/T; continued fractions recover denominator TT. Then apply the gcd steps above.

Local Qiskit sketches combine qpe, a modular-multiply block (e.g. for N=15N=15), and classical post-processing — APIs change; keep the math, update imports from current docs. Graded labs lock gcd⁡\gcd, periods, and the N=15N=15 factors without calling IBM.

Lab: wire phase-est skeleton​

Takeaway​

StepTool
Random rr, gcdclassical
Period of rx mod Nr^x\bmod NQPE + modular UU
T→T\to factorsgcd⁡(rT/2±1,N)\gcd(r^{T/2}\pm1,N)
QFT linkinverse QFT inside QPE
Quiz

Shor

1 / 3

Shor reduces factoring mainly to…

Pick an answer to see if you are right.

Next: 12.10b Shor labs.