cryptotools/examples/galois.py
2026-01-11 09:19:22 +01:00

37 lines
670 B
Python

#!/usr/bin/env python3
from Cryptotools.Groups.galois import Galois
import matplotlib.pyplot as plt # pip install numpy==1.26.4
def operation(a, b, n):
return (a ** b) % n
q = 13
g = Galois(q, operation)
add = g.add()
div = g.div()
mul = g.mul()
sub = g.sub()
g.check_closure_law('+')
g.check_closure_law('*')
g.check_closure_law('-')
g.check_closure_law('/')
print("Addition")
g.printMatrice(add)
print("Division")
g.printMatrice(div)
print("Multiplication")
g.printMatrice(mul)
print("Substraction")
g.printMatrice(sub)
print("Primitives root")
print(g.primitiveRoot(), end="\n\n")
#print("Identity elements")
g.check_identity_add()
g.check_identity_mul()