# sagemath GF(p^n) calculations

Is there a way to generate the primitive elements in $$GF(p^n)$$, in say Sagemath, and perform operations with these elements?

For example, using the irreducible polynomial $$p(x)=1+x+x^3$$ in $$GF(2^3)$$, how can i generate these primitive elements and how would I go about adding/multiplying them?

I have looked at the online manual, but can't seem to find what I am looking for. Thank you.

• Sagemath has the .gen() and .multiplicative_generator() methods which return a single primitive element. I don't think it has a simple command to get all the primitive elements of a Galois field. Sep 2, 2021 at 14:33
• FWIW, a comment to my answer here (to a question on mutually orthogonal latin squares) links to a Sage script that produces MOLS using finite field arithmetic. That script is rather terse, but you might find it helpful. Sep 2, 2021 at 14:36
• Thank you. Perhaps I should try looking at Octave or GAP. Manually generating these tables, and doing arithmetic is an absolute pain. I will take a look at that script also. Sep 2, 2021 at 14:47
• I think you want to extend $GF(2)$ with your polynomial. Does this question/answer help you? Sep 3, 2021 at 14:06
• It looks like the Frobenius companion matrix solves the issue. Creating a companion matrix of the irreducible polynomial allows me to add and multiply the elements in GF(2^n) with ease. I suspect it will hold for GF(p^n) - need to confirm still. Thanks again. Sep 14, 2021 at 5:52