A stupid implementation of non-prime fields
Never use in production! All algorithms are naive, so it's not even efficient!
As usual, non-prime fields are constructed using the polynomial ring with coefficients in
from non_prime_field import PrimeField, Polynomial, NonPrimeField
# GF(4). p is the irreducible polynomial
p = Polynomial([PrimeField(1, 2), PrimeField(1, 2), PrimeField(1, 2)], 2)
a = NonPrimeField(Polynomial([PrimeField(1, 2), PrimeField(1, 2)], 2), p)
# order. output should be 4
print(a.ord)
# integer representation. output should be 3
print(a.int)
# output should be '0 (mod [1, 1, 1] (mod 2))'
print(2 * a)
# output should be '2 (mod [1, 1, 1] (mod 2))'
print(a.invert())
Note: The polynomial representation [c0, c1, ..., cN]
means [1, 1, 1]
is [0, 1]
is just
I initially want to implement dumb12_381 (for BLS12-381 curve), but got lazy. Nonetheless this is still for playing with math and cryptography.
Just run pytest
to test.