This is a library for using Galois Field GF(p^n) in Python, which generates GF(p) and GF(p^n) and allows you to multiply, add, subtract, and divide elements. For Japanease
- Python 3.8 ~
- Generating GF(p) and GF(p^n).
- Generating an element of Galois Field. (from modulus operation)
- Four Arithmetic operations over GF(p^n).
- Compute the inverse of an element in GF(p^n).
You can install with pip:
$ pip install git+https://github.com/syakoo/galois-fieldfrom galois_field import GFp
# Generating the field GF(11)
gf = GFp(11)
# Generating an element in GF(11)
el1 = gf.elm(5) # 5 (mod 11)
el2 = gf.elm(13) # 2 (mod 11)
# Arithmetics
el1 + el2 # 7 (mod 11)
el1 - el2 # 3 (mod 11)
el1 * el2 # 10 (mod 11)
el1 / el2 # 8 (mod 11)
# The Inverse of elements.
el1.inverse() # 9 (mod 11)
el2.inverse() # 6 (mod 11)We use a monic irreducible polynomial. (in this case, x^4 + 2)
from galois_field import GFpn
# Generating the field GF(5^4)
gf = GFpn(5, [1, 0, 0, 0, 2])
# Generating an element in GF(5^4)
el1 = gf.elm([1, 2]) # 1x + 2
el2 = gf.elm([1, 2, 3, 4, 5]) # 2x^3 + 3x^2 + 4x + 3
# Arithmetics
el1 + el2 # 2x^3 + 3x^2
el1 - el2 # 3x^3 + 2x^2 + 2x + 4
el1 * el2 # 2x^3 + 1x + 2
el1 / el2 # 3x^3 + 4x^2
# The Inverse of elements.
el1.inverse() # 3x^3 + 4x^2 + 2x + 1
el2.inverse() # 1x^3 + 1x^2 + 2x + 1- The range of values is up to
2^64 bits, with a maximum of2^32 bitsto ensure that the product gets the right value, and up to ten decimal digits. - Please note that even if you use a value within the range, the value is not guaranteed with certainty. (We take no responsibility for this.)
This library has a lot of features we want to add and we are looking for contributors. Please feel free to add Issues and PullRequest.
Please set up your development environment with the following command:
$ python -m venv .venv
$ source .venv/bin/activate$ pip install -r requirements.dev.txt$ pytest$ flake8 galois_fieldMIT LICENSE