TL;DR
Take a cyclic group with generator and an element in it. The discrete logarithm problem asks for the exponent with . Computing from and takes a few multiplications, even for huge . Going the other way, from back to , has no known fast general method, and that gap is what modern key exchange relies on.
Where you'll see it: in the Diffie–Hellman key exchange, in elliptic-curve variants of it, and in digital signature schemes such as DSA.
Intuition
Exponents, but in a clock
On the real numbers, the logarithm answers the question "what power of 2 gives 8?" The answer is 3, and logarithms are easy to compute there. Now replace the real numbers with the clock arithmetic of integers mod a prime. Powers wrap around, so the sequence jumps unpredictably between residues instead of growing smoothly.
Why does this matter? In the real numbers, you can read off an exponent by looking at the size of the answer. Mod a prime, the size tells you nothing. The residues look scrambled, and the only generic way to find is to test candidates. That scrambling is what makes the problem useful.
The picture below shows the powers of 3 mod 17. The sequence cycles through every nonzero residue, so starting from 3, each target is reached at exactly one exponent.
flowchart LR E1["3^1 = 3"] --> E2["3^2 = 9"] E2 --> E3["3^3 = 10"] E3 --> E4["3^4 = 13"] E4 --> E5["3^5 = 5"] E5 --> E6["..."] E6 --> E16["3^16 = 1"]
Going forward is a single chain of multiplications. Going backward means searching this chain for a target you have been given.
The math
Let be a cyclic group of order with generator . Given , find the integer with and . The integer is the discrete logarithm of to the base , written .
In the most common setting, for a prime , the nonzero residues mod under multiplication. This group is cyclic and has order . The group operation is written multiplicatively, so means multiplied by itself times, reduced mod .
The forward direction is fast
Computing uses repeated squaring. Write in binary, square repeatedly, and multiply together the squares that match the 1-bits of . For an exponent with bits this takes about modular multiplications, so the cost grows with the number of digits of , not with its size.
The same fact is stated in algorithm terms: with the bit length of and of similar size, the forward cost is polynomial in .
The backward direction is the problem
The simplest method is to compute and stop when appears. This needs up to steps. A cleverer method is baby-step giant-step. Let , store for in a table, then test for until it appears in the table. This needs about steps and memory, so it is much better than brute force but still exponential in the number of digits of .
For with prime, the best known attacks are sub-exponential, through index-calculus methods, and no polynomial-time classical algorithm is known. Those are the facts the cryptographic argument relies on. The problem is not proven hard; only the absence of a known fast method is established.
Key result: the baby-step giant-step count
For a group of order , the search needs about table entries and about tests. Doubling the number of digits of roughly squares the work. This is why key sizes grow with the group order, and why the cost is measured with big-O notation as .
Key result: the role of the factorisation of
The group order matters. The Pohlig–Hellman method splits the problem into one subproblem per prime factor of , each in a subgroup of prime order. The total cost is dominated by the largest prime factor of (about steps with baby-step giant-step). So a safe choice of prime has for a large prime , and the problem lives in a subgroup of order where the easy shortcuts vanish.
Worked examples
Here , , . The exponent is small, so a direct search works.
- .
- .
- .
- .
The fourth power matches , so .
Interpretation. Four multiplications were enough because is small. The same search on a group with elements would be infeasible by brute force, which is the point of the problem.
Use , , , so and .
- Baby steps: compute for . The values are . Store them in a table with their exponents.
- Compute , the inverse of mod 17. Since , the inverse is 4.
- Giant steps: set . It is not in the table.
- Set . The value 1 is in the table at .
- Write with and . Then .
Interpretation. Six table operations (four stores and two lookups) found the answer. The method scales as , so for a group with near it would still need about steps, which is why the parameters are chosen with a large .
This example is illustrative only and uses numbers far too small to be secure. Take and . Alice picks a secret exponent and publishes .
- .
- .
- , so .
An eavesdropper sees and wants . With the eavesdropper can simply test until one equals 8, and reach after six tries. The example shows the mechanism, not its security.
Interpretation. The public value hides only as long as the search is expensive. Real systems use groups where the search is far beyond reach, and the attacker's problem is exactly the discrete logarithm.
Tradeoffs and failure modes
The problem is a good building block only when its parameters are chosen carefully. The main ways to get it wrong are listed below.
| Situation | Problem | Better choice |
|---|---|---|
| Small prime | Brute force or baby-step giant-step finishes quickly. | Choose large, so is out of reach. |
| has only small prime factors | Pohlig–Hellman reduces the problem to small subgroups and solves each one. | Choose a safe prime, where is also prime. |
| Reusing exponents or nonces | Repeated values can leak the secret. | Draw fresh random exponents for each session. |
| Trusting a generator without checking | A small-order element makes the group much smaller than assumed. | Validate that the element has the expected large order. |
| Assuming the problem is proven hard | Only the lack of a known fast algorithm is established. | Treat parameter choices as conservative and follow current guidance. |
A common mistake is to think that "the discrete log is hard" means it is impossible. It means that no fast general method is known, which can change if a new algorithm appears or if a quantum computer runs Shor's algorithm. Shor's algorithm solves the problem in polynomial time on a quantum computer, so the hardness assumption is only about classical machines.
History
Discrete logarithms were studied as a number-theoretic question long before they were used in cryptography. Carl Friedrich Gauss worked with primitive roots modulo primes in the Disquisitiones Arithmeticae (1801), which is the algebra underlying the problem.
The cryptographic use began in 1976, when Whitfield Diffie and Martin Hellman published New Directions in Cryptography. They proposed a key exchange in which two parties agree on a secret using only public values, and the security of the exchange rests on the difficulty of computing discrete logarithms. The idea spread quickly because it solved a problem that had been hard before: sharing a secret over an insecure channel without meeting in advance.
Algorithms for the problem improved over the following decades. Daniel Shanks's baby-step giant-step (early 1970s) and the Pohlig–Hellman method (1978) came first, and index-calculus methods followed for groups like . Those advances are why key sizes grew over time.
Check yourself
QuestionIn with generator , what is the discrete logarithm of ?Show answer
Compute powers of 3 mod 17 until you reach 16. The sequence is for exponents to . Check the last step: , and . So .
QuestionWhy does baby-step giant-step need about steps when the group has elements?Show answer
The method stores about baby steps and then tests about giant steps. Each giant step covers a block of exponents. Together the two parts cover all possible exponents, and the work is roughly .
QuestionWhy is a safe prime , where is also prime, a better choice than an arbitrary prime?Show answer
Pohlig–Hellman solves the problem separately for each prime-power part of the group order, so its cost is set by the largest prime factor of . For a safe prime, with a large prime, so the subproblem of size is still hard and the shortcut gains almost nothing. If is built only from small primes, the problem breaks into small pieces that are easy to solve.
QuestionA system uses the discrete logarithm problem with a group of about elements. Roughly how many steps does baby-step giant-step need, and is that feasible?Show answer
Baby-step giant-step needs about steps. A count of operations is far beyond any current computer, so the method is infeasible at this size. This illustrates why the group order is chosen to be very large.