Galois Fields for NumPy

0.4.10 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import galois
import numpy as np

# Define a Galois field, e.g., GF(3^5)
GF = galois.GF(3**5)
print(f"Galois Field properties:\n{GF.properties}")

# Create FieldArray instances (which are subclasses of np.ndarray)
x = GF([236, 87, 38, 112])
y = GF(np.array([109, 201, 2, 45]))

print(f"\nx (type: {type(x)}): {x}")
print(f"y (type: {type(y)}): {y}")

# Perform arithmetic operations in the finite field
result_add = x + y
result_mul = x * y

print(f"\nx + y: {result_add}")
print(f"x * y: {result_mul}")

view raw JSON →