Ask Your Question

Revision history [back]

There is a method to pass from an element of GF(2^n) to a polynomial with coefficients in GF(2):

sage: n = 5
sage: F.<t> = GF(2^n)
sage: f = F.random_element()
sage: f
t^4 + t^3 + t + 1
sage: p = f.polynomial()
sage: p
t^4 + t^3 + t + 1

f and p look the same, but they are not: the first belong to GF(2^n), the second is a genuine polynomial with coeffs in GF(2):

sage: f.parent()
Finite Field in t of size 2^5
sage: p.parent()
Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X)

Now, you can ask for the coeffs of p (in the variable t):

sage: p.coefficients(sparse=False)
[1, 1, 0, 1, 1]

Or (even better):

sage: p.dict()
{0: 1, 1: 1, 3: 1, 4: 1}

There is a method to pass from an element of GF(2^n) to a polynomial with coefficients in GF(2):

sage: n = 5
sage: F.<t> = GF(2^n)
sage: f = F.random_element()
sage: f
t^4 + t^3 + t + 1
sage: p = f.polynomial()
sage: p
t^4 + t^3 + t + 1

f and p look the same, but they are not: the first belong to GF(2^n), the second is a genuine polynomial with coeffs in GF(2):

sage: f.parent()
Finite Field in t of size 2^5
sage: p.parent()
Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X)

Now, you can ask for the coeffs of p (in the variable t):

sage: p.coefficients(sparse=False)
[1, 1, 0, 1, 1]

Or (even better):

sage: p.dict()
{0: 1, 1: 1, 3: 1, 4: 1}

Warning: be careful that without the sparse option, coefficients will only give the nonzero coefficients:

sage: p.coefficients(sparse=False)
[1, 1, 0, 1, 1]