Quantum Computation & Cryptography · Lecture 16

Lecture 16
Shor II: Circuits, Discrete Logs, and the Hidden Subgroup Problem

Week 9  |  where Shor's gates go, how the same idea breaks Diffie–Hellman and elliptic curves, and why it stops at lattices  |  reading: de Wolf Ch. 6; Nielsen–Chuang §5.4

Cartoon: one key for three locks, not for the fourthA stick figure holds a key labelled period finding. Three padlocks labelled RSA, DH and ECC hang open on a rail. A fourth lock, labelled lattice, is still closed. A speech bubble says: same key, three locks; the fourth one is shaped differently. same key, three locks;the fourth one is shaped differently RSADHECClattice
period finding in abelian groups breaks factoring, finite-field and elliptic-curve discrete logs; lattice problems hide a non-abelian structure
In this lecture
  1. Where the gates go
  2. Reversible arithmetic
  3. Discrete logarithms
  4. Elliptic curves
  5. The hidden subgroup problem
  6. Try it in code
  7. Summary and exercises

Lecture 15 treated each controlled multiplication as a black box. This lecture opens the box, counts what is inside, and then turns the algorithm on the other two public-key problems in use today: discrete logarithms in finite fields (Diffie–Hellman, DSA) and on elliptic curves (ECDH, ECDSA, Bitcoin). The last section shows that Simon's algorithm, order finding and discrete logs are one algorithm, the hidden subgroup algorithm, and explains why the same idea has not broken lattice-based cryptography. By the end you should be able to describe how controlled modular multiplication is built from adders and why it costs \(O(n^2)\) gates, run Shor's discrete-log algorithm on a small example, explain why elliptic-curve keys are an easier quantum target than RSA keys of comparable classical strength, and state the hidden subgroup problem with its known successes and failures.

1 — Where the gates go

For an \(n\)-bit modulus \(N\), order finding uses \(m\approx2n\) control qubits and two kinds of operations:

For \(j=30\), the constant \(c_{30}=a^{2^{30}}\bmod N\) is obtained .

\(a^{2^{j}}=\big(a^{2^{j-1}}\big)^2\). How many steps does that recursion take to reach \(j=30\)?
Each constant is the square of the previous one mod \(N\), so 30 squarings give \(c_{30}\). The quantum circuit only uses the constants; it never computes them.
example 16.1 — the multipliers for N = 35, a = 2

List the constants \(c_j=2^{2^j}\bmod35\) for \(j=0,\dots,10\).

Square repeatedly mod 35: \(2,\ 4,\ 16,\ 256\equiv11,\ 121\equiv16,\ 11,\ 16,\dots\). So the list is \(2,4,16,11,16,11,16,11,16,11,16\). Compare Lecture 15's \(N=15\), where every constant from \(j=2\) on was 1 and could be deleted: here all eleven multiplications are genuine. The classical precomputation costs eleven squarings mod 35, nothing compared with the quantum work.

Every multiplication is a full \(n\)-bit modular multiplication, and there are about \(2n\) of them. Section 2 shows that each costs \(O(n^2)\) gates with schoolbook arithmetic, so modular exponentiation costs \(O(n^3)\), while the QFT costs at most \(O(n^2)\). For \(n=2048\) the ratio is roughly a factor of \(n\), about a thousand: the arithmetic is the algorithm, and every modern resource estimate is mostly a careful accounting of adders.

With schoolbook arithmetic, by roughly what factor does the gate count of order finding grow when the modulus goes from 1024 to 2048 bits?

The cost is \(O(n^3)\): about \(2n\) multiplications, each costing order \(n^2\). What happens to \(n^3\) when \(n\) doubles?
\(2^3=8\): twice as many multiplications, each four times as expensive. The QFT, at \(O(n^2)\), would grow only by 4.

2 — Reversible arithmetic

Adders. Lecture 7 showed that any classical circuit can be made reversible with Toffoli gates. For addition there are very economical constructions. The ripple-carry adder of Cuccaro, Draper, Kutin and Moulton (2004) maps \(|a\rangle|b\rangle\mapsto|a\rangle|a+b\rangle\) for \(n\)-bit \(a,b\) using one ancilla, \(2n\) Toffolis and about \(4n\) CNOTs. It is built from two three-qubit blocks: MAJ, which computes the carry in place, and UMA, which uncomputes it and writes the sum bit (the code in Section 6 builds it and checks all inputs). Its cost is linear in \(n\). An alternative, Draper's QFT adder (2000), adds by rotating phases in the Fourier basis and uses no Toffolis at all, but \(O(n^2)\) controlled rotations.

