I've written an extended Euclidean algorithm function
xgcd :: FFElem -> FFElem -> (FFElem, FFElem)
that, for nonzero finite field elements a,b ∈ GF(pm), calculates s and t such that sa + tb = 1. Is there a way I can use xgcd
to calculate multiplicative inverses in the field? That is, given a ∈ GF(pm), I want to calculate b such that ab = 1 ∈ GF(pm).
I've also implemented the functions
(+) :: FFElem -> FFElem -> FFElem
(-) :: FFElem -> FFElem -> FFElem
(*) :: FFElem -> FFElem -> FFElem
(^) :: FFElem -> Integer -> FFElem
ffQuotRem :: FFElem -> FFElem -> (FFElem, FFElem)
degree :: FFElem -> Integer
Where (+)
, (-)
, (*)
, (^)
, and ffQuotRem
behave as you would expect and degree
is the usual Euclidean function for finite fields (the degree of the polynomial representation of the field element).
(Answers don't necessarily need to be in Haskell.)
Here are some steps toward an answer. First, consider the ring
Z/nZ
which is a field ifn
is prime. We can give a simple routine to compute the multiplicative inverse of an elementa
Its type is
inverse :: Integral a => a -> a -> Maybe a
because it allows for non-primen
, when the multiplicative inverse does not exist.If a field is not a prime field, then it is a field extension of a prime field
K = Z/nZ
for some primen
, and is isomorphic toK[x]/p
for some polynomialp
. In particular, we require that there is a functionthat tells us the degree of a polynomial, and a partial function
that projects a polynomial of degree 0 down to its underlying field in the obvious way. So if you know
n
andp
, thenAs an aside, if I were doing this, I would probably build on the definition of the
Integral
class in Haskell, and define a new classwhich would have some simple instances (prime fields, which can be represented with a data type like)
and more complicated instances for non-prime finite fields, whose elements are polynomials, probably represented with a
Map
-