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 read
Intuition
Every public-key exchange needs a computation that is easy to do in one direction and, as far as anyone knows, infeasible to undo in the other. Multiplication and factoring are one such pair for RSA; exponentiation and its inverse are the pair here. Raise a number to a power modulo a prime, and the answer falls out in a handful of squarings, however large the exponent (the previous page covers exactly that). Run the process backwards, given only the base, the modulus and the result, and there is no known shortcut: an attacker is reduced to something close to trying values one at a time. 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.
Mechanism
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 guaranteed to be at most . For most , though, it is smaller than that, 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 .
Worked example
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 this row as , which is wrong: , and , not . This is a source arithmetic slip, not a different convention. Every other explicitly printed row (rows to , , , ) matches the computation above exactly, and the source’s own next line, , is only reachable by doubling the correct , not the printed (doubling gives , not ). Rows through are not printed in the source at all: it shows the first six rows, an ellipsis, then jumps to rows and . They are filled in here by the same repeated-doubling computation so the order- claim can be checked in full.
Aside
The six primitive roots of are not a separate fact to memorise: they fall out of the table above. A power is itself a primitive root exactly when , since only then does generate the full cycle rather than a shorter one. The values of 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.
Mechanism
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.
Mechanism
Two directions, two different costs.
Forward: exponentiation, easy. Given , and , computing is fast: the previous page’s square-and-multiply method does it in about modular multiplications, regardless of how 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 for means scanning the table until lands on . Row gives , so . That search only finishes at a glance here because is small enough to hold the whole table in view. The lecture’s point survives the toy scale: for a prime with hundreds of digits, the equivalent search space is far too large to scan, and no faster general algorithm is known.
Exam detail
“No known faster algorithm” is doing real work in that last sentence: it is a computational hardness assumption, not a proof. Nobody has proven the discrete logarithm problem is hard in the way would make precise; 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. This is the same status RSA’s hardness assumption has, and the exam draws the same distinction for both: believed hard, not proven hard.
Mechanism
This asymmetry, 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.
Source
Week 4 Number Theory PDF