6 Primitive Roots and The Discrete Logarithm: 6.1 The Order of An Integer
6 Primitive Roots and The Discrete Logarithm: 6.1 The Order of An Integer
Definition 6.1. Let a, n be relatively prime integers with a 6= 0 and n positive. Then the
least positive integer x such that ax ≡ 1 mod n is called the order of a modulo n, written
ordn a.
21 ≡ 2 mod 7 31 ≡ 3 mod 7
22 ≡ 4 mod 7 32 ≡ 9 ≡ 2 mod 7
23 ≡ 1 mod 7 33 ≡ 27 ≡ 6 mod 7
34 ≡ 81 ≡ 4 mod 7
35 ≡ 4 · 3 ≡ 12 ≡ 5 mod 7
36 ≡ 5 · 3 ≡ 15 ≡ 1 mod 7.
Lemma 6.3. If a, n are relatively prime integers with a 6= 0 and n > 0, then a positive
integer x is a solution to the congruence ax ≡ 1 mod n if and ony if ordn a|x.
http://jaydaigle.net/teaching/courses/2019-fall-322/ 66
Jay Daigle Occidental College Math 322: Number Theory
Proof. First suppose ordn a|x. Then we can write x = m · ordn a for some integer m, and we
have
m
ax ≡ am·ordn a ≡ aordn a ≡ 1m ≡ 1 mod n.
Conversely, suppose ax ≡ 1 mod n, we can use the division algorithm divide x by ordn a
and write
x = q · ordn a + r, 0 ⇒ r < ordn a.
Then we compute
so we have ar ≡ 1 mod n but 0 ≤ r < ordn a. But ordn a is by definition the least positive
integer with this property, so r cannot be positive and must be 0. Thus x = q · ordn a as
desired.
Remark 6.4. This should remind you of the proof that since (a, b) is the least linear combi-
nation of a and b, we know that m is a linear combination of a and b if and only if (a, b)|m.
Example 6.5. Let’s see if 10, 20, or 30 are solutions to 3x ≡ 1 mod 7. We saw that
ord7 3 = 6, so 330 ≡ 1 mod 7 since 6|30. But 320 6≡ 1 mod 7 and 310 6≡ 1 mod 7 since
66 |10, 20.
Proof. Since (a, n) = 1 we know that aφ(n) ≡ 1 mod n, thus ordn a|φ(n).
We can use this to make it easier to compute orders: we only need to check numbers that
divide φ(n).
Example 6.7. Let’s find the order of 7 modulo 9. We can compute that φ(9) = 3(3−1) = 6,
so we just need to check 1, 2, 3, 6. We see
71 ≡ 7 6≡ 1 mod 9
72 ≡ 49 ≡ 4 6≡ 1 mod 9
73 ≡ 4 · 7 ≡ 28 ≡ 1 mod 9
http://jaydaigle.net/teaching/courses/2019-fall-322/ 67
Jay Daigle Occidental College Math 322: Number Theory
Example 6.8. Let’s find ord11 3. We know that φ(11) = 10 so we just need to check
1, 2, 5, 10. We have
31 ≡ 3 6≡ 1 mod 11
32 ≡ 9 6≡ 1 mod 11
35 ≡ 243 = 11(22) + 1 ≡ 1 mod 11
so ord11 3 = 5. This saves us from checking 3 or 4 since we know they can’t be the answer.
Remark 6.9. Note that sometimes ordn a = φ(n). For instance, you can check that ord11 2 =
10.
Proof. First, let’s suppose i ≡ j mod ordn a, and assume that i ≥ j. Then there is some k
such that i = j + k · ordn a, and we have
ai ≡ aj+k·ordn a ≡ aj · ak·ordn a
≡ aj · (aordn a )k ≡ aj · 1k ≡ aj mod n.
ai ≡ aj mod n
aj · ai−j ≡ aj mod n
ai−j ≡ 1 mod n
since (a, n) = 1 and thus (aj , n) = 1 so we can use the cancellation lemma. But if ai−j ≡ 1
mod n then by lemma 6.3 we know that ordn a|i − j, and so by defnition i ≡ j mod ordn a.
Definition 6.11. If (a, n) = 1, and ordn a = φ(n), we say that a is a primitive root modulo
n, and we say that n has a primitive root.
http://jaydaigle.net/teaching/courses/2019-fall-322/ 68
Jay Daigle Occidental College Math 322: Number Theory
Example 6.13. The number 8 does not have a primitive root. The integers relatively prime
to 8 are 1,3,5,7. We can compute ord8 1 = 1 and ord8 3 = ord8 5 = ord8 7 = 2, but φ(8) = 4.
Every prime number has a primitive root; we will prove this in subsection 6.3. Not every
composite number has a primitive root, but some, like 6 and 10, do.
Theorem 6.14. If (r, n) = 1 and n > 0, and r is a primitive root modulo n, then the set
{r1 , r2 , . . . , rφ(n) } is a reduced residue system modulo n.
Proof. This set clearly has the correct size, so we need to prove that these numbers are all
relatively prime to n and that no two are congruent modulo n.
Because (r, n) = 1 we know that (rk , n) = 1 for any natural number k. This satisfies the
first requirement.
Suppose ri ≡ rj mod n. Then by lemma 6.10 we know that i ≡ j mod ordn r. But r is
a primitive root, which means that ordn r = φ(n). Thus φ(n)|i − j but 1 ≤ i, j ≤ φ(n) and
thus i = j.
Example 6.15. We showed that ord7 3 = 6 so 3 is a primitive root modulo 7. Thus the set
We already noted that not every integer has a primitive root. But if an integer has a
primitive root it usually has several more. We will spend the rest of this subsection making
that statement more precise.
Lemma 6.16. Let n be a natural number, and (a, n) = 1, and set ordn a = t. Then for any
u ∈ N we have
t
ordn au = .
(u, t)
http://jaydaigle.net/teaching/courses/2019-fall-322/ 69
Jay Daigle Occidental College Math 322: Number Theory
Proof. First set t1 = t/(u, t) and u1 = u/(u, t), and set s = ordn au . We know that (t1 , u1 ) =
1. Now we want to show that s = t1 .
First we want to show that (au )t1 ≡ 1 mod n. But
Corollary 6.17. Let r be a primitive root modulo n. Then ru is a primitive root modulo n
if and only if (u, φ(n)) = 1.
So if a number n has a primitive root, how many does it have? It must have one for
every exponent that’s relatively prime to φ(n).
Corollary 6.18. If a positive integer n has a primitive root, it has exactly φ(φ(n)) primitive
roots.
Proof. Let r be a primitive root modulo n. Then ru is a primitive root if and only if
(u, φ(n)) = 1; there are φ(φ(n)) numbers relatively prime to φ(n).
(Every primitive root must have the form ru for some u, since these are all the numbers
relatively prime to n).
Example 6.19. We claimed earlier that ord11 2 = 10, and thus 2 is a primitive root modulo
11. This tells us that 11 has φ(φ(11)) = φ(10) = 4 incongruent primitive roots. In particular,
these roots are 2, 23 = 8, 27 = 128 ≡ 7, 29 = 512 ≡ 6. Thus {2, 6, 7, 8} is a complete set of
incongruent primitive roots modulo 11.
This result does have one weakness: it tells us what happens if there are any primitive
roots modulo n, but doesn’t tell us which integers n have any primitive roots at all.
http://jaydaigle.net/teaching/courses/2019-fall-322/ 70
Jay Daigle Occidental College Math 322: Number Theory
Definition 6.20. Let f (x) be a polynomial with integer coefficients. We say c is a root of f
modulo m if f (c) ≡ 0 mod m. (This is the same idea as a root in the integers, except we’re
thinking about everything as belonging to the integers modulo m).
Example 6.21. The polynomial f (x) = x2 + 1 has no roots in the integers, but it has two
roots modulo 5: f (2) = 5 ≡ 0 mod 5, and f (3) = 10 ≡ 0 mod 5.
Example 6.22. Let f (x) = xp−1 − 1 for a fixed prime p. Then by Fermat’s little theorem,
f has p − 1 incongruent roots modulo p: 1, 2, 3, . . . , p − 1.
It’s a famous result in the real numbers that a polynomial of degree n has at most n
distinct roots. A similar result holds modulo p.
http://jaydaigle.net/teaching/courses/2019-fall-322/ 71
Jay Daigle Occidental College Math 322: Number Theory
Thus since p is prime, either p|g(ci ) or p|(ci − c0 ). But by hypothesis we know that ci 6= c0
mod p so p6 |ci − c0 , and thus we have p|g(ci ) and g(ci ) ≡ 0 mod p. Thus ci is a root of g
modulo p for 1 ≤ i ≤ n.
Thus g is a polynomial of degree ≤ n − 1 with n incongruent solutions, which contradicts
the inductive hypothesis.
Remark 6.24. This theorem does not hold for composite moduli. For instance, if we take
g(x) = x2 − 3x + 2, then modulo 6 we see that g(1) = 0 ≡ 0 mod 6, and g(2) = 0 ≡ 0
mod 6, and g(4) = 6 ≡ 0 mod 6.
We want to use Lagrange’s Theorem to put limits on how many elements can have a
given order modulo p.
Proposition 6.25. Let p be a prime and let d be a divisor of p − 1. Then the polynomial
f (x) = xd − 1 has exactly d incongruent roots modulo p.
Proof. We know that d|p − 1, so by the difference of nth powers formula we have (xd −
1)|xp−1 − 1. In particular
Lemma 6.26. Let p be a prime and let d|p − 1. Then there are fewer than φ(d) positive
integers less than p that have order d modulo p.
Proof. Let F (d) be the number of positive integers of order d modulo p that are less than p.
We wish to prove that F (d) ≤ φ(d).
If there are no roots of order d modulo p then it’s clear that F (d) = 0 ≤ φ(d). So suppose
there is an integer a of order d modulo p. Then the integers a, a2 , . . . , ad are all incongruent
modulo p.
http://jaydaigle.net/teaching/courses/2019-fall-322/ 72
Jay Daigle Occidental College Math 322: Number Theory
Further, we see that for any k ∈ N, we compute that (ak )d = (ad )k ≡ 1k ≡ 1 mod p, so
ak is a root of xd − 1 modulo p for any k. Thus we have d incongruent roots of xd − 1 on
this list. Since we know xd − 1 has exactly d incongruent roots modulo p, we know that the
set of roots is exactly the set a, a2 , . . . , ad .
ordp a d
By lemma 6.16, we see that ordp ak = (k,ordp a)
= (k,d)
, and thus ak has order d if and only
if (k, d) = 1. There are exactly φ(d) such integers k with 1 ≤ k ≤ d, and thus if there is one
element of order d modulo p, there are exactly φ(d) positive integers less than p of order d
modulo p. Thus F (d) ≤ φ(d).
Remark 6.27. This theorem proves that for a given d|p − 1, either there are φ(d) elements
of order d or there are 0. But we didn’t state it that way because we are about to leverage
it into an even better result.
Theorem 6.28. Let p be a prime, and let d be a positive divisor of p − 1. Then the number
of incongruent ingeters of order d modulo p is exactly φ(d).
Proof. This is essentially a counting argument. For any d|p − 1, let F (d) be the number of
positive integers of order d modulo p that are less than p. Because every integer from 1 to
p − 1 has an order dividing p − 1, we see that
X
p−1= F (d).
d|p−1
From lemma 6.26 we know that F (d) ≤ φ(d), but their sums are equal; the only way this is
possible is if F (d) = φ(d) for each d|p − 1. Thus there are exactly φ(d) incongruent integers
of order d modulo p.
Proof. Let p be a prime. Then there are exactly φ(p − 1) incongruent integers of order p − 1
modulo p by theorem 6.28. But these are all primitive roots by definition. Since φ(p−1) ≥ 1,
this completes the proof.
http://jaydaigle.net/teaching/courses/2019-fall-322/ 73
Jay Daigle Occidental College Math 322: Number Theory
This proves that every prime has a primitive root, but doesn’t give us a way to find them.
In fact locating primitive roots is not trivial; on the other hand, 2 appears to be a primitive
root quite often. But we don’t know whether it is a primitive root infinitely often.
Conjecture 6.30 (Artin). Any integer a such that a 6= ±1 and a is not a perfect square is
a primitive root of infinitely many primes.
Proposition 6.31 (Hooley 1967). The Generalized Riemann Hypothesis implies Artin’s con-
jecture.
Proposition 6.32 (Heath-Brown 1985). There are at most three positive square-free integers
a such that a is a primitive root of only finitely many primes. Thus at least one of 2, 3, 5 is
a primitive root for infinitely many primes.
http://jaydaigle.net/teaching/courses/2019-fall-322/ 74
Jay Daigle Occidental College Math 322: Number Theory
Example 6.35. We have seen that 2 is a primitive root modulo 11. But 210 = 1024 ≡ 56
mod 121 so ord121 2 6= 10. Thus we must have ord121 2 = 110 = φ(121) so 2 is a primitive
root modulo 121.
We have seen that 3 is a primitive root modulo 7. But 36 = 729 ≡ 43 6≡ 1 mod 49. Thus
ord49 3 6= 6 so ord49 3 = 42 = φ(49) and 3 is a primitive root modulo 49.
Example 6.36. Let p = 487 be prime, and we compute that ord487 10 = 486. (We do not
do this by hand). But 10486 ≡ 1 mod 4872 so 10 is not a primitive root modulo 4872 . Thus
we know that 497 = 10 + 487 is a primitive root modulo 4872 .
Lemma 6.37. Let p be an odd prime. Then pk has a primitive root for any k ∈ N. Moreover,
if r is a primitive root modulo p2 , then r is a primitive root modulo pk for any k ∈ N.
Proof. By lemma 6.33 we know that p has a primitive root r that is also a primitive root
modulo p2 , and thus rp−1 6≡ 1 mod p2 .
k−2 (p−1)
First we will prove by induction that rp 6≡ 1 mod pk for any k ≥ 2. The base
case when k = 2 follows from Lemma 6.33. Suppose the assertion is true for k, and we will
prove it for k + 1.
By inductive hypothesis, we know that
k−2 (p−1)
rp 6≡ 1 mod pk .
But also (r, p) = 1 since r is a primitive root, and thus (r, pk−1 ) = 1. Thus φ(pk−1 ) =
pk−2 (p − 1) and thus
k−2 (p−1) k−1 )
rp = rφ(p ≡1 mod pk−1 .
where p6 |d since otherwise the congruence would hold moduldo pk . We can raise both sides
http://jaydaigle.net/teaching/courses/2019-fall-322/ 75
Jay Daigle Occidental College Math 322: Number Theory
Now we wish to show that r is a primtiive root modulo pk . Let n = ordpk r. We know
that n|φ(pk ) = pk−1 (p − 1). Further, we know that ordp r = p − 1 so we must have p − 1|n.
So n = pt (p − 1) for some 0 ≤ t ≤ k − 1.
But we know that
k−2 (p−1)
rp 6≡ 1 mod pk ,
so we must have t < k − 2. Thus t = k − 1 and so ordr = pk−1 (p − 1) = φ(pk ), and r is a
primitive root modulo pk .
Example 6.38. We saw that 2 is a primitive root modulo 11 and also modulo 121. Thus 2
is a primitive root modulo 11k for any k ∈ N.
http://jaydaigle.net/teaching/courses/2019-fall-322/ 76
Jay Daigle Occidental College Math 322: Number Theory
as desried.
This shows that there is never a primitive root modulo 2k if k ≥ 3. However, there is
always an “almost primitive root”–a number whose order is as big as possible without being
a primitive root. In fact, 5 is always such a number. The proof is very similar to the last
two proofs we did.
We now have a pretty thorough understanding of when a prime power has a primitive root.
What about other composite numbers? Mostly they don’t have primitive roots.
Lemma 6.41. If n is a positive integer that is not a prime power or twice a prime power,
then n does not have a primitive root.
Proof. Let n = pt11 . . . ptmm , and suppose r is a primitive root modulo n. Then (r, n) = 1 and
ordn r = φ(n).
We know that (r, pt ) = 1 for any p in the prime factorization of n, and for any t ∈ N.
t−1 (p−1) t
Thus rp = rφ(p ) ≡ 1 mod pt .
Let U be the least common multiple of φ(ptii ) i.e.
Then since φ(ptii )|U we know that rU ≡ 1 mod ptii for every i. Thus, by the Chinese
Remainder Theorem, rU ≡ 1 mod n.
Then we must have φ(n) = ordn r ≤ U . But since φ is multiplicative, this must imply
that
φ(pt1i ) . . . φ(ptmm ) ≤ U = lcm φ(pt11 ), . . . , φ(ptmm ) .
But the product of a set of integers is always at least their least common multiple, with
equality only when all the numbers are relatively prime. So we must have the φ(ptii ) all
pairwise relatively prime.
But recall that φ(`) is even unless ` is 1 or 2. Thus in order for the φ(ptii ) to all be
pairwise relatively prime, there can be at most one ptii that is not equal to 2. Thus either
n = pt1i and is a prime power, or n = 2pt11 and is two times a prime power, as desired.
http://jaydaigle.net/teaching/courses/2019-fall-322/ 77
Jay Daigle Occidental College Math 322: Number Theory
This lemma limits which numbers can have primitive roots. We’ve shown that many of
the possibilities do in fact have primitive roots: we know that prime powers have primitive
roots as long as the prime is not 2. But we haven’t checked this case of “twice a prime
power,” so we do that now.
Lemma 6.42. If p is an odd prime and t is a positive integer, then 2pt has a primitive root.
In particular, if r is an odd primitive root modulo pt then it is also a primitive root modulo
2pt . If r is an even primitive root modulo pt then r + pt is a primitive root modulo 2pt .
Proof. If r is a primitive root modulo pt , then ordpt r = φ(pt ) = pt−1 (p − 1). We observe that
φ(2pt ) = φ(2)φ(pt ) = φ(pt ), so ordpt r = φ(2pt ) as well.
t t
If r is odd, then r ≡ 1 mod 2 so rφ(2p ) ≡ 1 mod 2. Since rφ(2p ) ≡ 1 mod pt , by the
t
Chinese Remainder Theorem we have rφ(2p ) ≡ 1 mod 2pt . But if rn ≡ 1 mod 2pt then
rn ≡ 1 mod pt , and we know ordpt r = φ(2pt ) so n ≥ 2pt . Thus ord2pt r = φ(2pt ) and thus
r is a primitive root modulo 2pt .
If r is even, then r + pt is odd and a primitive root modulo pt , and by the same argument
we see that r + pt is a primitive root modulo 2pt .
Example 6.43. We showed that 2 is a primitive root modulo 11k for any k ∈ N. Since 2 is
even, we know that 2 + 11k is a primitive root modulo 2 · 11k for any k ∈ N.
Theorem 6.44. Let n be a positive integer greater than 1. Then n possesses a primitive
root if and only if n = 2, 4, pt , or 2pt for some odd prime p and natural number t.
Definition 6.45. Let m be a natural number with primitive root r, and let a be a positive
integer with (a, m) = 1. the unique integer x with 1 ≤ x ≤ φ(m) and rx ≡ a mod m is
called the index or discrete logarithm of a to the base r modulo m, and is denoted indr a or
logr a.
http://jaydaigle.net/teaching/courses/2019-fall-322/ 78
Jay Daigle Occidental College Math 322: Number Theory
Clearly rindr a ≡ a mod m. Further, by lemma 6.10 we see that a ≡ b mod m if and
only if indr a ≡ indr b mod φ(m), indeed if and only if indr a = indr b since the index is
always between 1 and φ(m).
31 ≡ 3 mod 7 32 ≡ 9 ≡ 2 mod 7
33 ≡ 27 ≡ 6 mod 7 34 ≡ 81 ≡ 4 mod 7
35 ≡ 4 · 3 ≡ 12 ≡ 5 mod 7 36 ≡ 5 · 3 ≡ 15 ≡ 1 mod 7.
If we use a different base we get different indices. For instance, we see that 5 is a primitive
root modulo 7, and we have
We can prove that the “index” operation has most of the properties of logarithms.
Exercise 6.47. Let m be a natural number with primitive root r, and let a, b be relatively
prime to m. Then
Example 6.48. We know that modulo 7, we have ind5 2 = 4 and ind5 3 = 5. We compute
that ind5 (2 · 3) = ind5 2 + ind3 = 4 + 5, and modulo φ(7) = 6 this is indeed equivalent to
ind5 6 = 3.
Example 6.49. We can use this to solve exponential congruences. Suppose we wish to find
all solutions of 6x12 ≡ 11 mod 17. We can compute that 3 is a primitive root modulo 17,
and can compute (or look up) a table of indices of integers modulo 17.
http://jaydaigle.net/teaching/courses/2019-fall-322/ 79
Jay Daigle Occidental College Math 322: Number Theory
a 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
ind3 a 16 14 1 12 5 15 11 10 2 3 7 13 4 9 6 8
Then we have
Remark 6.51. You might notice that we did a lot of work with the cavalier statement “we
can compute a table of indices.” In fact, computing indexes or discrete logarithms is quite
computationally intensive, and there isn’t much of a better way of computing ind3 12 than
just raising 3 to a bunch of powers and seeing which one gives you 12. (Thus if you’re
computing indices at all you might as well build a table).
The fact that this problem is computationally difficult underlies the security of much
cryptography currently in use; it is comparable to the problem of factoring large integers.
Like integer factorization, the discrete logarithm problem can be solved quickly on a
quantum computer. We don’t currently have useful quantum computers, but researchers
http://jaydaigle.net/teaching/courses/2019-fall-322/ 80
Jay Daigle Occidental College Math 322: Number Theory
are worried that they will be practical in the near-to-medium future, and we are starting to
move to “lattice-based” encryption methods that do not depend on the discrete logarithm
problem.
http://jaydaigle.net/teaching/courses/2019-fall-322/ 81