Discrete logarithms and primitive roots
The order of an element modulo a prime, the primitive-root condition, the discrete logarithm problem, and why one direction is easy while the other is believed hard.
- Define the order of an element modulo p and state the condition that makes it a primitive root.
- Verify that 2 is a primitive root of 19 by computing its full sequence of powers.
- State the discrete logarithm problem and identify which direction is easy and which is hard.
- Explain why that asymmetry is what Diffie-Hellman key exchange relies on.
16 min readJump to the quiz ↓
A primitive root has the maximum order, so its powers visit every nonzero residue
Every public-key exchange needs a computation that is easy in one direction and, as far as anyone knows, infeasible to undo in the other. Raise a number to a power modulo a prime and the answer falls out in a handful of squarings, however large the exponent. Run the process backwards, given only the base, the modulus and the result, and there is no known shortcut. That one-way street is called the discrete logarithm problem, and Diffie-Hellman key exchange, covered in Module 6, is built directly on top of it.
For a prime and an integer not divisible by , the order of modulo is the smallest positive with . By Fermat’s little theorem, always holds, so the order of is at most . For most it is smaller, meaning the powers of cycle back to early and never touch some of the other nonzero residues.
An element whose order is exactly , the maximum possible, is a primitive root of . Its powers run through every nonzero residue modulo exactly once before returning to .
Try it — worked example
Is 2 a primitive root of 19? Find its order.
Show answer and steps
Answer2 is a primitive root of 19, with order 18
The lecture demonstrates this for , , printing rows through of the table, an ellipsis, and then rows and . The full sequence, computed the same way at every step (multiply the previous result by and reduce), is below.
- All eighteen values are distinct, and is the first power to return to . So the order of modulo is , and is a primitive root.
Pitfall
Row above is . The Week 4 supplement prints , which is wrong: , and . The source’s own next line, , is only reachable by doubling the correct (doubling gives ). Rows through are not printed in the source at all, and are filled in here by the same repeated-doubling computation so the order- claim can be checked in full.
Optional aside
The six primitive roots of fall out of the table above. A power is itself a primitive root exactly when , since only then does generate the full cycle. The from to coprime to are , and there are of them. Reading those rows off the table: , , , , , . Sorted, that set is , exactly the primitive roots the lecture lists.
Exponentiation is easy and its inverse, the discrete logarithm, is not
Ordinary logarithms invert exponentiation: given , recovers . The discrete logarithm is the modular analogue. For a prime and a primitive root of ,
Formula
Discrete logarithm problem (DLP)
- a prime
- a primitive root of p
- the discrete logarithm of y to base g
- the result, given
Given g, x, p, finding y is easy. Given g, y, p, finding x is not: the DLP asks for the second direction.
The two directions have different costs.
Forward: exponentiation, easy. Given , and , computing is fast: the previous page’s square-and-multiply method does it in about modular multiplications, however large is. For , , : , matching row of the table above.
Reverse: the discrete logarithm, hard. Given , and , finding has no known method faster than something close to exhaustive search over every possible exponent. For , , : solving means scanning the table until lands on . Row gives , so . That search only finishes at a glance because is small enough to hold the whole table in view. For a prime with hundreds of digits the search space is far too large to scan, and no faster general algorithm is known.
Exam detail
“No known faster algorithm” is a computational hardness assumption, not a proof. Nobody has proven the discrete logarithm problem hard; the best known general attacks (index calculus and its relatives) are still exponential or sub-exponential in the size of , and every cryptosystem built on the DLP is only as secure as that gap holding up. RSA’s hardness assumption has the same status, and the exam draws the same distinction for both: believed hard, not proven hard.
That asymmetry is what Diffie-Hellman builds on
Cheap to compute forward and expensive to invert is precisely what a public-key exchange needs. Diffie-Hellman key exchange, covered in Diffie-Hellman key exchange, has each party publish and over an open channel while keeping and private. Anyone listening sees , , and both public values, and reconstructing either private exponent from those is exactly the discrete logarithm problem. Public-key cryptography and trapdoor functions covers where this fits alongside the RSA problem as one of the two hardness assumptions Module 6 is built on.
Recall
Why does knowing the discrete logarithm problem is hard tell you nothing about how hard it is to compute g^x mod p in the forward direction?
They are different computations with different costs. Forward exponentiation has an efficient algorithm (square-and-multiply) regardless of how large is. The discrete logarithm problem is about the absence of an efficient algorithm for the reverse direction: recovering from , and . A problem can be trivially easy one way and believed infeasible the other way at the same time; that gap is the entire point.
Check yourself
Source
Week 4 Number Theory PDF