Modular addition. To compute \(a+b\bmod N\) for \(a,b\lt N\): add, subtract \(N\), use the sign bit to decide whether to add \(N\) back, and then clean up the sign bit by comparing the result with \(a\). It costs a handful of adders and one extra ancilla.

Multiplication by a constant. To compute \(cy\bmod N\) for a classically known \(c\), write \(y=\sum_iy_i2^i\). Then

$$cy\equiv\sum_{i=0}^{n-1}y_i\,\big(c\,2^i\bmod N\big)\pmod N ,$$

so \(|y\rangle|0\rangle\mapsto|y\rangle|cy\bmod N\rangle\) is a sequence of \(n\) modular additions of the precomputed constants \(c2^i\bmod N\), the \(i\)-th one controlled by the bit \(y_i\) (and all of them by the phase-estimation control qubit). That is \(n\) modular additions of \(n\)-bit numbers, hence \(O(n^2)\) gates. HW8 asks you to count the Toffolis to leading order.

One problem remains. Phase estimation needs \(U_c|y\rangle=|cy\rangle\) in place, but the construction above leaves \(|y\rangle\) behind. Reversibility forbids simply erasing it; we need to uncompute it, and the classical inverse of \(c\) does that.

proposition 16.1 — in-place modular multiplication

Let \(c\in\mathbb Z_N^*\) with inverse \(c^{-1}\bmod N\). The three steps

$$|y\rangle|0\rangle\ \xrightarrow{\ +cy\ }\ |y\rangle|cy\rangle\ \xrightarrow{\ \text{SWAP}\ }\ |cy\rangle|y\rangle\ \xrightarrow{\ -c^{-1}\cdot(\text{first})\ }\ |cy\rangle|0\rangle$$

(all arithmetic mod \(N\)) implement \(U_c\) on the first register and return the ancilla register to \(|0\rangle\). Each arithmetic step is a multiply-accumulate by a constant, so the in-place multiplication costs about twice an out-of-place one.

The first step adds \(cy\) to the zero register. After the swap, the third step subtracts \(c^{-1}\cdot(cy)\equiv y\) from the second register, which holds \(y\), leaving 0. Each step is reversible (its inverse adds instead of subtracting), so the composite is a unitary that acts as \(|y\rangle|0\rangle\mapsto|cy\rangle|0\rangle\). If \(\gcd(c,N)\gt1\) there is no \(c^{-1}\), and indeed \(y\mapsto cy\) is not a bijection (Lecture 15, exercise 4).

To multiply in place by \(c=5\) modulo \(N=23\), step 3 of Proposition 16.1 needs \(c^{-1}\bmod23\). What is it?

Find \(k\in\{1,\dots,22\}\) with \(5k\equiv1\pmod{23}\): look for a multiple of 23 that is one less than a multiple of 5.
\(5\cdot14=70=3\cdot23+1\), so \(c^{-1}=14\). Subtracting \(14\cdot(5y)\equiv y\) clears the ancilla register.
In-place controlled multiplication by a constant c mod NThree wires: a control qubit, an n-qubit register holding y, and an n-qubit ancilla register holding 0. Block 1, controlled by the control qubit, adds c times y mod N into the ancilla, giving y and cy. Block 2 swaps the two registers (controlled), giving cy and y. Block 3 subtracts c inverse times the first register from the second, which leaves cy and 0. Net effect: y becomes cy mod N in place, and the ancilla returns to 0. Blocks 1 and 3 are each built from n controlled modular additions.controln qubits|y>n qubits|0>+ c*ymod NSWAP- c^-1 * ymod N|y>|cy>|cy>|y>|cy mod N>|0>compute, swap, uncompute: the classical inverse c^-1 mod N makes the step reversible
Proposition 16.1. All three blocks are controlled by the phase-estimation qubit (when it is 0 nothing happens). Blocks 1 and 3 are each \(n\) controlled modular additions of classically precomputed constants.
proposition 16.2 — the cost of Shor's algorithm

With schoolbook arithmetic, a controlled in-place modular multiplication of \(n\)-bit numbers costs \(O(n^2)\) gates, and order finding with \(m=O(n)\) control qubits costs \(O(n^3)\) gates and \(O(n)\) qubits. With the tricks below, \(2n+3\) logical qubits suffice (Beauregard, 2003); later constructions trade qubits and gates in both directions.

Proof sketch. \(O(n)\) modular additions of cost \(O(n)\) each per multiplication, and \(O(n)\) multiplications. The qubits are two \(n\)-qubit registers plus a few ancillas, and a single control qubit reused \(m\) times, as explained next.

idea — one control qubit is enough

