Basic number theory

 

Multiplicative inverses modulo m

The multiplicative group of integers modulo m is defined as: (1)Zm={a | gcd(a,m)=1} But why? This is because Euler’s theorem says that: (2)gcd(a,m)=1aϕ(m)=1 This in turn, implies that every element in Zm has an inverse, since: (3)aaϕ(m)1=1 Thus, for a prime p, all elements in Zp={1,2,,p1} have inverses. Specifically, the inverse of aZp is ap2.

Finding primitive roots mod p

Suppose you have Zp={1,2,3,,p2,p1}: i.e., the group of integers mod p, where p is a prime.

How do you find a generator g for it? (a.k.a., primitive roots) (4)g=def{g0,g1,g2,,gp2}=Zp

First, you factor its order p1 as (5)p1=iqiei, where qi are primes

Second, you simply brute-force: you pick a potential candidate generator g and ensure: (6)i,gp1qi1(modp) If all these checks pass, then g is a generator.