galois.FieldClass¶
- class galois.FieldClass(name, bases, namespace, **kwargs)¶
Defines a metaclass for all
galois.FieldArray
classes.This metaclass gives
galois.FieldArray
classes returned fromgalois.GF()
class methods and properties relating to its Galois field.Constructors
Methods
arithmetic_table
(operation[, mode])Generates the specified arithmetic table for the Galois field.
compile
(mode)Recompile the just-in-time compiled numba ufuncs for a new calculation mode.
display
([mode])Sets the display mode for all Galois field arrays of this type.
repr_table
([primitive_element])Generates an element representation table comparing the power, polynomial, vector, and integer representations.
Attributes
The prime characteristic \(p\) of the Galois field \(\mathrm{GF}(p^m)\).
The default ufunc arithmetic mode for this Galois field.
The prime characteristic’s degree \(m\) of the Galois field \(\mathrm{GF}(p^m)\).
The representation of Galois field elements, either
"int"
,"poly"
, or"power"
.List of valid integer
numpy.dtype
objects that are compatible with this Galois field.The irreducible polynomial \(f(x)\) of the Galois field \(\mathrm{GF}(p^m)\).
Indicates if the field’s order is a prime power.
Indicates if the field’s order is prime.
Indicates whether the
irreducible_poly
is a primitive polynomial.The Galois field name.
The order \(p^m\) of the Galois field \(\mathrm{GF}(p^m)\).
The prime subfield \(\mathrm{GF}(p)\) of the extension field \(\mathrm{GF}(p^m)\).
A primitive element \(\alpha\) of the Galois field \(\mathrm{GF}(p^m)\).
All primitive elements \(\alpha\) of the Galois field \(\mathrm{GF}(p^m)\).
A formatted string displaying relevant properties of the Galois field.
The mode for ufunc compilation, either
"jit-lookup"
,"jit-calculate"
,"python-calculate"
.All supported ufunc modes for this Galois field array class.
- arithmetic_table(operation, mode='int')[source]¶
Generates the specified arithmetic table for the Galois field.
- Parameters
- Returns
A UTF-8 formatted arithmetic table.
- Return type
Examples
In [1]: GF = galois.GF(3**2) In [2]: print(GF.arithmetic_table("+")) ╔═══════╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗ ║ x + y ║ 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 ║ ╠═══════╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣ ║ 0 ║ 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 ║ ╟───────╫───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║ 1 ║ 1 │ 2 │ 0 │ 4 │ 5 │ 3 │ 7 │ 8 │ 6 ║ ╟───────╫───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║ 2 ║ 2 │ 0 │ 1 │ 5 │ 3 │ 4 │ 8 │ 6 │ 7 ║ ╟───────╫───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║ 3 ║ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 0 │ 1 │ 2 ║ ╟───────╫───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║ 4 ║ 4 │ 5 │ 3 │ 7 │ 8 │ 6 │ 1 │ 2 │ 0 ║ ╟───────╫───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║ 5 ║ 5 │ 3 │ 4 │ 8 │ 6 │ 7 │ 2 │ 0 │ 1 ║ ╟───────╫───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║ 6 ║ 6 │ 7 │ 8 │ 0 │ 1 │ 2 │ 3 │ 4 │ 5 ║ ╟───────╫───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║ 7 ║ 7 │ 8 │ 6 │ 1 │ 2 │ 0 │ 4 │ 5 │ 3 ║ ╟───────╫───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║ 8 ║ 8 │ 6 │ 7 │ 2 │ 0 │ 1 │ 5 │ 3 │ 4 ║ ╚═══════╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╝
In [3]: GF = galois.GF(3**2) In [4]: print(GF.arithmetic_table("+", mode="poly")) ╔════════╦════════╦════════╦════════╦════════╦════════╦════════╦════════╦════════╦════════╗ ║ x + y ║ 0 │ 1 │ 2 │ α │ α + 1 │ α + 2 │ 2α │ 2α + 1 │ 2α + 2 ║ ╠════════╬════════╬════════╬════════╬════════╬════════╬════════╬════════╬════════╬════════╣ ║ 0 ║ 0 │ 1 │ 2 │ α │ α + 1 │ α + 2 │ 2α │ 2α + 1 │ 2α + 2 ║ ╟────────╫────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────╢ ║ 1 ║ 1 │ 2 │ 0 │ α + 1 │ α + 2 │ α │ 2α + 1 │ 2α + 2 │ 2α ║ ╟────────╫────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────╢ ║ 2 ║ 2 │ 0 │ 1 │ α + 2 │ α │ α + 1 │ 2α + 2 │ 2α │ 2α + 1 ║ ╟────────╫────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────╢ ║ α ║ α │ α + 1 │ α + 2 │ 2α │ 2α + 1 │ 2α + 2 │ 0 │ 1 │ 2 ║ ╟────────╫────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────╢ ║ α + 1 ║ α + 1 │ α + 2 │ α │ 2α + 1 │ 2α + 2 │ 2α │ 1 │ 2 │ 0 ║ ╟────────╫────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────╢ ║ α + 2 ║ α + 2 │ α │ α + 1 │ 2α + 2 │ 2α │ 2α + 1 │ 2 │ 0 │ 1 ║ ╟────────╫────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────╢ ║ 2α ║ 2α │ 2α + 1 │ 2α + 2 │ 0 │ 1 │ 2 │ α │ α + 1 │ α + 2 ║ ╟────────╫────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────╢ ║ 2α + 1 ║ 2α + 1 │ 2α + 2 │ 2α │ 1 │ 2 │ 0 │ α + 1 │ α + 2 │ α ║ ╟────────╫────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────╢ ║ 2α + 2 ║ 2α + 2 │ 2α │ 2α + 1 │ 2 │ 0 │ 1 │ α + 2 │ α │ α + 1 ║ ╚════════╩════════╩════════╩════════╩════════╩════════╩════════╩════════╩════════╩════════╝
- compile(mode)[source]¶
Recompile the just-in-time compiled numba ufuncs for a new calculation mode.
- Parameters
mode (str) – The method of field computation, either
"jit-lookup"
,"jit-calculate"
,"python-calculate"
. The “jit-lookup” mode will use Zech log, log, and anti-log lookup tables for speed. The “jit-calculate” mode will not store any lookup tables, but perform field arithmetic on the fly. The “jit-calculate” mode is designed for large fields that cannot store lookup tables in RAM. Generally, “jit-calculate” is slower than “jit-lookup”. The “python-calculate” mode is reserved for extremely large fields. In this mode the ufuncs are not JIT-compiled, but are pur python functions operating on python ints. The list of valid modes for this field is ingalois.FieldClass.ufunc_modes
.
- display(mode='int')[source]¶
Sets the display mode for all Galois field arrays of this type.
The display mode can be set to either the integer representation, polynomial representation, or power representation. This function updates
display_mode
.For the power representation,
np.log()
is computed on each element. So for large fields without lookup tables, this may take longer than desired.- Parameters
mode (str, optional) – The field element display mode, either
"int"
(default),"poly"
, or"power"
.
Examples
Change the display mode by calling the
display()
method.In [1]: GF = galois.GF(2**8) In [2]: a = GF.Random(); a Out[2]: GF(226, order=2^8) # Change the display mode going forward In [3]: GF.display("poly"); a Out[3]: GF(α^7 + α^6 + α^5 + α, order=2^8) In [4]: GF.display("power"); a Out[4]: GF(α^95, order=2^8) # Reset to the default display mode In [5]: GF.display(); a Out[5]: GF(226, order=2^8)
The
display()
method can also be used as a context manager, as shown below.For the polynomial representation, when the primitive element is \(x \in \mathrm{GF}(p)[x]\) the polynomial indeterminate used is
α
.In [6]: GF = galois.GF(2**8) In [7]: print(GF.properties) GF(2^8): characteristic: 2 degree: 8 order: 256 irreducible_poly: Poly(x^8 + x^4 + x^3 + x^2 + 1, GF(2)) is_primitive_poly: True primitive_element: GF(2, order=2^8) In [8]: a = GF.Random(); a Out[8]: GF(241, order=2^8) In [9]: with GF.display("poly"): ...: print(a) ...: GF(α^7 + α^6 + α^5 + α^4 + 1, order=2^8) In [10]: with GF.display("power"): ....: print(a) ....: GF(α^174, order=2^8)
But when the primitive element is not \(x \in \mathrm{GF}(p)[x]\), the polynomial indeterminate used is
x
.In [11]: GF = galois.GF(2**8, irreducible_poly=galois.Poly.Degrees([8,4,3,1,0])) In [12]: print(GF.properties) GF(2^8): characteristic: 2 degree: 8 order: 256 irreducible_poly: Poly(x^8 + x^4 + x^3 + x + 1, GF(2)) is_primitive_poly: False primitive_element: GF(3, order=2^8) In [13]: a = GF.Random(); a Out[13]: GF(142, order=2^8) In [14]: with GF.display("poly"): ....: print(a) ....: GF(x^7 + x^3 + x^2 + x, order=2^8) In [15]: with GF.display("power"): ....: print(a) ....: GF(α^173, order=2^8)
- repr_table(primitive_element=None)[source]¶
Generates an element representation table comparing the power, polynomial, vector, and integer representations.
- Parameters
primitive_element (galois.FieldArray, optional) – The primitive element to use for the power representation. The default is
None
which uses the field’s default primitive element,galois.FieldClass.primitive_element
.- Returns
A UTF-8 formatted table comparing the power, polynomial, vector, and integer representations of each field element.
- Return type
Examples
In [1]: GF = galois.GF(2**4) In [2]: print(GF.repr_table()) ╔════════╦═══════════════════╦══════════════╦═════════╗ ║ Power │ Polynomial │ Vector │ Integer ║ ║════════╬═══════════════════╬══════════════╬═════════║ ║ 0 │ 0 │ [0, 0, 0, 0] │ 0 ║ ╟────────┼───────────────────┼──────────────┼─────────╢ ║ α^0 │ 1 │ [0, 0, 0, 1] │ 1 ║ ╟────────┼───────────────────┼──────────────┼─────────╢ ║ α^1 │ α │ [0, 0, 1, 0] │ 2 ║ ╟────────┼───────────────────┼──────────────┼─────────╢ ║ α^2 │ α^2 │ [0, 1, 0, 0] │ 4 ║ ╟────────┼───────────────────┼──────────────┼─────────╢ ║ α^3 │ α^3 │ [1, 0, 0, 0] │ 8 ║ ╟────────┼───────────────────┼──────────────┼─────────╢ ║ α^4 │ α + 1 │ [0, 0, 1, 1] │ 3 ║ ╟────────┼───────────────────┼──────────────┼─────────╢ ║ α^5 │ α^2 + α │ [0, 1, 1, 0] │ 6 ║ ╟────────┼───────────────────┼──────────────┼─────────╢ ║ α^6 │ α^3 + α^2 │ [1, 1, 0, 0] │ 12 ║ ╟────────┼───────────────────┼──────────────┼─────────╢ ║ α^7 │ α^3 + α + 1 │ [1, 0, 1, 1] │ 11 ║ ╟────────┼───────────────────┼──────────────┼─────────╢ ║ α^8 │ α^2 + 1 │ [0, 1, 0, 1] │ 5 ║ ╟────────┼───────────────────┼──────────────┼─────────╢ ║ α^9 │ α^3 + α │ [1, 0, 1, 0] │ 10 ║ ╟────────┼───────────────────┼──────────────┼─────────╢ ║ α^10 │ α^2 + α + 1 │ [0, 1, 1, 1] │ 7 ║ ╟────────┼───────────────────┼──────────────┼─────────╢ ║ α^11 │ α^3 + α^2 + α │ [1, 1, 1, 0] │ 14 ║ ╟────────┼───────────────────┼──────────────┼─────────╢ ║ α^12 │ α^3 + α^2 + α + 1 │ [1, 1, 1, 1] │ 15 ║ ╟────────┼───────────────────┼──────────────┼─────────╢ ║ α^13 │ α^3 + α^2 + 1 │ [1, 1, 0, 1] │ 13 ║ ╟────────┼───────────────────┼──────────────┼─────────╢ ║ α^14 │ α^3 + 1 │ [1, 0, 0, 1] │ 9 ║ ╚════════╩═══════════════════╩══════════════╩═════════╝
In [3]: alpha = GF.primitive_elements[-1] In [4]: print(GF.repr_table(alpha)) ╔════════════════════╦═══════════════════╦══════════════╦═════════╗ ║ Power │ Polynomial │ Vector │ Integer ║ ║════════════════════╬═══════════════════╬══════════════╬═════════║ ║ 0 │ 0 │ [0, 0, 0, 0] │ 0 ║ ╟────────────────────┼───────────────────┼──────────────┼─────────╢ ║ (α^3 + α^2 + α)^0 │ 1 │ [0, 0, 0, 1] │ 1 ║ ╟────────────────────┼───────────────────┼──────────────┼─────────╢ ║ (α^3 + α^2 + α)^1 │ α^3 + α^2 + α │ [1, 1, 1, 0] │ 14 ║ ╟────────────────────┼───────────────────┼──────────────┼─────────╢ ║ (α^3 + α^2 + α)^2 │ α^3 + α + 1 │ [1, 0, 1, 1] │ 11 ║ ╟────────────────────┼───────────────────┼──────────────┼─────────╢ ║ (α^3 + α^2 + α)^3 │ α^3 │ [1, 0, 0, 0] │ 8 ║ ╟────────────────────┼───────────────────┼──────────────┼─────────╢ ║ (α^3 + α^2 + α)^4 │ α^3 + 1 │ [1, 0, 0, 1] │ 9 ║ ╟────────────────────┼───────────────────┼──────────────┼─────────╢ ║ (α^3 + α^2 + α)^5 │ α^2 + α + 1 │ [0, 1, 1, 1] │ 7 ║ ╟────────────────────┼───────────────────┼──────────────┼─────────╢ ║ (α^3 + α^2 + α)^6 │ α^3 + α^2 │ [1, 1, 0, 0] │ 12 ║ ╟────────────────────┼───────────────────┼──────────────┼─────────╢ ║ (α^3 + α^2 + α)^7 │ α^2 │ [0, 1, 0, 0] │ 4 ║ ╟────────────────────┼───────────────────┼──────────────┼─────────╢ ║ (α^3 + α^2 + α)^8 │ α^3 + α^2 + 1 │ [1, 1, 0, 1] │ 13 ║ ╟────────────────────┼───────────────────┼──────────────┼─────────╢ ║ (α^3 + α^2 + α)^9 │ α^3 + α │ [1, 0, 1, 0] │ 10 ║ ╟────────────────────┼───────────────────┼──────────────┼─────────╢ ║ (α^3 + α^2 + α)^10 │ α^2 + α │ [0, 1, 1, 0] │ 6 ║ ╟────────────────────┼───────────────────┼──────────────┼─────────╢ ║ (α^3 + α^2 + α)^11 │ α │ [0, 0, 1, 0] │ 2 ║ ╟────────────────────┼───────────────────┼──────────────┼─────────╢ ║ (α^3 + α^2 + α)^12 │ α^3 + α^2 + α + 1 │ [1, 1, 1, 1] │ 15 ║ ╟────────────────────┼───────────────────┼──────────────┼─────────╢ ║ (α^3 + α^2 + α)^13 │ α^2 + 1 │ [0, 1, 0, 1] │ 5 ║ ╟────────────────────┼───────────────────┼──────────────┼─────────╢ ║ (α^3 + α^2 + α)^14 │ α + 1 │ [0, 0, 1, 1] │ 3 ║ ╚════════════════════╩═══════════════════╩══════════════╩═════════╝
- property characteristic¶
The prime characteristic \(p\) of the Galois field \(\mathrm{GF}(p^m)\). Adding \(p\) copies of any element will always result in \(0\).
Examples
In [1]: GF = galois.GF(2**8) In [2]: GF.characteristic Out[2]: 2 In [3]: a = GF.Random(); a Out[3]: GF(45, order=2^8) In [4]: a * GF.characteristic Out[4]: GF(0, order=2^8)
In [5]: GF = galois.GF(31) In [6]: GF.characteristic Out[6]: 31 In [7]: a = GF.Random(); a Out[7]: GF(26, order=31) In [8]: a * GF.characteristic Out[8]: GF(0, order=31)
- Type
- property default_ufunc_mode¶
The default ufunc arithmetic mode for this Galois field.
Examples
In [1]: galois.GF(2).default_ufunc_mode Out[1]: 'jit-calculate' In [2]: galois.GF(2**8).default_ufunc_mode Out[2]: 'jit-lookup' In [3]: galois.GF(31).default_ufunc_mode Out[3]: 'jit-lookup' In [4]: galois.GF(2**100).default_ufunc_mode Out[4]: 'python-calculate'
- Type
- property degree¶
The prime characteristic’s degree \(m\) of the Galois field \(\mathrm{GF}(p^m)\). The degree is a positive integer.
Examples
In [1]: galois.GF(2).degree Out[1]: 1 In [2]: galois.GF(2**8).degree Out[2]: 8 In [3]: galois.GF(31).degree Out[3]: 1 In [4]: galois.GF(7**5).degree Out[4]: 5
- Type
- property display_mode¶
The representation of Galois field elements, either
"int"
,"poly"
, or"power"
. This can be changed withdisplay()
.Examples
For the polynomial representation, when the primitive element is \(x \in \mathrm{GF}(p)[x]\) the polynomial indeterminate used is
α
.In [1]: GF = galois.GF(2**8) In [2]: print(GF.properties) GF(2^8): characteristic: 2 degree: 8 order: 256 irreducible_poly: Poly(x^8 + x^4 + x^3 + x^2 + 1, GF(2)) is_primitive_poly: True primitive_element: GF(2, order=2^8) In [3]: a = GF.Random(); a Out[3]: GF(226, order=2^8) In [4]: with GF.display("poly"): ...: print(a) ...: GF(α^7 + α^6 + α^5 + α, order=2^8) In [5]: with GF.display("power"): ...: print(a) ...: GF(α^95, order=2^8)
But when the primitive element is not \(x \in \mathrm{GF}(p)[x]\), the polynomial indeterminate used is
x
.In [6]: GF = galois.GF(2**8, irreducible_poly=galois.Poly.Degrees([8,4,3,1,0])) In [7]: print(GF.properties) GF(2^8): characteristic: 2 degree: 8 order: 256 irreducible_poly: Poly(x^8 + x^4 + x^3 + x + 1, GF(2)) is_primitive_poly: False primitive_element: GF(3, order=2^8) In [8]: a = GF.Random(); a Out[8]: GF(30, order=2^8) In [9]: with GF.display("poly"): ...: print(a) ...: GF(x^4 + x^3 + x^2 + x, order=2^8) In [10]: with GF.display("power"): ....: print(a) ....: GF(α^28, order=2^8)
- Type
- property dtypes¶
List of valid integer
numpy.dtype
objects that are compatible with this Galois field.Examples
In [1]: GF = galois.GF(2); GF.dtypes Out[1]: [numpy.uint8, numpy.uint16, numpy.uint32, numpy.int8, numpy.int16, numpy.int32, numpy.int64] In [2]: GF = galois.GF(2**8); GF.dtypes Out[2]: [numpy.uint8, numpy.uint16, numpy.uint32, numpy.int16, numpy.int32, numpy.int64] In [3]: GF = galois.GF(31); GF.dtypes Out[3]: [numpy.uint8, numpy.uint16, numpy.uint32, numpy.int8, numpy.int16, numpy.int32, numpy.int64] In [4]: GF = galois.GF(7**5); GF.dtypes Out[4]: [numpy.uint16, numpy.uint32, numpy.int16, numpy.int32, numpy.int64]
For Galois fields that cannot be represented by
numpy.int64
, the only valid dtype isnumpy.object_
.In [5]: GF = galois.GF(2**100); GF.dtypes Out[5]: [numpy.object_] In [6]: GF = galois.GF(36893488147419103183); GF.dtypes Out[6]: [numpy.object_]
- Type
- property irreducible_poly¶
The irreducible polynomial \(f(x)\) of the Galois field \(\mathrm{GF}(p^m)\). The irreducible polynomial is of degree \(m\) over \(\mathrm{GF}(p)\).
Examples
In [1]: galois.GF(2).irreducible_poly Out[1]: Poly(x + 1, GF(2)) In [2]: galois.GF(2**8).irreducible_poly Out[2]: Poly(x^8 + x^4 + x^3 + x^2 + 1, GF(2)) In [3]: galois.GF(31).irreducible_poly Out[3]: Poly(x + 28, GF(31)) In [4]: galois.GF(7**5).irreducible_poly Out[4]: Poly(x^5 + x + 4, GF(7))
- Type
- property is_extension_field¶
Indicates if the field’s order is a prime power.
Examples
In [1]: galois.GF(2).is_extension_field Out[1]: False In [2]: galois.GF(2**8).is_extension_field Out[2]: True In [3]: galois.GF(31).is_extension_field Out[3]: False In [4]: galois.GF(7**5).is_extension_field Out[4]: True
- Type
- property is_prime_field¶
Indicates if the field’s order is prime.
Examples
In [1]: galois.GF(2).is_prime_field Out[1]: True In [2]: galois.GF(2**8).is_prime_field Out[2]: False In [3]: galois.GF(31).is_prime_field Out[3]: True In [4]: galois.GF(7**5).is_prime_field Out[4]: False
- Type
- property is_primitive_poly¶
Indicates whether the
irreducible_poly
is a primitive polynomial.Examples
In [1]: GF = galois.GF(2**8) In [2]: GF.irreducible_poly Out[2]: Poly(x^8 + x^4 + x^3 + x^2 + 1, GF(2)) In [3]: GF.primitive_element Out[3]: GF(2, order=2^8) # The irreducible polynomial is a primitive polynomial is the primitive element is a root In [4]: GF.irreducible_poly(GF.primitive_element, field=GF) Out[4]: GF(0, order=2^8) In [5]: GF.is_primitive_poly Out[5]: True
# Field used in AES In [6]: GF = galois.GF(2**8, irreducible_poly=galois.Poly.Degrees([8,4,3,1,0])) In [7]: GF.irreducible_poly Out[7]: Poly(x^8 + x^4 + x^3 + x + 1, GF(2)) In [8]: GF.primitive_element Out[8]: GF(3, order=2^8) # The irreducible polynomial is a primitive polynomial is the primitive element is a root In [9]: GF.irreducible_poly(GF.primitive_element, field=GF) Out[9]: GF(6, order=2^8) In [10]: GF.is_primitive_poly Out[10]: False
- Type
- property name¶
The Galois field name.
Examples
In [1]: galois.GF(2).name Out[1]: 'GF(2)' In [2]: galois.GF(2**8).name Out[2]: 'GF(2^8)' In [3]: galois.GF(31).name Out[3]: 'GF(31)' In [4]: galois.GF(7**5).name Out[4]: 'GF(7^5)'
- Type
- property order¶
The order \(p^m\) of the Galois field \(\mathrm{GF}(p^m)\). The order of the field is also equal to the field’s size.
Examples
In [1]: galois.GF(2).order Out[1]: 2 In [2]: galois.GF(2**8).order Out[2]: 256 In [3]: galois.GF(31).order Out[3]: 31 In [4]: galois.GF(7**5).order Out[4]: 16807
- Type
- property prime_subfield¶
The prime subfield \(\mathrm{GF}(p)\) of the extension field \(\mathrm{GF}(p^m)\).
Examples
In [1]: print(galois.GF(2).prime_subfield.properties) GF(2): characteristic: 2 degree: 1 order: 2 In [2]: print(galois.GF(2**8).prime_subfield.properties) GF(2): characteristic: 2 degree: 1 order: 2 In [3]: print(galois.GF(31).prime_subfield.properties) GF(31): characteristic: 31 degree: 1 order: 31 In [4]: print(galois.GF(7**5).prime_subfield.properties) GF(7): characteristic: 7 degree: 1 order: 7
- Type
- property primitive_element¶
A primitive element \(\alpha\) of the Galois field \(\mathrm{GF}(p^m)\). A primitive element is a multiplicative generator of the field, such that \(\mathrm{GF}(p^m) = \{0, 1, \alpha^1, \alpha^2, \dots, \alpha^{p^m - 2}\}\).
A primitive element is a root of the primitive polynomial \(f(x)\), such that \(f(\alpha) = 0\) over \(\mathrm{GF}(p^m)\).
Examples
In [1]: galois.GF(2).primitive_element Out[1]: GF(1, order=2) In [2]: galois.GF(2**8).primitive_element Out[2]: GF(2, order=2^8) In [3]: galois.GF(31).primitive_element Out[3]: GF(3, order=31) In [4]: galois.GF(7**5).primitive_element Out[4]: GF(7, order=7^5)
- Type
- property primitive_elements¶
All primitive elements \(\alpha\) of the Galois field \(\mathrm{GF}(p^m)\). A primitive element is a multiplicative generator of the field, such that \(\mathrm{GF}(p^m) = \{0, 1, \alpha^1, \alpha^2, \dots, \alpha^{p^m - 2}\}\).
Examples
In [1]: galois.GF(2).primitive_elements Out[1]: GF([1], order=2) In [2]: galois.GF(2**8).primitive_elements Out[2]: GF([ 2, 4, 6, 9, 13, 14, 16, 18, 19, 20, 22, 24, 25, 27, 29, 30, 31, 34, 35, 40, 42, 43, 48, 49, 50, 52, 57, 60, 63, 65, 66, 67, 71, 72, 73, 74, 75, 76, 81, 82, 83, 84, 88, 90, 91, 92, 93, 95, 98, 99, 104, 105, 109, 111, 112, 113, 118, 119, 121, 122, 123, 126, 128, 129, 131, 133, 135, 136, 137, 140, 141, 142, 144, 148, 149, 151, 154, 155, 157, 158, 159, 162, 163, 164, 165, 170, 171, 175, 176, 177, 178, 183, 187, 188, 189, 192, 194, 198, 199, 200, 201, 202, 203, 204, 209, 210, 211, 212, 213, 216, 218, 222, 224, 225, 227, 229, 232, 234, 236, 238, 240, 243, 246, 247, 248, 249, 250, 254], order=2^8) In [3]: galois.GF(31).primitive_elements Out[3]: GF([ 3, 11, 12, 13, 17, 21, 22, 24], order=31) In [4]: galois.GF(7**5).primitive_elements Out[4]: GF([ 7, 8, 14, ..., 16797, 16798, 16803], order=7^5)
- Type
- property properties¶
A formatted string displaying relevant properties of the Galois field.
Examples
In [1]: GF = galois.GF(2); print(GF.properties) GF(2): characteristic: 2 degree: 1 order: 2 In [2]: GF = galois.GF(2**8); print(GF.properties) GF(2^8): characteristic: 2 degree: 8 order: 256 irreducible_poly: Poly(x^8 + x^4 + x^3 + x^2 + 1, GF(2)) is_primitive_poly: True primitive_element: GF(2, order=2^8) In [3]: GF = galois.GF(31); print(GF.properties) GF(31): characteristic: 31 degree: 1 order: 31 In [4]: GF = galois.GF(7**5); print(GF.properties) GF(7^5): characteristic: 7 degree: 5 order: 16807 irreducible_poly: Poly(x^5 + x + 4, GF(7)) is_primitive_poly: True primitive_element: GF(7, order=7^5)
- Type
- property ufunc_mode¶
The mode for ufunc compilation, either
"jit-lookup"
,"jit-calculate"
,"python-calculate"
.Examples
In [1]: galois.GF(2).ufunc_mode Out[1]: 'jit-calculate' In [2]: galois.GF(2**8).ufunc_mode Out[2]: 'jit-lookup' In [3]: galois.GF(31).ufunc_mode Out[3]: 'jit-lookup' In [4]: galois.GF(7**5).ufunc_mode Out[4]: 'jit-lookup'
- Type
- property ufunc_modes¶
All supported ufunc modes for this Galois field array class.
Examples
In [1]: galois.GF(2).ufunc_modes Out[1]: ['jit-calculate'] In [2]: galois.GF(2**8).ufunc_modes Out[2]: ['jit-lookup', 'jit-calculate'] In [3]: galois.GF(31).ufunc_modes Out[3]: ['jit-lookup', 'jit-calculate'] In [4]: galois.GF(2**100).ufunc_modes Out[4]: ['python-calculate']
- Type