In the inverse QFT, each control qubit only affects the later ones through controlled rotations, and a controlled gate followed by measurement of its control can be replaced by measuring first and applying the gate classically controlled (the deferred-measurement principle of Lecture 8, run backwards). So one can process the control qubits one at a time: prepare \(|+\rangle\), apply the controlled \(U^{2^j}\), rotate by an angle determined by the bits already measured, apply \(H\), measure, reset and reuse. This semiclassical QFT (Griffiths and Niu, 1996) replaces \(m\) control qubits by one, and the inverse QFT by \(m\) single-qubit rotations. It needs mid-circuit measurement and fast feed-forward, exactly the dynamic circuits of Lab 2.

The semiclassical QFT replaces the \(m\) control qubits by one. Which statement about it is correct?

Recount what happens in each round: prepare, controlled power, rotate by an angle that depends on earlier outcomes, measure, reset.
The rounds still apply all \(m\) controlled powers, so the gate count barely changes; what disappears is \(m-1\) qubits and the multi-qubit inverse QFT, at the price of measuring and reacting during the circuit.

Asymptotically faster multiplication (Karatsuba, Schönhage–Strassen) lowers the exponent below 3, but for 2048-bit numbers the constants matter more than the exponent. Practical estimates instead use windowing (look up several bits of the exponent at a time), approximate arithmetic, and careful layout on the error-correcting code; Lecture 17 reads one of them.

3 — Discrete logarithms

definition 16.1 — the discrete logarithm problem

Let \(G\) be a cyclic group of order \(r\) generated by \(g\), written multiplicatively. Given \(h\in G\), the discrete logarithm of \(h\) is the unique \(x\in\{0,\dots,r-1\}\) with \(g^x=h\). The discrete logarithm problem (DLP) is to find \(x\) from \(g\) and \(h\).

The number 2 generates \(\mathbb Z_{13}^*\) (order \(r=12\)). Find the discrete logarithm of \(h=11\) to the base 2.

List \(2^1,2^2,\dots\) mod 13, doubling and reducing each time, until you reach 11.
\(2,4,8,3,6,12,11\): so \(2^7\equiv11\pmod{13}\) and \(x=7\). (For 256-bit groups this listing is hopeless, which is the whole point.)
crypto connection — Diffie–Hellman and signatures

In Diffie–Hellman key exchange, Alice sends \(g^\alpha\), Bob sends \(g^\beta\), and both compute \(g^{\alpha\beta}\); an eavesdropper sees \(g^\alpha\) and \(g^\beta\). Anyone who solves the DLP recovers \(\alpha\) and the shared key. DSA, ECDSA, EdDSA, ECDH and X25519 all rest on the DLP, in the multiplicative group \(\mathbb Z_p^*\) (finite-field groups) or in an elliptic-curve group. Together with RSA, that is essentially all public-key cryptography deployed before 2024.

Classically, the best algorithms for \(\mathbb Z_p^*\) are subexponential (number field sieve variants, much like factoring), and for well-chosen elliptic curves only generic algorithms work, which take about \(\sqrt r\) group operations. That is why a 256-bit curve gives security comparable to 3072-bit RSA.

Shor's idea. Consider the function of two exponents

$$f(a,b)=g^a\,h^{-b}=g^{\,a-xb},\qquad a,b\in\mathbb Z_r .$$

It takes the same value at \((a,b)\) and \((a',b')\) exactly when \(a-xb\equiv a'-xb'\pmod r\), that is, when \((a-a',\,b-b')\) lies in

$$H=\{(a,b)\in\mathbb Z_r\times\mathbb Z_r:\ a\equiv xb\pmod r\}=\{(xb\bmod r,\ b):\ b\in\mathbb Z_r\}.$$

So \(f\) is periodic, not along a line of integers but along the hidden "direction" \((x,1)\), and the direction is the secret. Fourier sampling finds it.

theorem 16.3 — Shor's discrete-log algorithm

Prepare \(\frac1r\sum_{a,b\in\mathbb Z_r}|a\rangle|b\rangle|f(a,b)\rangle\) (two controlled modular exponentiations), apply the Fourier transform over \(\mathbb Z_r\) to each of the first two registers, and measure them. The outcome \((c,d)\) is uniformly distributed over the \(r\) pairs with

$$d\equiv-xc\pmod r .$$

Whenever \(c\) is invertible mod \(r\), \(x\equiv-d\,c^{-1}\pmod r\).

Measuring (or ignoring) the third register leaves a uniform superposition over a coset \((a_0,b_0)+H\), whose elements are \((a_0+xb,\ b_0+b)\) for \(b\in\mathbb Z_r\). With \(\omega=e^{2\pi i/r}\), the Fourier amplitude of \((c,d)\) is proportional to

