Lesson 14 of 15
Finite Fields
Finite Fields
A finite field (or Galois field) has exactly elements, where must be a prime power: .
— Prime Fields
When , . These are the simplest finite fields.
Multiplicative Group Structure
The nonzero elements of form a cyclic group under multiplication. A primitive root (generator of this group) satisfies:
Finding Primitive Roots
An element is a primitive root mod if and only if for every prime factor of .
Discrete Logarithm
Given a primitive root , the discrete logarithm is the unique such that .
def discrete_log(g, a, p):
power = 1
for k in range(p - 1):
if power == a:
return k
power = (power * g) % p
return -1
The difficulty of computing discrete logarithms in large fields is the basis of many cryptographic systems.
Your Task
Implement is_primitive_root(g, p), find_primitive_roots(p) returning all sorted primitive roots, and discrete_log(g, a, p).
Pyodide loading...
Loading...
Click "Run" to execute your code.