mirror of
https://github.com/Ikatono/Galois.git
synced 2025-10-29 04:45:31 -05:00
continued work on field class
This commit is contained in:
15
GF.py
15
GF.py
@@ -42,6 +42,11 @@ class GF:
|
|||||||
self.poly.append((int(i),1))
|
self.poly.append((int(i),1))
|
||||||
if p == 2:
|
if p == 2:
|
||||||
self.poly.append((0,1))
|
self.poly.append((0,1))
|
||||||
|
|
||||||
|
#performs a modulus operation using self.poly
|
||||||
|
def mod(self, other):
|
||||||
|
#copy the provided list
|
||||||
|
other = list(other)
|
||||||
|
|
||||||
|
|
||||||
#creates a new element with the given value
|
#creates a new element with the given value
|
||||||
@@ -54,11 +59,18 @@ class GF:
|
|||||||
if isisntance(val, int):
|
if isisntance(val, int):
|
||||||
if self.characteristic != 2:
|
if self.characteristic != 2:
|
||||||
raise TypeError('integer definition of field elements is only allowed in fields of characteristic 2')
|
raise TypeError('integer definition of field elements is only allowed in fields of characteristic 2')
|
||||||
|
#TODO cover binary conversion
|
||||||
#covers the case that the value is an iterable of individual terms
|
#covers the case that the value is an iterable of individual terms
|
||||||
#first term is for exponent zero, etc.
|
#first term is for exponent zero, etc.
|
||||||
#accepts integers or strings
|
#accepts integers or strings
|
||||||
else:
|
else:
|
||||||
pol = [0] * self.degree
|
#makes val into a list in order to check the number of terms
|
||||||
|
if isinstance(val, str):
|
||||||
|
#strings are interpreted as the first character being most significant
|
||||||
|
val = [i for i in val[::-1]]
|
||||||
|
else:
|
||||||
|
val = list(val)
|
||||||
|
pol = [0] * len(val)
|
||||||
for i in range(len(val)):
|
for i in range(len(val)):
|
||||||
if isinstance(val[i], int):
|
if isinstance(val[i], int):
|
||||||
pol[i] = val[i]
|
pol[i] = val[i]
|
||||||
@@ -75,6 +87,7 @@ class GF:
|
|||||||
pol[i] = a - 87
|
pol[i] = a - 87
|
||||||
else:
|
else:
|
||||||
raise ValueError('polynomial coefficient is uninterprettable')
|
raise ValueError('polynomial coefficient is uninterprettable')
|
||||||
|
pol = self.mod(pol)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user