$$\sum_{b\in\mathbb Z_r}\omega^{(a_0+xb)c+(b_0+b)d}=\omega^{a_0c+b_0d}\sum_{b}\omega^{\,b(xc+d)} ,$$

which by Proposition 2.2 is \(r\,\omega^{a_0c+b_0d}\) if \(xc+d\equiv0\) and 0 otherwise. The \(r\) pairs \((c,-xc)\) therefore share the probability equally, whatever the coset. If \(\gcd(c,r)=1\), solve \(xc\equiv-d\).

Run Shor's discrete-log algorithm in the group of the last check (\(r=12\)) for an unknown \(x\). One run returns \((c,d)=(5,1)\). Use Theorem 16.3 to recover \(x\).

The outcome satisfies \(d\equiv-xc\pmod{12}\), and 5 is invertible mod 12 (\(5\cdot5=25\equiv1\)). Mind the minus sign.
\(x\equiv-d\,c^{-1}=-1\cdot5=-5\equiv7\pmod{12}\), matching the classical answer \(2^7\equiv11\). A single run with \(c\) coprime to \(r\) is enough.
example 16.2 — a discrete log in Z11*

Let \(p=11\), \(g=2\) and \(h=9\). Find \(x\) classically, then describe the output of Shor's algorithm.

The powers of 2 mod 11 are \(1,2,4,8,5,10,9,7,3,6\) for exponents \(0,\dots,9\), so 2 generates \(\mathbb Z_{11}^*\) (order \(r=10\)) and \(2^6=64\equiv9\): \(x=6\). Theorem 16.3 predicts ten equally likely outcomes with \(d\equiv-6c\equiv4c\pmod{10}\):

$$(0,0),\ (1,4),\ (2,8),\ (3,2),\ (4,6),\ (5,0),\ (6,4),\ (7,8),\ (8,2),\ (9,6).$$

The four with \(c\in\{1,3,7,9\}\) reveal \(x\) at once. For \((3,2)\): \(3^{-1}\equiv7\pmod{10}\), so \(x\equiv-2\cdot7=-14\equiv6\). The others carry partial information: \((5,0)\) says \(5x\equiv0\), so \(x\) is even.

Outcomes of Shor's discrete-log algorithm for p = 11, g = 2, h = 9A 10 by 10 grid of outcome pairs (c, d), c across and d up, each from 0 to 9. Exactly ten cells are possible, each with probability 1/10: (0,0), (1,4), (2,8), (3,2), (4,6), (5,0), (6,4), (7,8), (8,2), (9,6). They satisfy d = 4c mod 10, that is d + 6c = 0 mod 10, which encodes the secret x = 6. The four cells with c = 1, 3, 7, 9, where c is invertible mod 10, are highlighted: each reveals x = -d/c mod 10 = 6.01234567890123456789c (first register)deach coloured cell: probability 1/10they all satisfy d = -6c (mod 10)rose: c invertible mod 10 -> x = -d c^-1 mod 10 = 6sky: c shares a factor with 10 -> x only determined mod 10/gcdexample: (c, d) = (3, 2) 3^-1 = 7 mod 10, x = -2 * 7 = -14 = 6 (mod 10)
Example 16.2, computed exactly in verify_L16.py. The outcomes lie on the "line" \(d\equiv-6c\pmod{10}\) through the origin, which wraps around the grid; its slope is the secret.

Discrete-log sampler

Choose a prime \(p\), a generator \(g\) of \(\mathbb Z_p^*\), and the secret exponent \(x\). The grid shows every possible outcome \((c,d)\) of Theorem 16.3 (rose: \(c\) invertible mod \(r=p-1\), so \(x\) can be read off). "Sample" draws outcomes and solves for \(x\) when it can.

Two practical remarks. First, the group order \(r\) must be known; for \(\mathbb Z_p^*\) it is \(p-1\), and for an elliptic-curve group it is public. If it were not, order finding would supply it. Second, real implementations use registers of \(m\approx\log_2r\) qubits with the QFT over \(\mathbb Z_{2^m}\) instead of \(\mathbb Z_r\), which gives approximately the same peaks, just as in Lecture 15.

4 — Elliptic curves

An elliptic curve over the field \(\mathbb F_q\) (\(q\) a prime greater than 3) is the set of solutions of \(y^2=x^3+Ax+B\), together with a "point at infinity" \(\mathcal O\). The points form an abelian group: to add \(P\) and \(Q\), draw the line through them (the tangent if \(P=Q\)), find its third intersection with the curve, and reflect it in the \(x\)-axis. In coordinates, with \(\lambda\) the slope of that line,

