galois¶
A performant numpy extension for Galois fields.
Galois Fields¶
Galois field class creation
|
Factory function to construct a Galois field array class for \(\mathrm{GF}(p^m)\). |
|
Alias of |
|
Creates an array over \(\mathrm{GF}(p^m)\). |
|
Defines a metaclass for all |
Pre-made Galois field classes
|
Creates an array over \(\mathrm{GF}(2)\). |
Prime field functions
|
Finds the smallest primitive root modulo \(n\). |
|
Finds all primitive roots modulo \(n\). |
|
Determines if \(g\) is a primitive root modulo \(n\). |
Extension field functions
|
Returns a degree-\(m\) irreducible polynomial \(f(x)\) over \(\mathrm{GF}(p)\). |
|
Returns all degree-\(m\) irreducible polynomials \(f(x)\) over \(\mathrm{GF}(p)\). |
|
Checks whether the polynomial \(f(x)\) over \(\mathrm{GF}(p)\) is irreducible. |
|
Returns a degree-\(m\) primitive polynomial \(f(x)\) over \(\mathrm{GF}(p)\). |
|
Returns all degree-\(m\) primitive polynomials \(f(x)\) over \(\mathrm{GF}(p)\). |
|
Checks whether the polynomial \(f(x)\) over \(\mathrm{GF}(p)\) is primitive. |
|
Returns the degree-\(n\) Conway polynomial \(C_{p,n}\) over \(\mathrm{GF}(p)\). |
|
Finds the smallest primitive element \(g(x)\) of the Galois field \(\mathrm{GF}(p^m)\) with degree-\(m\) irreducible polynomial \(f(x)\) over \(\mathrm{GF}(p)\). |
|
Finds all primitive elements \(g(x)\) of the Galois field \(\mathrm{GF}(p^m)\) with degree-\(m\) irreducible polynomial \(f(x)\) over \(\mathrm{GF}(p)\). |
|
Determines if \(g(x)\) is a primitive element of the Galois field \(\mathrm{GF}(p^m)\) with degree-\(m\) irreducible polynomial \(f(x)\) over \(\mathrm{GF}(p)\). |
|
Computes the minimal polynomial \(m_e(x) \in \mathrm{GF}(p)[x]\) of a Galois field element \(e \in \mathrm{GF}(p^m)\). |
Galois fields for cryptography
|
Returns the Galois field for the first Oakley group from RFC 2409. |
|
Returns the Galois field for the second Oakley group from RFC 2409. |
|
Returns the Galois field for the third Oakley group from RFC 2409. |
|
Returns the Galois field for the fourth Oakley group from RFC 2409. |
Polynomials over Galois Fields¶
Polynomial classes
|
Create a polynomial \(f(x)\) over \(\mathrm{GF}(p^m)\). |
Polynomial functions
|
Finds the greatest common divisor of two polynomials \(a(x)\) and \(b(x)\) over \(\mathrm{GF}(q)\). |
|
Efficiently exponentiates a polynomial \(f(x)\) to the power \(k\) reducing by modulo \(g(x)\), \(f(x)^k\ \textrm{mod}\ g(x)\). |
|
Factors the polynomial \(f(x)\) into a product of \(n\) irreducible factors \(f(x) = g_0(x)^{k_0} g_1(x)^{k_1} \dots g_{n-1}(x)^{k_{n-1}}\) with \(k_0 \le k_1 \le \dots \le k_{n-1}\). |
Create specific polynomials
|
Returns a degree-\(m\) irreducible polynomial \(f(x)\) over \(\mathrm{GF}(p)\). |
|
Returns all degree-\(m\) irreducible polynomials \(f(x)\) over \(\mathrm{GF}(p)\). |
|
Returns a degree-\(m\) primitive polynomial \(f(x)\) over \(\mathrm{GF}(p)\). |
|
Returns all degree-\(m\) primitive polynomials \(f(x)\) over \(\mathrm{GF}(p)\). |
|
Returns the degree-\(n\) Conway polynomial \(C_{p,n}\) over \(\mathrm{GF}(p)\). |
|
Computes the minimal polynomial \(m_e(x) \in \mathrm{GF}(p)[x]\) of a Galois field element \(e \in \mathrm{GF}(p^m)\). |
Polynomial tests
|
Determines whether the polynomial is monic, i.e. having leading coefficient equal to 1. |
|
Checks whether the polynomial \(f(x)\) over \(\mathrm{GF}(p)\) is irreducible. |
|
Checks whether the polynomial \(f(x)\) over \(\mathrm{GF}(p)\) is primitive. |
Linear Sequences¶
|
Finds the minimum-degree polynomial \(c(x)\) that produces the sequence in \(\mathrm{GF}(p^m)\). |
Forward Error Correcting Codes¶
BCH Codes
|
Constructs a primitive, narrow-sense binary \(\textrm{BCH}(n, k)\) code. |
|
Returns a list of \((n, k, t)\) tuples of valid primitive binary BCH codes. |
|
Returns the generator polynomial for the primitive binary \(\textrm{BCH}(n, k)\) code. |
|
Returns the generator matrix for the primitive binary \(\textrm{BCH}(n, k)\) code. |
Modular Arithmetic¶
|
Finds the integer multiplicands of \(a\) and \(b\) such that \(a x + b y = \mathrm{gcd}(a, b)\). |
|
Computes the least common multiple of the integer arguments. |
|
Solves the simultaneous system of congruences for \(x\). |
|
Computes the integer square root of \(n\) such that \(\textrm{isqrt}(n)^2 \le n\). |
|
Finds the integer \(k\)-th root \(x\) of \(n\), such that \(x^k \le n\). |
|
Finds the integer \(\textrm{log}_b(n) = k\), such that \(b^k \le n\). |
|
Efficiently exponentiates an integer \(a^k (\textrm{mod}\ m)\). |
|
Determines whether the multiplicative group \((\mathbb{Z}/n\mathbb{Z}){^\times}\) is cyclic. |
|
Finds the smallest positive integer \(m\) such that \(a^m \equiv 1\ (\textrm{mod}\ n)\) for every integer \(a\) in \(1 \le a < n\) that is coprime to \(n\). |
Counts the positive integers (totatives) in \(1 \le k < n\) that are relatively prime to \(n\), i.e. \(\mathrm{gcd}(n, k) = 1\). |
|
|
Returns the positive integers (totatives) in \(1 \le k < n\) that are coprime with \(n\), i.e. \(\mathrm{gcd}(n, k) = 1\). |
Discrete Logarithms¶
|
Computes the discrete logarithm \(x = \textrm{log}_{\alpha}(\beta)\ (\textrm{mod}\ m)\). |
Primes¶
Prime numbers
|
Returns all primes \(p\) for \(p \le n\). |
|
Returns the \(k\)-th prime. |
|
Returns the nearest prime \(p\), such that \(p \le n\). |
|
Returns the nearest prime \(p\), such that \(p > n\). |
|
Returns a random prime \(p\) with \(b\) bits, such that \(2^b \le p < 2^{b+1}\). |
|
Returns all known Mersenne exponents \(e\) for \(e \le n\). |
|
Returns all known Mersenne primes \(p\) for \(p \le 2^n - 1\). |
Primality tests
|
Determines if \(n\) is prime. |
Determines if \(n\) is composite. |
|
|
Determines if \(n\) is composite. |
Prime factorization
Computes the prime factors of the positive integer \(n\). |
|
|
Determines if the positive integer \(n\) is \(B\)-smooth, i.e. all its prime factors satisfy \(p \le B\). |