classmethod galois.Poly.Int(integer: int, field: = None) Self

Constructs a polynomial over $$\mathrm{GF}(p^m)$$ from its integer representation.

Parameters:
integer: int

The integer representation of the polynomial $$f(x)$$.

field: = None

The Galois field $$\mathrm{GF}(p^m)$$ the polynomial is over. The default is None which corresponds to GF2.

Returns:

The polynomial $$f(x)$$.

Notes

Int() and __int__() are inverse operations.

Examples

Construct a polynomial over $$\mathrm{GF}(2)$$ from its integer representation.

In [1]: f = galois.Poly.Int(5); f
Out[1]: Poly(x^2 + 1, GF(2))

In [2]: int(f)
Out[2]: 5


Construct a polynomial over $$\mathrm{GF}(3^5)$$ from its integer representation.

In [3]: GF = galois.GF(3**5)

In [4]: f = galois.Poly.Int(186535908, field=GF); f
Out[4]: Poly(13x^3 + 117, GF(3^5))

In [5]: int(f)
Out[5]: 186535908

# The polynomial/integer equivalence
In [6]: int(f) == 13*GF.order**3 + 117
Out[6]: True


Construct a polynomial over $$\mathrm{GF}(2)$$ from its binary string.

In [7]: f = galois.Poly.Int(int("0b1011", 2)); f
Out[7]: Poly(x^3 + x + 1, GF(2))

In [8]: bin(f)
Out[8]: '0b1011'


Construct a polynomial over $$\mathrm{GF}(2^3)$$ from its octal string.

In [9]: GF = galois.GF(2**3)

In [10]: f = galois.Poly.Int(int("0o5034", 8), field=GF); f
Out[10]: Poly(5x^3 + 3x + 4, GF(2^3))

In [11]: oct(f)
Out[11]: '0o5034'


Construct a polynomial over $$\mathrm{GF}(2^8)$$ from its hexadecimal string.

In [12]: GF = galois.GF(2**8)

In [13]: f = galois.Poly.Int(int("0xf700a275", 16), field=GF); f
Out[13]: Poly(247x^3 + 162x + 117, GF(2^8))

In [14]: hex(f)
Out[14]: '0xf700a275'