$$\lambda=\frac{y_Q-y_P}{x_Q-x_P}\ \ (P\neq Q),\qquad \lambda=\frac{3x_P^2+A}{2y_P}\ \ (P=Q),$$ $$x_{P+Q}=\lambda^2-x_P-x_Q,\qquad y_{P+Q}=\lambda(x_P-x_{P+Q})-y_P ,$$

all mod \(q\). The elliptic-curve discrete logarithm problem (ECDLP) is: given points \(P\) and \(Q=kP=P+\dots+P\), find \(k\).

example 16.3 — a toy curve

On \(y^2=x^3+2x+2\) over \(\mathbb F_{17}\), let \(P=(5,1)\). Compute \(2P\) and \(3P\).

Doubling: \(\lambda=(3\cdot25+2)/(2\cdot1)=77/2\). Mod 17, \(77\equiv9\) and \(2^{-1}\equiv9\), so \(\lambda\equiv81\equiv13\). Then \(x=13^2-5-5=159\equiv6\) and \(y=13(5-6)-1=-14\equiv3\): \(2P=(6,3)\). Adding \(P\): \(\lambda=(1-3)/(5-6)=2\), \(x=4-6-5=-7\equiv10\), \(y=2(6-10)-3=-11\equiv6\): \(3P=(10,6)\). Continuing (verify_L16.py), \(P\) has order 19, which is the whole group: the curve has 18 affine points plus \(\mathcal O\). For instance \(13P=(16,4)\), so the discrete log of \((16,4)\) is 13.

Shor's algorithm applies unchanged: the function \(f(a,b)=aP-bQ\) has the hidden subgroup \(\{(kb,b)\}\), and Theorem 16.3 holds word for word with additive notation. What changes is the arithmetic. Each group operation needs a modular inversion (the division in \(\lambda\)), which is much more expensive than a multiplication when done reversibly. On the other hand, the numbers are much shorter: 256 bits instead of 2048 or 3072.

Published logical resource estimates: elliptic curves versus RSATwo bar charts on logarithmic scales. Left, logical qubits: RSA-3072 6146 and P-256 2330 (Roetteler, Naehrig, Svore and Lauter 2017, same methodology for both), and a 256-bit curve at under 1200 (Babbush et al. 2026, preprint). Right, Toffoli gates: RSA-3072 1.86e13, P-256 1.26e11 (Roetteler et al. 2017), and under 9e7 (Babbush et al. 2026). RSA-3072 and P-256 offer similar classical security, yet the curve needs fewer qubits and far fewer gates.logical qubits1e21e31e46,146RSA-307220172,330P-2562017<1,200256-bit EC2026*Toffoli gates1e71e81e91e101e111e121e131e141.9e13RSA-307220171.3e11P-2562017<9e7256-bit EC2026*2017: Roetteler et al., one method for both; *2026: Babbush et al., preprint (option A)
Published logical resource estimates. Roetteler, Naehrig, Svore and Lauter (2017) used one methodology for both problems: P-256 needs 2,330 logical qubits and about \(1.3\times10^{11}\) Toffolis, while RSA-3072, of comparable classical security, needs 6,146 qubits and \(1.9\times10^{13}\) Toffolis. A 2026 preprint by Babbush et al. reports fewer than 1,200 logical qubits and fewer than \(9\times10^7\) Toffolis for 256-bit curves (or fewer than 1,450 qubits and \(7\times10^7\) Toffolis), and estimates a runtime of minutes on fewer than half a million physical qubits under standard superconducting assumptions.
crypto connection — elliptic curves are the softer target

At equal classical security, elliptic-curve keys are far shorter than RSA keys, and Shor's cost depends on the key length, not on the classical difficulty. So the quantum attack on a 256-bit curve needs fewer logical qubits than the attack on RSA-2048, and in the most recent estimates also far fewer gates. The 2026 preprint above went further than earlier work in one respect worth noticing: "in the interest of responsible disclosure", its authors did not publish their circuits but released a zero-knowledge proof that circuits with the stated costs exist. Since Bitcoin and Ethereum signatures, TLS key exchange (X25519, P-256) and most code signing use elliptic curves, this is where a cryptographically relevant quantum computer would bite first.

P-256 and RSA-3072 are about equally hard to break classically, but the quantum attack on P-256 needs fewer logical qubits, because Shor's cost grows with .

Classical attacks on curves are generic (about \(\sqrt r\) steps), but Shor's algorithm is polynomial in the number of bits. Compare 256 with 3072.
Shor's registers and arithmetic scale with the key length, 256 bits against 3072, which outweighs the more expensive curve arithmetic.

5 — The hidden subgroup problem

Simon's algorithm, order finding and discrete logs share one structure: a function that is constant on the cosets of a hidden subgroup and distinct on different cosets.

