The `galois` library is a performant Python package that extends NumPy arrays to operate over finite fields (Galois fields) for various mathematical and cryptographic applications. It leverages Numba and LLVM for just-in-time compilation to optimize finite field arithmetic, often outperforming native NumPy operations for modular arithmetic. It supports all Galois fields GF(p^m), offering functionalities for linear algebra, polynomials, forward error correction codes (BCH, Reed-Solomon), and number theoretic functions. Currently at version 0.4.10, the library maintains an active release cadence, with updates typically arriving monthly or bi-monthly.
pip install galoisVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a Galois field, create `FieldArray` instances which inherit from NumPy arrays, and perform basic arithmetic operations within that finite field. The `galois.GF()` factory function is used to create the field class.
Migrate all calls from `galois.Field()` to `galois.GF()`. They are functionally equivalent.
Always pass these specific arguments by keyword, not by position. For example, use `galois.GF(p**m, irreducible_poly=poly)` instead of `galois.GF(p**m, poly)`.
Do not use `galois` for production security-sensitive applications where constant-time arithmetic is a requirement. It is intended for research, development, cryptanalysis, and education.
If encountering `ImportError` or other runtime issues related to NumPy/Numba, check the official `galois` documentation for its recommended `numpy` and `numba` versions. Consider installing `numpy` and `numba` first, or using a virtual environment to isolate dependencies.
Replace `galois.Field(...)` with `galois.GF(...)`.
Ensure all such arguments are passed by keyword, e.g., `galois.GF(2**8, irreducible_poly=poly)`.
Ensure both `FieldArray` instances are created from the *exact same* `GF` class. If necessary, explicitly cast one array to the field of the other using `GF_target(array_source)` if the conversion is meaningful and defined.
If on Python 3.10.1, try upgrading to a later Python 3.10.x release, Python 3.11+, or downgrading to Python 3.9. Ensure Numba and NumPy are also updated to their latest compatible versions.