galois.primitive_element(irreducible_poly: Poly, method: 'min' | 'max' | 'random' = 'min') Poly

Finds a primitive element \(g\) of the Galois field \(\mathrm{GF}(q^m)\) with degree-\(m\) irreducible polynomial \(f(x)\) over \(\mathrm{GF}(q)\).

Parameters:
irreducible_poly: Poly

The degree-\(m\) irreducible polynomial \(f(x)\) over \(\mathrm{GF}(q)\) that defines the extension field \(\mathrm{GF}(q^m)\).

method: 'min' | 'max' | 'random' = 'min'

The search method for finding the primitive element.

Returns:

A primitive element \(g\) of \(\mathrm{GF}(q^m)\) with irreducible polynomial \(f(x)\). The primitive element \(g\) is a polynomial over \(\mathrm{GF}(q)\) with degree less than \(m\).

Examples

Construct the extension field \(\mathrm{GF}(7^5)\).

In [1]: f = galois.irreducible_poly(7, 5, method="max"); f
Out[1]: Poly(x^5 + 6x^4 + 6x^3 + 6x^2 + 6x + 6, GF(7))

In [2]: GF = galois.GF(7**5, irreducible_poly=f, repr="poly")

In [3]: print(GF.properties)
Galois Field:
  name: GF(7^5)
  characteristic: 7
  degree: 5
  order: 16807
  irreducible_poly: x^5 + 6x^4 + 6x^3 + 6x^2 + 6x + 6
  is_primitive_poly: False
  primitive_element: x + 3

Find the smallest primitive element for the degree-5 extension of \(\mathrm{GF}(7)\) with irreducible polynomial \(f(x)\).

In [4]: g = galois.primitive_element(f); g
Out[4]: Poly(x + 3, GF(7))

# Convert the polynomial over GF(7) into an element of GF(7^5)
In [5]: g = GF(int(g)); g
Out[5]: GF(x + 3, order=7^5)

In [6]: g.multiplicative_order() == GF.order - 1
Out[6]: True

Find the largest primitive element for the degree-5 extension of \(\mathrm{GF}(7)\) with irreducible polynomial \(f(x)\).

In [7]: g = galois.primitive_element(f, method="max"); g
Out[7]: Poly(6x^4 + 6x^3 + 6x^2 + 6x + 3, GF(7))

# Convert the polynomial over GF(7) into an element of GF(7^5)
In [8]: g = GF(int(g)); g
Out[8]: GF(6x^4 + 6x^3 + 6x^2 + 6x + 3, order=7^5)

In [9]: g.multiplicative_order() == GF.order - 1
Out[9]: True

Find a random primitive element for the degree-5 extension of \(\mathrm{GF}(7)\) with irreducible polynomial \(f(x)\).

In [10]: g = galois.primitive_element(f, method="random"); g
Out[10]: Poly(4x^4 + 3x^3 + 4x^2 + 4x + 1, GF(7))

# Convert the polynomial over GF(7) into an element of GF(7^5)
In [11]: g = GF(int(g)); g
Out[11]: GF(4x^4 + 3x^3 + 4x^2 + 4x + 1, order=7^5)

In [12]: g.multiplicative_order() == GF.order - 1
Out[12]: True