definition 16.2 — the hidden subgroup problem (HSP)

Let \(G\) be a group and \(f:G\to S\) a function to some set. We say \(f\) hides the subgroup \(H\le G\) if \(f(g_1)=f(g_2)\) exactly when \(g_1\) and \(g_2\) lie in the same coset of \(H\) (\(g_1H=g_2H\)). The HSP is: given \(f\) as an oracle, find \(H\) (for example, a generating set), using a number of queries and gates polynomial in \(\log|G|\).

Let \(G=\mathbb Z_{12}\) under addition and \(f(x)=x\bmod4\). \(f\) hides a subgroup \(H\). How many elements does \(H\) have, and how many cosets?

\(H\) is the set of \(g\) with \(f(g)=f(0)\). The cosets are the level sets of \(f\).
\(H=\{0,4,8\}\), 3 elements, and \(f\) takes 4 values, one per coset \(\{k,k+4,k+8\}\): \(3\cdot4=12=|G|\).
theorem 16.4 — the abelian HSP is easy

If \(G\) is a finite abelian group whose Fourier transform can be implemented efficiently, the HSP over \(G\) can be solved with \(O(\log|G|)\) queries and polynomially many gates. The algorithm repeats: prepare \(\frac{1}{\sqrt{|G|}}\sum_g|g\rangle|f(g)\rangle\); Fourier-transform the first register; measure. Each outcome is a uniformly random character \(\chi\) with \(\chi(h)=1\) for all \(h\in H\); after \(O(\log|G|)\) samples, \(H\) is determined as the set of elements on which all sampled characters are 1.

Proof sketch. Theorem 16.3's calculation, in general: after measuring \(f\), the state is a uniform superposition over a coset \(g_0H\), and its Fourier transform is supported on the characters trivial on \(H\) (the "annihilator" \(H^\perp\)), each with the same probability. Random elements of a group generate it after \(O(\log|G|)\) samples, as in Proposition 10.3. See de Wolf, Ch. 6.

example 16.4 — three algorithms, one template

Identify \(G\), \(H\) and the information in one sample for Simon's algorithm, order finding and the DLP.

  • Simon (Lecture 10): \(G=\mathbb Z_2^n\) with XOR, \(H=\{0,s\}\). The Fourier transform is \(H^{\otimes n}\), and a sample is a \(y\) with \(y\cdot s=0\): one linear equation for \(s\).
  • Order finding (Lecture 15): \(G=\mathbb Z\) with addition (truncated to \(\mathbb Z_{2^m}\)), \(f(x)=a^x\bmod N\), \(H=r\mathbb Z\). A sample is close to a multiple of \(2^m/r\), giving \(s/r\).
  • Discrete log (Section 3): \(G=\mathbb Z_r\times\mathbb Z_r\), \(H=\{(xb,b)\}\). A sample is a pair \((c,d)\) with \(xc+d\equiv0\): one linear equation for \(x\).

For non-abelian groups the story changes. Ettinger, Høyer and Knill (2004) showed that polynomially many queries always suffice to determine \(H\), but no one knows how to extract \(H\) from those samples with polynomial computation for the groups that matter.

problemgroup \(G\)abelian?efficient quantum algorithm?
Simon's problem\(\mathbb Z_2^n\)yesyes (Simon 1994)
factoring, order finding\(\mathbb Z\)yesyes (Shor 1994)
discrete log, \(\mathbb Z_p^*\) and elliptic curves\(\mathbb Z_r\times\mathbb Z_r\)yesyes (Shor 1994)
Pell's equation, unit groups\(\mathbb R\), \(\mathbb R^k\)yesyes (Hallgren 2002 and later)
graph isomorphism\(S_n\)nonone known
unique shortest vector in a latticedihedral \(D_N\) (via Regev)nosubexponential only (Kuperberg)
idea — why lattice cryptography is believed to survive

Lattice-based schemes such as ML-KEM and ML-DSA, the new NIST standards (Lecture 17), rest on problems like learning with errors: solve a system of linear equations mod \(q\) that has small random errors added. Without the errors, Gaussian elimination solves it instantly; with them, the best classical and quantum algorithms take exponential time. The natural route to a quantum attack goes through the dihedral HSP, where the best algorithm is subexponential and still impractical, and decades of effort have produced no Shor-like speedup. That is evidence, not proof: in 2024 a claimed polynomial-time quantum algorithm for lattice problems (Chen) circulated for about ten days before a bug was found. The lesson is that post-quantum security is a belief about the absence of an algorithm, and it is held more confidently the longer smart people fail to find one.

