Post · 1 min read· p. 127

Basic number theory

Multiplicative inverses modulo mm

The multiplicative group of integers modulo mm is defined as:

Zm∗={a ∣ gcd⁡(a,m)=1}\begin{align} \Z_m^* = \{a\ |\ \gcd(a,m) = 1\} \end{align}
But why? This is because Euler’s theorem says that:
gcd⁡(a,m)=1⇒aϕ(m)=1\begin{align} \gcd(a,m) = 1\Rightarrow a^{\phi(m)} = 1 \end{align}
This in turn, implies that every element in Zm∗\Z_m^* has an inverse, since:
a⋅aϕ(m)−1=1\begin{align} a\cdot a^{\phi(m) - 1} &= 1 \end{align}
Thus, for a prime pp, all elements in Zp∗={1,2,…,p−1}\Z_p^* = \{1,2,\dots, p-1\} have inverses. Specifically, the inverse of a∈Zp∗a \in \Z_p^* is ap−2a^{p-2}.

Finding primitive roots mod pp

Suppose you have \Zp∗={1,2,3,…,p−2,p−1}\Zp^* = \{1,2,3,\ldots,p-2,p-1\}: i.e., the group of integers mod pp, where pp is a prime.

How do you find a generator gg for it? (a.k.a., primitive roots)

⟨g⟩\bydef{g0,g1,g2,…,gp−2}=\Zp∗\begin{align} \langle g\rangle \bydef \{g^0, g^1, g^2,\ldots,g^{p-2}\}= \Zp^* \end{align}

First, you factor its order p−1p-1 as

p−1=∏iqiei, where qi are primes\begin{align} p-1=\prod_i q_i^{e_i},\ \text{where}\ q_i\ \text{are primes} \end{align}

Second, you simply brute-force: you pick a potential candidate generator gg and ensure:

∀i,gp−1qi≠1(modp)\begin{align} \forall i, g^\frac{p-1}{q_i} \ne 1 \pmod p \end{align}
If all these checks pass, then gg is a generator.