From 24087c2bb4a7023d4bbf3770c638faab82b6e287 Mon Sep 17 00:00:00 2001 From: Szymon Wojciechowski Date: Wed, 30 May 2018 18:35:47 +0000 Subject: [PATCH 01/10] =?UTF-8?q?Prze=C5=9Blij=20pliki=20do=20''?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ring.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Ring.py diff --git a/Ring.py b/Ring.py new file mode 100644 index 0000000..88345d4 --- /dev/null +++ b/Ring.py @@ -0,0 +1,48 @@ +from fractions import gcd + +class Modulo: + + def __init__(self, n): + self.n = int(n) + self.modulo_set = list(range(self.n)) + self.answer = [] + + def get_inverse_elements(self): + self.inverse_elements = [] + for i in self.modulo_set: + if gcd(i, self.n) == 1: + self.inverse_elements.append(i) + self.answer.append(self.inverse_elements) + + def get_zero_divisors(self): + self.zero_divisors = [] + for i in self.modulo_set: + for j in self.modulo_set: + if (i * j) % self.n == 0 and i != 0 and j != 0: + self.zero_divisors.append(i) + self.answer.append(list(set(self.zero_divisors))) + + def get_nilpotent_elements(self): + self.nilpotent_elements = [] + for i in self.modulo_set: + for j in range(1, len(self.inverse_elements) + 1): + if (i**j) % self.n == 0 and i != 0: + self.nilpotent_elements.append(i) + self.answer.append(list(set(self.nilpotent_elements))) + + def get_idempotent_elements(self): + self.idempotent_elements = [] + for i in self.modulo_set: + if (i*i) % self.n == i: + self.idempotent_elements.append(i) + self.answer.append(self.idempotent_elements) + + def get_all(self): + self.get_inverse_elements() + self.get_zero_divisors() + self.get_nilpotent_elements() + self.get_idempotent_elements() + return self.answer + +s = Modulo(input("Enter n: ")) +print(s.get_all()) -- 2.20.1 From 448979c654b0966b86ebaf8a8d4d94c1013aa6e5 Mon Sep 17 00:00:00 2001 From: Szymon Wojciechowski Date: Wed, 6 Jun 2018 23:25:32 +0000 Subject: [PATCH 02/10] Dodaj 'wielomiany.py' --- wielomiany.py | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 wielomiany.py diff --git a/wielomiany.py b/wielomiany.py new file mode 100644 index 0000000..c00ab5f --- /dev/null +++ b/wielomiany.py @@ -0,0 +1,87 @@ +class Polynomial: + + n = 0 + + def __init__(self, *args): + self.degree = len(args) - 1 + self.coefficients = list(args) + + @staticmethod + def multiply(p1, p2): + result = [0] * (p1.degree + p2.degree + 1) + f = p1.coefficients + g = p2.coefficients + for i in range(0, len(f)): + for j in range(0, len(g)): + result[i+j] += f[i] * g[j] + result = [x % int(n) for x in result] + return Polynomial(*result) + + @staticmethod + def divide(p1, p2): + def inverse(x): + for i in range(1, int(n)): + r = (i * x) % int(n) + if r == 1: + break + else: + raise ZeroDivisionError + return i + if p1.degree < p2.degree: + return p1 + f = p1.coefficients + g = p2.coefficients + g_lead_coef = g[-1] + g_deg = p2.degree + while len(f) >= len(g): + f_lead_coef = f[-1] + tmp_coef = f_lead_coef * inverse(g_lead_coef) + tmp_exp = len(f) - 1 - g_deg + tmp = [] + for i in range(tmp_exp): + tmp.append(0) + tmp.append(tmp_coef) + tmp_poly = Polynomial(*tmp) + sub = Polynomial.multiply(p2, tmp_poly) + f = [x - y for x, y in zip(f, sub.coefficients)] + f = [x % int(n) for x in f] + while f and f[-1] == 0: + f.pop() + return Polynomial(*f) + + @staticmethod + def gcd(p1, p2): + if len(p2.coefficients) == 0: + return p1 + return Polynomial.gcd(p2, Polynomial.divide(p1, p2)) + + +n = input("Enter n: ") +Polynomial.n = int(n) + +c1 = [int(x) for x in input("Enter 1st polynomial (coefficients divided by space): ").split()] +c1 = [x % Polynomial.n for x in c1] +c2 = [int(x) for x in input("Enter 2nd polynomial: ").split()] +c2 = [x % Polynomial.n for x in c2] + +f = Polynomial(*c1) +g = Polynomial(*c2) + +ans = [] + +mul = Polynomial.multiply(f, g) +ans.append(mul.coefficients) + +try: + div = Polynomial.divide(f, g) + ans.append(div.coefficients) +except ZeroDivisionError as e: + ans.append(e) + +try: + gcd = Polynomial.gcd(f, g) + ans.append(gcd.coefficients) +except ZeroDivisionError as e: + ans.append(e) + +print(ans) \ No newline at end of file -- 2.20.1 From 78f79da83cc4fc43b6840de833447a1b0c5dc974 Mon Sep 17 00:00:00 2001 From: Szymon Wojciechowski Date: Thu, 7 Jun 2018 08:06:57 +0000 Subject: [PATCH 03/10] Zaktualizuj 'wielomiany.py' --- wielomiany.py | 59 +++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/wielomiany.py b/wielomiany.py index c00ab5f..833e9d6 100644 --- a/wielomiany.py +++ b/wielomiany.py @@ -1,10 +1,13 @@ +import sys +import ast + class Polynomial: n = 0 - def __init__(self, *args): - self.degree = len(args) - 1 - self.coefficients = list(args) + def __init__(self, coef_list): + self.degree = len(coef_list) - 1 + self.coefficients = coef_list @staticmethod def multiply(p1, p2): @@ -15,7 +18,7 @@ class Polynomial: for j in range(0, len(g)): result[i+j] += f[i] * g[j] result = [x % int(n) for x in result] - return Polynomial(*result) + return Polynomial(result) @staticmethod def divide(p1, p2): @@ -41,13 +44,13 @@ class Polynomial: for i in range(tmp_exp): tmp.append(0) tmp.append(tmp_coef) - tmp_poly = Polynomial(*tmp) + tmp_poly = Polynomial(tmp) sub = Polynomial.multiply(p2, tmp_poly) f = [x - y for x, y in zip(f, sub.coefficients)] f = [x % int(n) for x in f] while f and f[-1] == 0: f.pop() - return Polynomial(*f) + return Polynomial(f) @staticmethod def gcd(p1, p2): @@ -56,32 +59,32 @@ class Polynomial: return Polynomial.gcd(p2, Polynomial.divide(p1, p2)) -n = input("Enter n: ") -Polynomial.n = int(n) +def main(): + c1 = ast.literal_eval(sys.argv[2]) + c2 = ast.literal_eval(sys.argv[3]) -c1 = [int(x) for x in input("Enter 1st polynomial (coefficients divided by space): ").split()] -c1 = [x % Polynomial.n for x in c1] -c2 = [int(x) for x in input("Enter 2nd polynomial: ").split()] -c2 = [x % Polynomial.n for x in c2] + f = Polynomial(c1) + g = Polynomial(c2) -f = Polynomial(*c1) -g = Polynomial(*c2) + ans = [] -ans = [] + mul = Polynomial.multiply(f, g) + ans.append(mul.coefficients) -mul = Polynomial.multiply(f, g) -ans.append(mul.coefficients) + try: + div = Polynomial.divide(f, g) + ans.append(div.coefficients) + except ZeroDivisionError as e: + ans.append(e) -try: - div = Polynomial.divide(f, g) - ans.append(div.coefficients) -except ZeroDivisionError as e: - ans.append(e) + try: + gcd = Polynomial.gcd(f, g) + ans.append(gcd.coefficients) + except ZeroDivisionError as e: + ans.append(e) -try: - gcd = Polynomial.gcd(f, g) - ans.append(gcd.coefficients) -except ZeroDivisionError as e: - ans.append(e) + print(ans) -print(ans) \ No newline at end of file +if __name__ == "__main__": + n = int(sys.argv[1]) + main() \ No newline at end of file -- 2.20.1 From 0cee287283b3e867d6db404035ca1a0c055ecf5f Mon Sep 17 00:00:00 2001 From: Szymon Wojciechowski Date: Wed, 20 Jun 2018 15:28:24 +0000 Subject: [PATCH 04/10] Dodaj 'crc16.py' --- crc16.py | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 crc16.py diff --git a/crc16.py b/crc16.py new file mode 100644 index 0000000..bd75c00 --- /dev/null +++ b/crc16.py @@ -0,0 +1,139 @@ +import sys +import ast +import time +from itertools import zip_longest + +class Polynomial: + + def __init__(self, coef_list): + self.degree = len(coef_list) - 1 + self.coefficients = coef_list + + @staticmethod + def add(p1, p2): + result = [] + f = p1.coefficients + g = p2.coefficients + if len(f) >= len(g): + result = f + for i in range(0, len(g)): + result[i] = f[i] + g[i] + else: + result = g + for i in range(0, len(f)): + result[i] = f[i] + g[i] + result = [x % int(n) for x in result] + return Polynomial(result) + + @staticmethod + def multiply(p1, p2): + result = [0] * (p1.degree + p2.degree + 1) + f = p1.coefficients + g = p2.coefficients + for i in range(0, len(f)): + for j in range(0, len(g)): + result[i+j] += f[i] * g[j] + result = [x % int(n) for x in result] + return Polynomial(result) + + @staticmethod + def divide(p1, p2): + def inverse(x): + for i in range(1, int(n)): + r = (i * x) % int(n) + if r == 1: + break + else: + raise ZeroDivisionError + return i + if p1.degree < p2.degree: + return p1 + f = p1.coefficients + g = p2.coefficients + g_lead_coef = g[-1] + g_deg = p2.degree + while len(f) >= len(g): + f_lead_coef = f[-1] + tmp_coef = f_lead_coef * inverse(g_lead_coef) + tmp_exp = len(f) - 1 - g_deg + tmp = [] + for _ in range(tmp_exp): + tmp.append(0) + tmp.append(tmp_coef) + tmp_poly = Polynomial(tmp) + sub = Polynomial.multiply(p2, tmp_poly) + f = [x - y for x, y in zip(f, sub.coefficients)] + f = [x % int(n) for x in f] + while f and f[-1] == 0: + f.pop() + return Polynomial(f) + + +n = 2 + + +def normalize_byte(data): + while len(data) != 8: + if len(data) < 8: + data = str(0) + data + else: + data.replace(data[0], '') + return data + + +def encode(in_data): + data = in_data + data = list(data) + data_binary = [bin(ord(char)).replace('b', '') for char in data] + data_binary = [normalize_byte(byte) for byte in data_binary] + data_binary = [int(bit) for bit in list(''.join(data_binary))] + data_binary.reverse() + + M = [0] * 16 + data_binary + L = [0] * (len(data_binary)) + [1] * 16 + G = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1] + FCS_poly = Polynomial.divide(Polynomial.add(Polynomial(M), Polynomial(L)), Polynomial(G)) + FCS = FCS_poly.coefficients + [0] * (16 - len(FCS_poly.coefficients)) + + FCS.reverse() + data_binary.reverse() + data_binary = data_binary + FCS + data_binary = [data_binary[i:i+8] for i in range(0, len(data_binary), 8)] + data = [chr(int(''.join(map(str, byte)), 2)) for byte in data_binary] + + return ''.join(data) + + +def check_fcs(in_data): + data = in_data + data = list(data) + data_binary = [bin(ord(char)).replace('b', '') for char in data] + data_binary = [normalize_byte(byte) for byte in data_binary] + data_binary = [int(bit) for bit in list(''.join(data_binary))] + data_binary.reverse() + + C = [0] * 16 + data_binary + L = [0] * len(data_binary) + [1] * 16 + G = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1] + S = Polynomial.divide(Polynomial.add(Polynomial(C), Polynomial(L)), Polynomial(G)) + + if S.coefficients == []: + return True + + return False + + +def main(): + try: + if sys.argv[1] == '-e' or sys.argv[1] == '-encode': + print(encode(sys.argv[2])) + elif sys.argv[1] == '-c' or sys.argv[1] == '-check': + print(check_fcs(sys.argv[2])) + else: + raise IndexError + except IndexError: + print("To encode: python3 CRC16.py -e [argument]\nTo check FCS: python3 CRC16.py -c [argument]") + + +if __name__ == "__main__": + main() -- 2.20.1 From 772736120b54377dc291118984ca775689d6ac10 Mon Sep 17 00:00:00 2001 From: Szymon Wojciechowski Date: Mon, 25 Jun 2018 15:21:17 +0000 Subject: [PATCH 05/10] bugfix --- crc16.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crc16.py b/crc16.py index bd75c00..f3d1777 100644 --- a/crc16.py +++ b/crc16.py @@ -1,7 +1,5 @@ import sys import ast -import time -from itertools import zip_longest class Polynomial: @@ -77,7 +75,7 @@ def normalize_byte(data): if len(data) < 8: data = str(0) + data else: - data.replace(data[0], '') + data = data[1:] return data @@ -126,7 +124,9 @@ def check_fcs(in_data): def main(): try: if sys.argv[1] == '-e' or sys.argv[1] == '-encode': - print(encode(sys.argv[2])) + arg = encode(sys.argv[2]) + print(arg) + print(check_fcs(arg)) # powinno zawsze zwracać true elif sys.argv[1] == '-c' or sys.argv[1] == '-check': print(check_fcs(sys.argv[2])) else: @@ -136,4 +136,4 @@ def main(): if __name__ == "__main__": - main() + main() \ No newline at end of file -- 2.20.1 From 09dcfac9ab436cf8ae72d5fac712bd8710f21553 Mon Sep 17 00:00:00 2001 From: Szymon Wojciechowski Date: Mon, 25 Jun 2018 17:54:51 +0000 Subject: [PATCH 06/10] changed input --- crc16.py | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/crc16.py b/crc16.py index f3d1777..ade6f26 100644 --- a/crc16.py +++ b/crc16.py @@ -90,24 +90,34 @@ def encode(in_data): M = [0] * 16 + data_binary L = [0] * (len(data_binary)) + [1] * 16 G = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1] - FCS_poly = Polynomial.divide(Polynomial.add(Polynomial(M), Polynomial(L)), Polynomial(G)) - FCS = FCS_poly.coefficients + [0] * (16 - len(FCS_poly.coefficients)) + result_poly = Polynomial.divide(Polynomial.add(Polynomial(M), Polynomial(L)), Polynomial(G)) + result = result_poly.coefficients + [0] * (16 - len(result_poly.coefficients)) - FCS.reverse() + result.reverse() data_binary.reverse() - data_binary = data_binary + FCS + data_binary = data_binary + result data_binary = [data_binary[i:i+8] for i in range(0, len(data_binary), 8)] - data = [chr(int(''.join(map(str, byte)), 2)) for byte in data_binary] + data_binary = [int(''.join(map(str, byte)), 2) for byte in data_binary] - return ''.join(data) + fcs = [hex(byte) for byte in data_binary] + fcs = fcs[-2:] + + data = [chr(byte) for byte in data_binary] + data = ''.join(data[0:-2]) + + return data, fcs -def check_fcs(in_data): +def check_fcs(in_data, fcs): data = in_data data = list(data) data_binary = [bin(ord(char)).replace('b', '') for char in data] data_binary = [normalize_byte(byte) for byte in data_binary] data_binary = [int(bit) for bit in list(''.join(data_binary))] + fcs_binary = [bin(int(in_hex, 16)).replace('b', '') for in_hex in fcs] + fcs_binary = [normalize_byte(byte) for byte in fcs_binary] + fcs_binary = [int(bit) for bit in list(''.join(fcs_binary))] + data_binary += fcs_binary data_binary.reverse() C = [0] * 16 + data_binary @@ -124,15 +134,17 @@ def check_fcs(in_data): def main(): try: if sys.argv[1] == '-e' or sys.argv[1] == '-encode': - arg = encode(sys.argv[2]) - print(arg) - print(check_fcs(arg)) # powinno zawsze zwracać true + arg, fcs = encode(sys.argv[2]) + print(arg, fcs) + print(check_fcs(arg, fcs)) # powinno zawsze zwracać true elif sys.argv[1] == '-c' or sys.argv[1] == '-check': - print(check_fcs(sys.argv[2])) + arg = sys.argv[2] + fcs = ast.literal_eval(sys.argv[3]) + print(check_fcs(arg, fcs)) else: raise IndexError except IndexError: - print("To encode: python3 CRC16.py -e [argument]\nTo check FCS: python3 CRC16.py -c [argument]") + print("To encode: python3 CRC16.py -e [argument]\nTo check result: python3 CRC16.py -c [argument] [fcs]") if __name__ == "__main__": -- 2.20.1 From bc3dcdaabe2971fc0328316e7a898e8a7bf64c55 Mon Sep 17 00:00:00 2001 From: Szymon Wojciechowski Date: Wed, 27 Jun 2018 17:29:48 +0000 Subject: [PATCH 07/10] added polynomial addition --- wielomiany.py => poly.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) rename wielomiany.py => poly.py (73%) diff --git a/wielomiany.py b/poly.py similarity index 73% rename from wielomiany.py rename to poly.py index 833e9d6..2f335ff 100644 --- a/wielomiany.py +++ b/poly.py @@ -9,6 +9,22 @@ class Polynomial: self.degree = len(coef_list) - 1 self.coefficients = coef_list + @staticmethod + def add(p1, p2): + result = [] + f = p1.coefficients + g = p2.coefficients + if len(f) >= len(g): + result = f + for i in range(0, len(g)): + result[i] = f[i] + g[i] + else: + result = g + for i in range(0, len(f)): + result[i] = f[i] + g[i] + result = [x % int(Polynomial.n) for x in result] + return Polynomial(result) + @staticmethod def multiply(p1, p2): result = [0] * (p1.degree + p2.degree + 1) @@ -17,14 +33,14 @@ class Polynomial: for i in range(0, len(f)): for j in range(0, len(g)): result[i+j] += f[i] * g[j] - result = [x % int(n) for x in result] + result = [x % int(Polynomial.n) for x in result] return Polynomial(result) @staticmethod def divide(p1, p2): def inverse(x): - for i in range(1, int(n)): - r = (i * x) % int(n) + for i in range(1, int(Polynomial.n)): + r = (i * x) % int(Polynomial.n) if r == 1: break else: @@ -41,13 +57,13 @@ class Polynomial: tmp_coef = f_lead_coef * inverse(g_lead_coef) tmp_exp = len(f) - 1 - g_deg tmp = [] - for i in range(tmp_exp): + for _ in range(tmp_exp): tmp.append(0) tmp.append(tmp_coef) tmp_poly = Polynomial(tmp) sub = Polynomial.multiply(p2, tmp_poly) f = [x - y for x, y in zip(f, sub.coefficients)] - f = [x % int(n) for x in f] + f = [x % int(Polynomial.n) for x in f] while f and f[-1] == 0: f.pop() return Polynomial(f) @@ -60,6 +76,7 @@ class Polynomial: def main(): + Polynomial.n = int(sys.argv[1]) c1 = ast.literal_eval(sys.argv[2]) c2 = ast.literal_eval(sys.argv[3]) @@ -86,5 +103,4 @@ def main(): print(ans) if __name__ == "__main__": - n = int(sys.argv[1]) - main() \ No newline at end of file + main() -- 2.20.1 From f76cc9e06d4f0a1b509b8f9d565849cefcb81865 Mon Sep 17 00:00:00 2001 From: Szymon Wojciechowski Date: Wed, 27 Jun 2018 17:38:32 +0000 Subject: [PATCH 08/10] import poly --- crc16.py | 70 ++------------------------------------------------------ 1 file changed, 2 insertions(+), 68 deletions(-) diff --git a/crc16.py b/crc16.py index ade6f26..0a44f74 100644 --- a/crc16.py +++ b/crc16.py @@ -1,74 +1,8 @@ +from poly import Polynomial import sys import ast -class Polynomial: - - def __init__(self, coef_list): - self.degree = len(coef_list) - 1 - self.coefficients = coef_list - - @staticmethod - def add(p1, p2): - result = [] - f = p1.coefficients - g = p2.coefficients - if len(f) >= len(g): - result = f - for i in range(0, len(g)): - result[i] = f[i] + g[i] - else: - result = g - for i in range(0, len(f)): - result[i] = f[i] + g[i] - result = [x % int(n) for x in result] - return Polynomial(result) - - @staticmethod - def multiply(p1, p2): - result = [0] * (p1.degree + p2.degree + 1) - f = p1.coefficients - g = p2.coefficients - for i in range(0, len(f)): - for j in range(0, len(g)): - result[i+j] += f[i] * g[j] - result = [x % int(n) for x in result] - return Polynomial(result) - - @staticmethod - def divide(p1, p2): - def inverse(x): - for i in range(1, int(n)): - r = (i * x) % int(n) - if r == 1: - break - else: - raise ZeroDivisionError - return i - if p1.degree < p2.degree: - return p1 - f = p1.coefficients - g = p2.coefficients - g_lead_coef = g[-1] - g_deg = p2.degree - while len(f) >= len(g): - f_lead_coef = f[-1] - tmp_coef = f_lead_coef * inverse(g_lead_coef) - tmp_exp = len(f) - 1 - g_deg - tmp = [] - for _ in range(tmp_exp): - tmp.append(0) - tmp.append(tmp_coef) - tmp_poly = Polynomial(tmp) - sub = Polynomial.multiply(p2, tmp_poly) - f = [x - y for x, y in zip(f, sub.coefficients)] - f = [x % int(n) for x in f] - while f and f[-1] == 0: - f.pop() - return Polynomial(f) - - -n = 2 - +Polynomial.n = 2 def normalize_byte(data): while len(data) != 8: -- 2.20.1 From 965b5a039490ff49cb6257956f8eae147a7b1e5a Mon Sep 17 00:00:00 2001 From: Szymon Wojciechowski Date: Wed, 27 Jun 2018 17:43:04 +0000 Subject: [PATCH 09/10] Update 'poly.py' --- poly.py | 33 +-------------------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/poly.py b/poly.py index 2f335ff..9ace2ef 100644 --- a/poly.py +++ b/poly.py @@ -72,35 +72,4 @@ class Polynomial: def gcd(p1, p2): if len(p2.coefficients) == 0: return p1 - return Polynomial.gcd(p2, Polynomial.divide(p1, p2)) - - -def main(): - Polynomial.n = int(sys.argv[1]) - c1 = ast.literal_eval(sys.argv[2]) - c2 = ast.literal_eval(sys.argv[3]) - - f = Polynomial(c1) - g = Polynomial(c2) - - ans = [] - - mul = Polynomial.multiply(f, g) - ans.append(mul.coefficients) - - try: - div = Polynomial.divide(f, g) - ans.append(div.coefficients) - except ZeroDivisionError as e: - ans.append(e) - - try: - gcd = Polynomial.gcd(f, g) - ans.append(gcd.coefficients) - except ZeroDivisionError as e: - ans.append(e) - - print(ans) - -if __name__ == "__main__": - main() + return Polynomial.gcd(p2, Polynomial.divide(p1, p2)) \ No newline at end of file -- 2.20.1 From 074d255dabf29fb5320ca087fefa2d3082e5daf8 Mon Sep 17 00:00:00 2001 From: Szymon Wojciechowski Date: Wed, 27 Jun 2018 19:59:00 +0000 Subject: [PATCH 10/10] Update 'poly.py' --- poly.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/poly.py b/poly.py index 9ace2ef..d9ddd32 100644 --- a/poly.py +++ b/poly.py @@ -7,7 +7,7 @@ class Polynomial: def __init__(self, coef_list): self.degree = len(coef_list) - 1 - self.coefficients = coef_list + self.coefficients = [x % Polynomial.n for x in coef_list] @staticmethod def add(p1, p2): @@ -72,4 +72,4 @@ class Polynomial: def gcd(p1, p2): if len(p2.coefficients) == 0: return p1 - return Polynomial.gcd(p2, Polynomial.divide(p1, p2)) \ No newline at end of file + return Polynomial.gcd(p2, Polynomial.divide(p1, p2)) -- 2.20.1