Tick every problem for which an efficient (polynomial-time) quantum algorithm is known.

Efficient algorithms are known for the abelian hidden subgroup problems. Which of these hide a subgroup of an abelian group?
Factoring and both kinds of discrete log are abelian HSPs, so Shor breaks them. Graph isomorphism and lattice problems lead to non-abelian groups, where no efficient algorithm is known.

6 — Try it in code

tool — a reversible ripple-carry adder (tested with qiskit 2.5)
import itertools
import numpy as np
from qiskit import QuantumCircuit
from qiskit.circuit.library import CDKMRippleCarryAdder
from qiskit.quantum_info import Statevector

def maj(qc, c, b, a):                      # MAJ: a <- majority(a, b, c), and b, c become b^a, c^a
    qc.cx(a, b); qc.cx(a, c); qc.ccx(c, b, a)

def uma(qc, c, b, a):                      # UMA: undo MAJ and leave the sum bit in b
    qc.ccx(c, b, a); qc.cx(a, c); qc.cx(c, b)

def adder(n):
    """|a>|b> -> |a>|a+b>: qubit 0 is a zero ancilla, a_i on 1+2i, b_i on 2+2i, carry-out on 2n+1"""
    qc = QuantumCircuit(2 * n + 2)
    A = [1 + 2 * i for i in range(n)]; B = [2 + 2 * i for i in range(n)]
    maj(qc, 0, B[0], A[0])
    for i in range(1, n): maj(qc, A[i - 1], B[i], A[i])
    qc.cx(A[n - 1], 2 * n + 1)                 # copy out the top carry
    for i in reversed(range(1, n)): uma(qc, A[i - 1], B[i], A[i])
    uma(qc, 0, B[0], A[0])
    return qc, A, B

n = 3
qc, A, B = adder(n)
ok = True
for a, b in itertools.product(range(2 ** n), repeat=2):
    prep = QuantumCircuit(2 * n + 2)
    for i in range(n):
        if (a >> i) & 1: prep.x(A[i])
        if (b >> i) & 1: prep.x(B[i])
    out = int(np.argmax(Statevector.from_instruction(prep.compose(qc)).probabilities()))
    s = sum(((out >> B[i]) & 1) << i for i in range(n)) + (((out >> (2 * n + 1)) & 1) << n)
    ok &= (s == a + b)
print("3-bit adder correct on all 64 inputs:", ok)
for n in (4, 8, 16, 32):
    ops = adder(n)[0].count_ops()
    print(f"n = {n:2d}: Toffolis {ops['ccx']:3d}, CNOTs {ops['cx']:3d}, qubits {2 * n + 2}")
print("Qiskit's CDKMRippleCarryAdder(8), Toffolis:", CDKMRippleCarryAdder(8, kind="full").decompose(reps=2).count_ops()["ccx"])
3-bit adder correct on all 64 inputs: True
n =  4: Toffolis   8, CNOTs  17, qubits 10
n =  8: Toffolis  16, CNOTs  33, qubits 18
n = 16: Toffolis  32, CNOTs  65, qubits 34
n = 32: Toffolis  64, CNOTs 129, qubits 66
Qiskit's CDKMRippleCarryAdder(8), Toffolis: 16

The adder uses exactly \(2n\) Toffolis and \(4n+1\) CNOTs, linear in \(n\), and matches Qiskit's library version. The carry ripples through MAJ blocks on the way up and is uncomputed by UMA blocks on the way down, so the only ancilla, qubit 0, ends in \(|0\rangle\). A modular multiplication uses about \(n\) such additions (plus comparisons), which is where Proposition 16.2's \(n^2\) comes from.

tool — Shor's discrete-log algorithm for 2x = 9 mod 11, simulated exactly
import numpy as np
from math import gcd

p, g, h = 11, 2, 9                         # find x with 2^x = 9 (mod 11); the order of g is r = 10
r = 10
hinv = pow(h, -1, p)
f = {(a, b): pow(g, a, p) * pow(hinv, b, p) % p for a in range(r) for b in range(r)}

# state (1/r) sum_{a,b} |a>|b>|f(a,b)>, then the Fourier transform over Z_r on both registers
w = np.exp(2j * np.pi / r)
P = np.zeros((r, r))
for val in set(f.values()):
    coset = [ab for ab, v in f.items() if v == val]           # the (a, b) with this value of f
    amp = np.array([[sum(w ** (a * c + b * d) for a, b in coset) for d in range(r)] for c in range(r)])
    P += np.abs(amp) ** 2 / r ** 4

