Quantum Computing & Shor's DLP Algorithm
Read this post first.
Alright, let’s say you don’t just want to break RSA by factoring large integers. You want to solve another famously hard problem in cryptography: the Discrete Logarithm Problem (DLP). In a nutshell, the DLP asks you to find an exponent. More concretely, someone gives you a large prime number , along with two numbers and , both chosen between and . They promise that is actually raised to some secret power , all modulo . In other words, . Your task is to figure out — the “discrete logarithm” of base . This problem is believed to be super-hard for classical computers, forming the backbone of crypto systems like Diffie-Hellman key exchange and certain elliptic-curve schemes.
Now, similarly to factoring, quantum computing doesn’t magically solve all problems by "trying all possibilities at once". The same disclaimer applies here. A quantum computer can’t just brute-force the solution by checking every possible exponent from 1 up to something astronomically large, then instantly pick out the right one. If you tried that, and then looked at the quantum state, you’d end up with a random guess for — about as helpful as throwing darts in the dark.
So if we hope to solve the DLP using a quantum computer, we’re going to need to exploit the underlying mathematical structure of the problem. Just like factoring, the discrete log problem isn’t just some random puzzle. It’s deeply tied to the behavior of powers taken modulo a prime number, and this structure is exactly what a quantum algorithm like Shor’s can latch onto.
Let’s dig into what that structure looks like. Consider the setup again: we have a prime , a “generator” (which, for this discussion, you can think of as a number that, when raised to various powers mod , can produce a large range of possible residues), and a number . We know for some secret exponent . Now, consider the sequence:
, and so on.
If is truly a “generator” in the mathematical sense, then as you keep increasing the exponent, you’ll eventually cycle through all nonzero residues mod . In fact, the sequence of powers of will have a certain period related to (this period is called the “order” of ). For a good choice of , this period should be itself, meaning that , and no smaller positive power of returns you to 1. That’s a fancy way of saying that if you imagine counting powers of on a circular number line mod , you’ll loop all the way around at exactly steps.
Alright, so if , then we know the sequence of powers repeats with period . Where does fit in? Well, we know for some unknown . If we could somehow access a related sequence that encodes the value of within its period, we’d be in good shape.
The key trick in the quantum algorithm for discrete log is very similar to the one used for factoring: we reduce the DLP to a problem of finding a period. But how exactly do we construct a function whose period reveals ?
To understand this, let’s think step-by-step. We start with what we know: . We want a function that takes an integer and gives us some result that, when we look at it across different values of , has a regular pattern repeating every certain number of steps. Ideally, that period will depend on .
A naive idea might be to compute . This by itself creates a periodic sequence with period , but it doesn’t directly tell us anything about . And then to compute as well. Since , this is effectively . Now we have two sequences: one is , and the other is .
Together, gives us a pair of values that depend on both and . But just having a pair isn’t enough; we need a clever construction that isolates the information about into a nice periodic form.
One approach, inspired by Shor’s algorithm for factoring, is to combine these exponentials in a way that produces a “hidden” period. For example, consider forming a ratio of powers that somehow cancels out most variables except those related directly to . One might try something like:
If we substitute , we get:
At first glance, this might look like it gives us a neat periodicity in terms of . But there’s a subtlety: if we just pick this function directly, we end up with something that might be too simple or not aligned with how the hidden subgroup framework works in practice. The ratio isn’t directly what’s used, because it doesn’t straightforwardly solve our problem. We need a function that fits into the well-studied paradigm known as the “hidden subgroup problem” (HSP).
In the HSP setting, we construct a function from a known group (here, integers mod or a related group) into a larger structure, such that the subgroup we’re trying to find (which encodes ) corresponds to the set of values that map to a particular pattern. By carefully choosing how these exponentials are combined — for instance, creating a function that maps to a pair and then using that pair in a way that the quantum algorithm can exploit — we arrange it so that the “hidden” period of the function directly relates to .
The details of how exactly Shor’s algorithm sets up this function can get intricate. It draws on group theory to ensure that the periodicity in the chosen function corresponds exactly to the discrete logarithm. The end goal is that, once we have defined the right function, its period will be linked to . Just like with factoring, once we identify that period using a quantum Fourier transform, we can back out the value of .
Once we’ve defined the right kind of periodic function, we face the same obstacle as before: the period could be huge — as large as — and might have hundreds or thousands of digits! Finding this period by brute force would be completely impractical on an ordinary computer.
Enter the quantum computer. Just like in the factoring case, we can create a giant quantum superposition over many possible exponents , and evaluate our chosen function in superposition. This step — building a big quantum state where each part of the superposition corresponds to — is critical. And thanks to efficient modular exponentiation by repeated squaring, we can do it fast enough. The goal is that this superposition encapsulates all the information about the periodic structure we’re trying to uncover.
Now we come to the same magic wand we waved in the factoring problem: the Quantum Fourier Transform (QFT). The QFT is an operation that takes a quantum state encoding a periodic sequence and transforms it into a state whose “peaks” occur at the frequencies (or periods) of that sequence. In other words, the QFT is able to pick out the underlying beat from hundreds of thousands of drummers playing different styles of music, but all keeping the same underlying rhythm. The QFT will single out the true period that all are tapping to.
Here, we’re doing the same thing: we have a pattern that repeats every so often, and we want to find out exactly how long that cycle is. That length — that period — will give us the discrete log. The QFT causes constructive interference for the correct period (the one that aligns with ) and destructive interference for all the wrong periods.
To put it another, more mathematical way: quantum mechanics allows amplitudes (which you can think of as tiny arrow-like quantities in the complex plane) to point in different directions. For the correct period, all these little arrows line up and reinforce each other. For any incorrect guess at the period, the arrows point in every which way, canceling each other out. When you measure the final quantum state after performing the QFT, you’re overwhelmingly likely to see the correct period encoded in the outcome. With that period in hand, you can “peel away” the disguise and find the discrete log .
So what have we achieved? By applying the quantum Fourier transform to a superposition carefully constructed from , , and , we’ve managed to solve a problem that classical computers find incredibly hard. This is the essence of how Shor’s algorithm (originally famous for factoring) also solves the Discrete Logarithm Problem. It’s the same high-level approach: reduce your cryptographic challenge to finding a period, then let the quantum computer’s ability to perform QFT-based interference extract that period in polynomial time.
And just like in factoring, the reason this quantum magic works is that we’re not trying to isolate a single special needle from an enormous haystack. Instead, we’re identifying a global property — a repeating pattern shared by all elements of a giant quantum superposition. Quantum mechanics doesn’t let you “see” all exponentially many possibilities at once in a naive way, but it does let you exploit global patterns in a way no classical method can. That’s what cracks problems like factoring and discrete logarithms wide open for a quantum computer.
Of course, these results hinge on having a large-scale, fault-tolerant quantum computer, something we’re still working hard to build. But if and when we do, today’s cryptographic assumptions, including the hardness of the Discrete Logarithm Problem, will be toppled.