Galois field calculator GF(2^4) GF(2^8)

1.2k views Asked by At

I am fairly new to python and I have this challenge to complete but have no clue on how to approach this below are the questions:

Code a simple four-function calculator in GF(2^4). You may use table lookups for the multiplicative inverses.

And

Code a simple four-function calculator in GF(28). You should compute the multiplicative inverses on the fly.

I need tips and if possible solutions for this challenge thanks.

1

There are 1 answers

1
Matt Hostetter On

I am the author of the galois Python 3 package. It extends NumPy arrays to operate over Galois fields. Both lookup tables and explicit calculation may be used.

If you are simply trying to accomplish the task, the below examples will do the trick. However, if you'd like to understand how to implement the arithmetic yourself, the code is open-source on GitHub, so you can view the exact implementations. For instance, here is the code for Galois field arithmetic in GF(2^m).

Additionally, I have two tutorials on how Galois fields work -- one on prime fields and one on extension fields. You may find them helpful.

>>> import galois

>>> galois.__version__
'0.0.26'

>>> GF = galois.GF(2**4)

>>> print(GF)
Galois Field:
  name: GF(2^4)
  characteristic: 2
  degree: 4
  order: 16
  irreducible_poly: x^4 + x + 1
  is_primitive_poly: True
  primitive_element: x

>>> x = GF.Random(10); x
GF([ 1, 12, 13, 12, 11, 10, 11,  2,  3,  1], order=2^4)

>>> y = GF.Random(10, low=1); y
GF([14,  5,  2,  2,  8,  4, 14,  7,  5, 13], order=2^4)

>>> x + y
GF([15,  9, 15, 14,  3, 14,  5,  5,  6, 12], order=2^4)

>>> x - y
GF([15,  9, 15, 14,  3, 14,  5,  5,  6, 12], order=2^4)

>>> x * y
GF([14,  9,  9, 11,  7, 14,  8, 14, 15, 13], order=2^4)

>>> x / y
GF([ 3, 13, 15,  6,  3, 11, 14, 12, 14,  4], order=2^4)