rng = np.random.default_rng(16)
for _ in range(6):
    k = rng.choice(r * r, p=P.ravel()); c, d = divmod(int(k), r)
    if gcd(c, r) == 1:
        print(f"(c, d) = ({c}, {d}):  x = -d * c^-1 mod {r} = {(-d * pow(c, -1, r)) % r}")
    else:
        print(f"(c, d) = ({c}, {d}):  c is not invertible mod {r}; try again")
(c, d) = (5, 0):  c is not invertible mod 10; try again
(c, d) = (4, 6):  c is not invertible mod 10; try again
(c, d) = (0, 0):  c is not invertible mod 10; try again
(c, d) = (3, 2):  x = -d * c^-1 mod 10 = 6
(c, d) = (6, 4):  c is not invertible mod 10; try again
(c, d) = (0, 0):  c is not invertible mod 10; try again

Each run returns a pair on the line \(d\equiv-6c\); only those with \(c\in\{1,3,7,9\}\), four of the ten, solve the problem directly. Even the failures help: \((5,0)\) says \(5x\equiv0\pmod{10}\), so \(x\) is even, and \((4,6)\) says \(4x+6\equiv0\pmod{10}\), so \(x\in\{1,6\}\); together they force \(x=6\) (exercise 3).

7 — Summary and exercises

summary

Next time: what the resource estimates actually say about RSA and elliptic curves, harvest-now-decrypt-later, and the migration to post-quantum cryptography. HW8 (Lectures 15–16) is due at the start of Week 10.

exercises 16
  1. List the multipliers \(3^{2^j}\bmod35\) for \(j=0,\dots,5\). How many distinct ones are there?
  2. Why does Proposition 16.1 fail for \(c=5\), \(N=35\)? What does \(y\mapsto5y\bmod35\) do to the 35 residues?
  3. In Example 16.2, two runs return \((5,0)\) and \((4,6)\). Solve each congruence for \(x\) mod 10 and combine them. Is the answer unique?
  4. On the toy curve of Example 16.3, verify that \(3P=(10,6)\) lies on the curve, and compute \(4P=3P+P\).
  5. Show that \(H=\{(xb\bmod r,\,b)\}\) is a subgroup of \(\mathbb Z_r\times\mathbb Z_r\) with \(r\) elements, and that the pairs \((c,d)\) with \(xc+d\equiv0\) also form a subgroup with \(r\) elements.
  6. Using the figure in Section 4, argue which is the easier quantum target, RSA-2048 or a 256-bit elliptic curve, and say what extra information you would want before answering for physical qubits rather than logical ones.
  1. \(3,9,81\equiv11,121\equiv16,256\equiv11,16\). From \(j=2\) on they alternate between 11 and 16 (because \(11^2\equiv16\) and \(16^2\equiv11\)), so there are four distinct multipliers: 3, 9, 11, 16. (The order of 3 mod 35 is 12.)
  2. \(\gcd(5,35)=5\), so 5 has no inverse mod 35 and step 3 cannot be built. Indeed \(5y\bmod35\) takes only the seven values \(0,5,10,\dots,30\); the map is not a bijection, hence not unitary.
  3. \(5x\equiv0\pmod{10}\) means \(x\) is even. For \((4,6)\) the relation is \(xc+d\equiv0\), that is \(4x+6\equiv0\), so \(4x\equiv4\pmod{10}\), \(2x\equiv2\pmod5\), \(x\equiv1\pmod5\): \(x\in\{1,6\}\). Together, \(x=6\), uniquely. (Mind the sign: a common slip is to write \(4x\equiv6\).)
  4. \(6^2=36\equiv2\) and \(10^3+2\cdot10+2=1022=60\cdot17+2\equiv2\). ✓ For \(4P\): \(\lambda=(1-6)/(5-10)=1\), \(x=1-10-5=-14\equiv3\), \(y=1\cdot(10-3)-6=1\): \(4P=(3,1)\).
  5. \((xb,b)+(xb',b')=(x(b+b'),b+b')\) and \((0,0)\) is in \(H\), and \(b\mapsto(xb,b)\) is injective, so \(|H|=r\). The second set is the solution set of one linear congruence \(d\equiv-xc\), closed under addition, with one \(d\) for each \(c\): \(r\) elements. (It is \(H^\perp\), the set of characters trivial on \(H\).)
  6. In logical terms the curve is easier: about 2,330 versus 6,146 logical qubits even at the RSA-3072 comparison, and the 2026 estimate is under 1,200 logical qubits with fewer than \(10^8\) Toffolis. For physical qubits one needs the full set of assumptions (error rate, code, cycle time, connectivity, runtime), which is exactly what Lecture 17 teaches you to look for.

Reading and sources

all numbers and figures in these notes are computed in python (verify_L16.py) or taken from the cited estimates, and follow the page theme