Quantum Discrete Logarithm Algorithm
The discrete logarithm problem is one of the two number-theoretic hinges — integer factoring is the other — on which almost all deployed public-key cryptography turns. Fix a finite cyclic group of order , written multiplicatively, and an element . Because generates the whole group, there is a unique exponent with ; that exponent is the discrete logarithm . Classically it is believed hard: index calculus for the multiplicative group of a finite field runs in subexponential time, and the best generic methods — Pollard's rho, baby-step/giant-step — cost , exponential in the bit-length . Shor's discrete-log algorithm computes in time polynomial in , and with it every DLP-based scheme becomes breakable by a large fault-tolerant quantum computer. The trick is to make the unknown exponent geometric. Consider the two-variable function on . Two inputs collide precisely when , that is, when their difference lies on the subgroup — a one-dimensional line of slope inside the lattice . The hidden slope is the answer. Recovering a hidden subgroup of an abelian group from such a level-set-constant function is the abelian hidden subgroup problem, and the quantum Fourier transform diagonalises the coset structure so that a Fourier measurement exposes the subgroup, hence . Operationally the circuit builds a uniform superposition over , computes reversibly, discards that register to collapse onto one coset, and Fourier-transforms each index register; the measured outcomes then obey a linear congruence in , and a single good sample with the order yields by one modular division. The same machinery breaks Diffie–Hellman, DSA, ElGamal, and — most cheaply of all — elliptic-curve cryptography, which is why it drives the migration to post-quantum standards.
- The discrete logarithm problem asks: given a generator of a cyclic group of order and an element , find . Classically this is believed exponentially hard; quantumly Shor solves it in time polynomial in .
- The engine reframes DLP as a hidden-subgroup problem: the function is constant exactly on cosets of the line , so the unknown exponent is a hidden slope.
- Two quantum Fourier transforms over send that slope to a measured congruence ; one modular division then recovers the logarithm.
- The group order is supplied first by order finding — the period-finding core of Shor's factoring algorithm — or is simply read off when the group has publicly known prime order.
- Each shot succeeds with probability , which is for the prime-order groups used in cryptography, so a handful of repetitions suffice.
- ECC is the most fragile target: a 256-bit elliptic curve falls to a few thousand logical qubits, fewer than RSA-2048, because its group order is smaller.
- Key idea: encode the unknown exponent as the slope of a hidden line through ; a double quantum Fourier transform over turns that slope into a measured linear constraint , and modular division recovers .
Encode the unknown exponent as the slope of a hidden line through the function ; a double quantum Fourier transform over turns that slope into a measured linear constraint , from which one modular division recovers .
Where this lives today
No machine can yet run the discrete-log algorithm at cryptographically relevant sizes — the largest honest demonstrations involve a handful of qubits on toy groups, orders of magnitude short of the thousands of high-fidelity logical qubits and billions of Toffoli gates the resource estimates demand. Yet the algorithm dominates present-day cryptographic planning because of the "harvest now, decrypt later" threat: an adversary can record encrypted traffic today and decrypt it the day a capable machine exists, so any secret that must stay confidential for a decade is already at risk. That logic drove the US National Institute of Standards and Technology to finalise in 2024 the lattice-based standards ML-KEM (FIPS 203), ML-DSA (FIPS 204), and SLH-DSA (FIPS 205) as replacements for Diffie–Hellman, DSA, and ECDSA. Refined resource studies — Roetteler and colleagues for elliptic curves, Gidney and Ekerå for RSA — confirm that ECC, with its smaller group order, is the cheapest target. And the same abelian-hidden-subgroup lens that makes DLP easy sharpens the frontier of what remains hard: the non-abelian hidden subgroup problems behind graph isomorphism and, most consequentially, the lattice problems on which the new standards rest, for which no analogous quantum Fourier attack is known.
The physical picture
Think of multiplication-by- as walking around a ring of stations; computing asks "how many steps land you on ?". Classically you essentially have to walk the ring, because the ordering of powers carries no exploitable structure. Quantumly you instead build a function whose repeating pattern is the answer: takes the same value whenever you move along the direction , so is baked into the geometry of where repeats — and the Fourier transform reads geometry as frequency. The two index registers behave like a two-dimensional grating: after you compute and discard , the surviving amplitude lives on a single tilted coset, and transforming a line of slope produces a dual line of slope in frequency space, so each measurement samples one point of that dual line — a clean linear equation in the unknown.
Why does one equation suffice, when a classical solver would need to walk the whole ring? Because the quantum machine also hands you the modulus , and a single congruence pins uniquely as soon as is invertible — which a random is with probability , equal to for the prime-order groups cryptographers deploy. The whole construction is the abelian hidden subgroup problem in a cryptographic costume: Shor's factoring hides a period , discrete log hides a slope ; same Fourier engine, different hidden subgroup. The circuit is short — prepare, oracle, discard, transform, measure — and the only expensive part is realising group multiplication as a reversible arithmetic circuit.
The core equations
The problem itself is one line: a target element is a known power of the generator, and the exponent is what we want. Everything the algorithm does is a way to read that exponent out of the group's structure rather than by search.
where: — generator of a finite cyclic group ; — the group order, , so ; — the target element; — the unknown exponent, the discrete logarithm. Reading it: because generates , the map is a bijection , so exists and is unique — the difficulty is purely computational. The single design decision that makes the problem tractable is the two-variable function below. It combines a power of the generator with an inverse power of the target so that the answer enters as the coefficient tying the two indices together.
where: — index variables ranging over ; — a group element depending only on the combination ; — the source of the term. Reading it: can only "see" the linear form , so its level sets are the lines of slope — collisions occur exactly along the hidden subgroup , and learning that slope is solving DLP (the derivation below makes this precise). Running the oracle on the uniform superposition entangles every input pair with its function value in a third register, so all evaluations coexist.
where: — two index registers, each uniform over ; — the function register holding via reversible group arithmetic; — normalisation of the equal terms. Reading it: this is quantum parallelism, but by itself it is useless — the point is what interference does next. Measuring (or simply discarding) the function register collapses the state onto the inputs sharing one value of — a single coset of the hidden line, with an unknown offset .
where: — the value with equal to the measured -outcome; — the first-register index, locked to the line of slope mod . Reading it: the slope now lives in the correlation between the registers, not in any single amplitude, and the offset is about to become harmless. The transform that reads slope as frequency is the quantum Fourier transform over — the abelian character sum. Applied to each index register it maps the tilted coset onto its dual line.
where: — input index in ; — the conjugate (frequency) index; — the character of at . Reading it: characters are orthogonal, so a complete phase sum either reinforces to or cancels to — the mechanism that carves out the dual line. After the double transform the probability is supported only on outcomes satisfying a linear congruence; the unknown offset has dropped out as a pure phase.
where: — measured frequencies of the two index registers; — the dual-line constraint carrying ; — uniform weight over the allowed points. Reading it: every shot returns one point of the dual line, i.e. one linear equation in the single unknown . One equation with an invertible coefficient determines by a modular division — the extended Euclidean algorithm supplies the inverse in polynomial time.
where: — the inverse of in ; — the invertibility condition. Reading it: whenever the sampled is coprime to the logarithm falls out in one step, and the candidate is checked for free by recomputing . The chance that a shot is usable is the fraction of invertible residues — the Euler totient ratio — which is near one for prime order.
where: — Euler's totient, the count of residues coprime to ; — the prime-order limit. Reading it: for the prime-order groups of real cryptosystems essentially every shot works, so a constant number of repetitions gives certainty.
The goal is to prove that the function is constant exactly on the cosets of the line , so that "find the hidden subgroup of on which is invariant" is literally the same problem as "find the discrete logarithm " — the structural claim that converts an unstructured search into a hidden-subgroup problem an abelian Fourier transform can crack. We start from the collision condition and read off the subgroup.
Step 1. Write out when two inputs agree: means , and since has order , equal powers force equal exponents mod , i.e. . Why: the order of the generator is what turns an equality of group elements into a linear congruence — the only place the group structure enters.
Step 2. Rearrange the congruence into a statement about the difference of inputs: . Setting , this says lies on the line of slope through the origin. Why: collisions are governed only by input differences, so the invariance structure is a subgroup, not a scattered set.
Step 3. Collect all such differences into and check it is a subgroup: it is closed under addition mod , contains , and has order because ranges over . Thus iff . Why: this is exactly the defining property of a hidden subgroup — is constant on cosets of and distinct across them.
Step 4. Read off the payload: the slope of is , so any procedure that identifies the hidden subgroup returns the discrete logarithm. A concrete check (, , , so ) gives , the blue points of the first figure. Why: it grounds the abstract subgroup in the numeric instance we will carry through the worked example, confirming the slope really equals the answer. *Note: direct enumeration for the instance confirms is constant on every coset of ; the subgroup axioms hold because generates a cyclic group of order in .*
Go deeper · Derivation B · 2 minFourier sampling pins the slope
The goal is to carry the post-measurement coset state through the two quantum Fourier transforms and show that amplitude survives only on the dual line , with the unknown coset offset demoted to an unobservable phase. This is the heart of the algorithm — where the geometry of the hidden slope is converted, by the orthogonality of characters, into a measurement yielding a clean linear equation in the single unknown . We transform each register in turn and collapse the resulting phase sum.
Step 1. Transform the first register. Each index maps under to . Why: the first register carries the slope information as the coefficient of inside the phase, which is what the transform will expose.
Step 2. Transform the second register. The index maps to , a standard . Why: applying the transform to both registers is what builds the two-dimensional dual pattern rather than a one-dimensional spectrum.
Step 3. Collect the sum over . The amplitude of is , and the inner sum is a complete geometric series equal to when and otherwise. Why: this is character orthogonality on , — the exact cancellation that carves the dual line out of the full grid.
Step 4. Read off the amplitude and probability. On the surviving line the amplitude is , so for and elsewhere. The offset appears only in the modulus-one phase and cancels in . Why: this is precisely why discarding the function register — which fixed to an unknown value — costs nothing: the offset never reaches the probabilities.
Step 5. Confirm normalisation and the geometry. There are exactly allowed pairs (one for each ), each with weight , summing to ; the allowed set is the dual line of slope . For the instance the outcomes are — the green points of the first figure, each with probability . Why: the numeric check confirms both the constraint and the uniform-over-the-line distribution the next derivation exploits. *Note: direct simulation of the double on the coset state reproduces the five outcomes at probability each, all satisfying .*
Go deeper · Derivation C · 1 minRecovering s and the totient success bound
The goal is to show that one Fourier sample with an invertible coordinate determines exactly by a single modular division, and to compute the per-shot success probability as the totient ratio , near one for prime order. This closes the loop from measurement to answer and quantifies how many repetitions the algorithm needs. We invert the sampled congruence, count the good samples, and bound the failure of repetition.
Step 1. Start from a measured pair obeying . Solving for gives , provided exists. Why: the whole informational content of a shot is this one linear equation, and division is the only step needed to expose .
Step 2. Determine when the inverse exists: is defined iff , and the extended Euclidean algorithm returns it in bit operations. Why: a non-invertible (in particular ) yields a congruence that does not isolate — the sample is discarded, not wrong.
Step 3. Count the usable samples. Because the outcomes are uniform, the probability that is invertible equals the fraction of residues coprime to , which is by definition of the totient. Why: this converts the algebra of invertibility directly into the success probability of a single run.
Step 4. Specialise to cryptographic groups. When is prime every nonzero residue is invertible, so : essentially every shot succeeds. Any candidate is verified for free by testing , removing residual ambiguity. Why: real DLP groups use prime order precisely so that one shot almost always suffices and verification is trivial.
Step 5. Bound repetition for the worst case. Even for composite where dips, the failure probability after independent shots is at most , which decays exponentially, so runs drive it below any threshold. Why: it guarantees efficiency uniformly, since is the worst the totient ratio can be. *Note: for the instance each invertible sample returns by , and matches the prime limit .*
Limiting cases
The cost of discrete log depends sharply on the group, the algorithm, and whether you are the attacker or the defender:
| Case | Result | Meaning |
|---|---|---|
| Classical generic DLP | Pollard rho and baby-step/giant-step in a black-box group of order take steps — exponential in the bit-length , and provably optimal in the generic-group model. | |
| Quantum (Shor) DLP | Polynomially many group multiplications and QFTs in the input size ; the dominant cost is reversible modular exponentiation or scalar multiplication. | |
| ECDLP qubit count | For an elliptic curve over an -bit field the Proos–Zalka estimate is of order logical qubits; a 256-bit curve needs a few thousand, fewer than RSA-2048. | |
| Symmetric-key contrast | Public-key DLP collapses to polynomial time, but Grover only halves the effective key length of a -bit symmetric cipher — so AES-256 keeps security. | |
| Prime vs composite order | Prime order gives near-certain success per shot; composite order lowers the totient ratio, costing a few extra repetitions but no change in asymptotic efficiency. |
Worked examples
1 · Solving a discrete log end to end (fully worked)
Work in the order-5 subgroup of generated by , with target . Find by running the algorithm and recovering from a single Fourier sample.
Step 1. Fix the group and check the order. The powers of mod are , so has prime order . The target sits in , so a logarithm exists; the answer we are hunting is the with .
Step 2. Form the oracle function and its hidden line. The circuit evaluates over . Its hidden subgroup is ; with the true this is — the blue coset in the first figure. The algorithm does not know yet; it only prepares the superposition and calls once.
Step 3. Discard the function register and Fourier-sample. Measuring collapses the state onto one coset of ; the double then spreads all probability onto the dual line . The five equally likely outcomes are , each with probability — exactly the green points of the figure and the simulation.
Step 4. Recover from one good sample. Suppose the measurement returns . Since , invert: , so . Cross-check with a different shot : in , so . Both agree.
Step 5. Verify and interpret. Confirm the candidate directly: . So , obtained from a single oracle call plus one modular division; the only useless outcome is , where is not invertible, occurring with probability .
2 · Why elliptic curves fall first (resource scaling)
Compare the quantum cost of breaking a 256-bit elliptic curve with breaking RSA-2048, and contrast both with the classical effort.
Step 1. Classical baseline. The best generic attack on a 256-bit curve is Pollard rho at group operations — beyond any classical machine, which is why 256-bit ECC is standardised for 128-bit security. Shor's algorithm ignores this, costing only -scale reversible operations in .
Step 2. Logical-qubit count. Proos–Zalka scaling gives logical qubits, so ; careful modern synthesis (Roetteler and collaborators) lands near once ancillas for reversible field arithmetic are counted. RSA-2048 by contrast needs logical qubits, its modulus being eight times longer than the curve's field.
Step 3. Read the asymmetry. The break cost scales with the bit-length of the group order, and ECC deliberately uses a small order for a given security level — its whole classical selling point. Against a quantum computer that economy inverts into fragility: a 256-bit curve needs about half the logical qubits of RSA-2048, making ECDLP arguably the first public-key primitive a fault-tolerant machine would break.
3 · Composite order and repetitions
The group has composite order . How many shots for 99% confidence?
Step 1. Totient ratio. The residues coprime to are , so and each shot succeeds with probability — barely better than a coin, because has many zero divisors.
Step 2. Repetition bound. Failure after shots is at most , and needs . Composite order costs only a small constant factor; prime-order groups, with , essentially never need more than one shot.
Physics of the portrait
Discrete log and factoring were sister hardness assumptions for two decades before one paper showed a quantum computer dissolves both at once. That paper, and the algorithm carried through this article, belong to Peter Shor.
Origins · 1 minPeter Shor and how this was discovered
Peter Williston Shor is the mathematician who turned quantum computing from an intriguing model into a threat and a discipline. Working at Bell Labs in the early 1990s, he was struck by Daniel Simon's 1994 result that a quantum computer could find a hidden period with an exponential advantage that survives bounded error. Shor saw that the same Fourier-sampling idea, carried from the group to , would expose the period of modular exponentiation — and therefore factor integers and, by the slope construction of this article, compute discrete logarithms. His 1994 conference paper carried both in its title, "Algorithms for Quantum Computation: Discrete Logarithms and Factoring", with the full analysis appearing in the SIAM Journal on Computing in 1997. The impact was immediate and double-edged: it promised that a scalable quantum computer would break RSA, Diffie–Hellman, DSA, ElGamal, and elliptic-curve cryptography, and it made the theory of quantum algorithms suddenly consequential. Shor did not stop there — in 1995 he introduced the first quantum error-correcting code, the nine-qubit code showing fault-tolerant quantum computation was possible in principle and removing the most serious objection to his own algorithm's feasibility. Now a professor at MIT, his work has been recognised with the Nevanlinna Prize, the Gödel Prize, the Dirac Medal, and the 2023 Breakthrough Prize in Fundamental Physics. The discrete-logarithm algorithm and its factoring sibling remain the reason the world is now rebuilding its cryptographic foundations.
Going further
Texts. Nielsen and Chuang, Quantum Computation and Quantum Information, §5.4 (order finding, factoring, and the discrete-log discussion) · Preskill, Lecture Notes for Physics 219, Ch. 6 (abelian Fourier sampling and discrete log) · Kitaev, Shen and Vyalyi, Classical and Quantum Computation, §13 (the abelian stabiliser and hidden subgroup problems) · Watrous, quantum-algorithms and hidden-subgroup lecture notes · Mermin, Quantum Computer Science, Ch. 3 (period finding and its applications).
Primary and resource sources. Shor, Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer, SIAM J. Comput. 26, 1484 (1997) · Proos and Zalka, Shor's discrete logarithm quantum algorithm for elliptic curves, Quantum Inf. Comput. 3, 317 (2003) · Roetteler, Naehrig, Svore and Lauter, Quantum resource estimates for computing elliptic curve discrete logarithms, ASIACRYPT 2017 · Gidney and Ekerå, How to factor 2048 bit RSA integers in 8 hours using 20 million noisy qubits, Quantum 5, 433 (2021). The key checkpoints of this article are: (1) is constant exactly on cosets of ; (2) the character-orthogonality sum yields the dual-line constraint ; (3) the toy instance , , , gives outcomes at probability each, with from every invertible sample; (4) the per-shot success probability is , with prime limit and ; (5) the ECDLP logical-qubit cost is against for RSA.
Prerequisites. Quantum Fourier Transform · Order Finding and Period Finding · Hidden Subgroup Problem · Quantum Phase Estimation · Shor's Factoring Algorithm. Leads to. Hidden Subgroup Problem · Post-Quantum Cryptography · Grover's Search Algorithm.
Ask the tutor: Ask me to run the algorithm on any small group you choose — pick a generator, a target, and an order, and watch the hidden slope turn into a measured line and then into the recovered logarithm.
Why does discarding the function register before the Fourier transform not throw away s?
Because the slope lives in the correlation between the two index registers, not in any single amplitude. Measuring collapses the state onto one coset of the hidden line, where the only thing lost is the coset label — the specific value of the discarded function output. That enters the post-transform amplitude solely through the phase factor , which has modulus one and cancels when you take . So the measurement probabilities depend only on , never on which coset you happened to land in. This is why the algorithm can afford to throw the function register away rather than uncompute it: the offset it fixes is invisible to the final statistics.
How can a single measured equation determine s, when classically you would need to search?
The single congruence has one unknown, , and one modulus, . As soon as is invertible mod you divide once, , and is pinned exactly — there is nothing left to search. The reason this works quantumly and not classically is that the equation is handed to you already true: the Fourier interference guarantees every measured pair lies on the dual line, so the sample is not a guess to be tested but a constraint to be solved. Classically you have no way to produce such a constraint without effectively walking the group. Knowing is essential to the division, which is why order finding runs first when the order is not already public.
What exactly does the order-finding subroutine contribute, and when is it unnecessary?
The discrete-log step transforms over and finishes with a division mod , so the order must be known before you start. Order finding — the period-finding heart of Shor's factoring algorithm — supplies it: it samples from a periodic function and extracts by continued fractions once . That subroutine is only needed when the order is genuinely unknown. For the standardised cryptographic groups that matter in practice — prime-order subgroups of or of an elliptic curve, whose order is a published parameter — you simply read off and go straight to the discrete-log Fourier sampling, skipping order finding entirely.
Why is ECC considered more vulnerable than RSA if both are "broken"?
Both fall to Shor, but the cost scales with the bit-length of the group order, and ECC deliberately uses a much smaller for the same classical security. A 256-bit curve matches the classical strength of RSA-2048, yet its quantum break needs roughly – logical qubits against RSA-2048's , and correspondingly fewer reversible operations. What makes elliptic curves attractive classically — compact keys from a small, hard group — is exactly what makes them the cheapest quantum target, so ECDLP is likely the first public-key primitive to break, not the last.
Could Grover's search give the same exponential break of discrete log?
No. Grover's algorithm speeds up unstructured search only quadratically, turning a brute-force scan of exponents into — still exponential in the bit-length, and no better asymptotically than classical Pollard rho. The exponential break comes specifically from Fourier sampling exploiting the algebraic coset structure of the group, which Grover's oracle does not use. This is also why symmetric ciphers survive: with no algebraic structure to exploit, a -bit key loses only half its bits to Grover, so AES-256 retains security while DLP-based public-key crypto collapses to polynomial time.
If this breaks discrete log, why does lattice-based post-quantum cryptography survive it?
Because the exponential speedup is not generic — it is bought entirely by the abelian group structure that lets the quantum Fourier transform diagonalise the coset relation into a clean linear congruence. Lattice problems such as Learning With Errors and the shortest-vector problem do not present that structure; the relevant hidden-subgroup instances are non-abelian (for example the dihedral group behind certain lattice reductions), and no efficient quantum Fourier attack is known for them. That is the whole design principle of post-quantum cryptography: migrate to hardness assumptions that lack the algebraic symmetry Shor exploits. The new NIST standards (ML-KEM, ML-DSA) rest on lattices for exactly this reason, though their quantum hardness is a conjecture, not a theorem.