mhostetter / galois

A performant NumPy extension for Galois fields and their applications
https://mhostetter.github.io/galois/
MIT License
295 stars 27 forks source link

galois.GF(2^128) problem #531

Closed suchuankai closed 6 months ago

suchuankai commented 6 months ago

Hello,

I am relatively new to coding and want to express my gratitude for your library, which helps me a lot!

Currently, I am encountering an issue while working with calculations in GF(2^128). When attempting to create a class for GF(2^128), I encountered a LookupError. When using "galois.irreducible_poly," I identified an irreducible polynomial: "x^128 + x^7 + x^2 + x + 1."

I am seeking guidance on how to make GF(2^128) compatible with this specific irreducible polynomial. Any assistance would be greatly appreciated!

Thank you very much for your time and support!

mhostetter commented 6 months ago

I'm glad you're enjoying the library. The keyword argument you're looking for is irreducible_poly, see here https://mhostetter.github.io/galois/latest/api/galois.GF/#p-irreducible_poly. You can specify a PolyLike object, see here https://mhostetter.github.io/galois/latest/api/galois.typing.PolyLike/.

So, for you, you can create the field like this

In [1]: import galois

In [2]: GF = galois.GF(2**128, irreducible_poly="x^128 + x^7 + x^2 + x + 1")

In [3]: GF
Out[3]: <class 'galois.GF(2^128)'>

In [4]: print(GF.properties)
Galois Field:
  name: GF(2^128)
  characteristic: 2
  degree: 128
  order: 340282366920938463463374607431768211456
  irreducible_poly: x^128 + x^7 + x^2 + x + 1
  is_primitive_poly: True
  primitive_element: x
suchuankai commented 6 months ago

Thanks for the solution you provided! It worked perfectly and solved my issue. I really appreciate your help!