mirror of
https://github.com/Ikatono/Galois.git
synced 2025-10-29 04:45:31 -05:00
started work on field class:
This commit is contained in:
44
GF.py
Normal file
44
GF.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from math import log
|
||||
|
||||
#defines the field itself
|
||||
#responsible for creating elements and performing operations
|
||||
#all elements contain a pointer to the field that created them
|
||||
#elements from different fields can't interact, even if they're equivalent
|
||||
|
||||
class GF:
|
||||
def __init__(self, *args):
|
||||
|
||||
def characteristic(a):
|
||||
if a%2 == 0:
|
||||
b = log(a, 2)
|
||||
if b != int(b):
|
||||
raise ValueError('%i is not a prime power' % a)
|
||||
return 2, int(b)
|
||||
i = 3
|
||||
while i <= 23:
|
||||
if a%i == 0:
|
||||
b = log(a, i)
|
||||
if b != int(b):
|
||||
raise ValueError('%i is not a prime power' % a)
|
||||
return i, int(b)
|
||||
i += 2
|
||||
|
||||
if len(args) == 1:
|
||||
p, n = characteristic(args[0])
|
||||
elif len(args) > 2:
|
||||
raise TypeError('too many arguments')
|
||||
else:
|
||||
p, n = args
|
||||
self.characteristic = p
|
||||
self.order = p**n
|
||||
self.degree = n
|
||||
file = open('gf' + str(p) + '.txt', 'r')
|
||||
pol = file.readlines()[n-2]
|
||||
file.close()
|
||||
pol = pol.split(',')
|
||||
#integer coefficients of defining polynomial
|
||||
#index is the exponent
|
||||
self.poly = [None]*n + [1]
|
||||
if p == 2:
|
||||
self.poly[0] = 1
|
||||
for i in pol
|
||||
Reference in New Issue
Block a user