Skip to content

Primitive Roots and Discrete Logarithms

Definition. The order of aa modulo nn (gcd⁡(a,n)=1\gcd(a, n) = 1) is the smallest positive dd with ad≡1(modn)a^d \equiv 1 \pmod n. It always exists (Fermat/Euler bound it by p−1p - 1, φ(n)\varphi(n)) and divides every exponent that kills aa: if ak≡1a^k \equiv 1 then d∣kd \mid k.

Proof of the division fact. Write k=qd+rk = qd + r, 0≤r<d0 \leq r < d. Then ak=(ad)qar≡ar≡1a^k = (a^d)^q a^r \equiv a^r \equiv 1; minimality of dd forces r=0r = 0. ■\blacksquare

Worked example. Powers of 3 mod 7: 3,2,6,4,5,13, 2, 6, 4, 5, 1; order 6 = φ(7)\varphi(7).

Definition. gg is a primitive root modulo nn if the order of gg is φ(n)\varphi(n), i.e. the powers of gg run through all units:

{g1,g2,…,gφ(n)}={1≤a<n:gcd⁡(a,n)=1}.\{g^1, g^2, \ldots, g^{\varphi(n)}\} = \{1 \leq a < n : \gcd(a, n) = 1\}.

Equivalently gg generates the group of units, and every unit is gkg^k for exactly one k∈{1,…,φ(n)}k \in \{1, \ldots, \varphi(n)\}.

Theorem (Gauss). nn possesses a primitive root if and only if n∈{1,2,4,pk,2pk}n \in \{1, 2, 4, p^k, 2p^k\} for odd primes pp.

So primitive roots exist for every odd prime power (and 2, 4), but not for n=8n = 8 (squares of odd units are ≡1(mod8)\equiv 1 \pmod 8) nor for most even moduli.

Example. Mod 7, the order of 3 is 6 = φ(7)\varphi(7), so 3 is a primitive root; every unit is a power of 3. Mod 7, 2 has order 3 (2,4,12, 4, 1); not a primitive root.

If gg is a primitive root mod nn and gcd⁡(a,n)=1\gcd(a, n) = 1, the index of aa (base gg) is the unique kk with a≡gk(modn)a \equiv g^k \pmod n; the discrete logarithm. Indices turn multiplication into addition, exactly like logarithms:

ind⁡g(ab)≡ind⁡g(a)+ind⁡g(b)(modφ(n)).\operatorname{ind}_g(ab) \equiv \operatorname{ind}_g(a) + \operatorname{ind}_g(b) \pmod{\varphi(n)}.

They are the computational engine of old-style power-congruence problems, and their one-way hardness (computing ind⁡\operatorname{ind} from gkg^k) underlies Diffie–Hellman key exchange; see Number Theory and Cryptography.

The order of any unit divides φ(n)\varphi(n); gg is primitive iff gφ(n)/q≢1g^{\varphi(n)/q} \not\equiv 1 for every prime q∣φ(n)q \mid \varphi(n). Testing the prime factors only is the standard shortcut.

Example. Mod 31, φ(31)=30=2⋅3⋅5\varphi(31) = 30 = 2 \cdot 3 \cdot 5. Test 3: 315≡3^{15} \equiv (compute) ≢1\not\equiv 1, 310≡26≢13^{10} \equiv 26 \not\equiv 1, 36=729≡16≢13^6 = 729 \equiv 16 \not\equiv 1: order 30; 3 is a primitive root mod 31.

The number of primitive roots mod pp is φ(p−1)\varphi(p - 1), and they are exactly gkg^k for gcd⁡(k,p−1)=1\gcd(k, p-1) = 1.

  • Power equation solvability: xm≡a(modp)x^m \equiv a \pmod p (with gg a primitive root and ind⁡(a)=b\operatorname{ind}(a) = b) reduces to the linear congruence mk≡b(modp−1)m k \equiv b \pmod{p - 1} in indices; solvable iff gcd⁡(m,p−1)∣b\gcd(m, p-1) \mid b.
  • Quadratic residues are exactly the even-index powers: see Quadratic Residues.
  • Products of two squares and related characterisations fall out of the index parity.
  • Checking only g(p−1)/2≢1g^{(p-1)/2} \not\equiv 1 does not prove gg is primitive; all prime factors of p−1p - 1 must be excluded.
  • Primitive roots exist only for n∈{1,2,4,pk,2pk}n \in \{1, 2, 4, p^k, 2p^k\}: there is no primitive root mod 8 or mod 15; “find a primitive root mod 15” is a trick question.
  • ind⁡\operatorname{ind} values live modulo φ(n)\varphi(n), and the discrete log of a sum is not the sum of discrete logs.

Solve 3x≡5(mod7)3^x \equiv 5 \pmod 7 using index tables base 3: ind⁡3(5)=5\operatorname{ind}_3(5) = 5 and ind⁡3(3)=1\operatorname{ind}_3(3) = 1, so x≡5(mod6)x \equiv 5 \pmod 6; the linear-congruence method from the CRT page.

ind⁡g(ab)≡ind⁡g(a)+ind⁡g(b)(modφ(n))\operatorname{ind}_g(ab) \equiv \operatorname{ind}_g(a) + \operatorname{ind}_g(b) \pmod{\varphi(n)}

Index arithmetic converts multiplication problems into linear congruences. To compute 317(mod7)3^{17} \pmod{7} when 3 has order 6: reduce the exponent 17 modulo 6 to 5, and read off 35≡5(mod7)3^5 \equiv 5 \pmod 7 from the power table. State the order reduction step explicitly.

ind⁡g(ab)≡ind⁡g(a)+ind⁡g(b)(modφ(n))\operatorname{ind}_g(ab) \equiv \operatorname{ind}_g(a) + \operatorname{ind}_g(b) \pmod{\varphi(n)}

Index arithmetic converts multiplication problems into linear congruences. To compute 317(mod7)3^{17} \pmod 7 when 3 has order 6: reduce the exponent 17 modulo 6 to 5, and read off 35≡5(mod7)3^5 \equiv 5 \pmod 7 from the power table. State the order reduction step explicitly.