diff --git a/inverse_mult.py b/inverse_mult.py index b4187920a0095794ffd46c66d5ccc3e88ef14335..8f74c4f08739ab9ea379f72dc9761090f249cb62 100644 --- a/inverse_mult.py +++ b/inverse_mult.py @@ -7,10 +7,10 @@ from euclide import * # x = Multiplicative inverse of a mod p: # a * x mod p = 1 def inverse_mult(a, p) : - pgcd, x, y = pgcd_etendu(a, p) - if pgcd != 1: - return None - return x if a > p else y + pgcd, x, y = pgcd_etendu(a, p) + if pgcd != 1: + return None + return x if a > p else y if __name__ == "__main__": - print(inverse_mult(3, 11)) \ No newline at end of file + print(inverse_mult(3, 11)) \ No newline at end of file diff --git a/main.py b/main.py index 32da3ec71778f310339335f7f1e3bdc2fc07e47f..f0006fb305e5cda80c4ccd60d69b4a57dcca7e1e 100644 --- a/main.py +++ b/main.py @@ -3,8 +3,8 @@ from polynome import * if __name__ == "__main__": - pol1 = polynome([1, 2, 3, 4, 5]) - pol2 = polynome([2, 3, 4, 4, 4]) - # pol3 = pol1.add(pol2) - pol1.show() - pol1.evaluate(2) \ No newline at end of file + pol1 = polynome([1, 2, 3, 4, 5]) + pol2 = polynome([2, 3, 4, 4, 4]) + # pol3 = pol1.add(pol2) + pol1.show() + pol1.evaluate(2) \ No newline at end of file diff --git a/polynome.py b/polynome.py index 2f8be27262a6a75eb5588d80c73ed755629eb62f..af51ff964594352c7201c74b0411b9cf5a43a2f6 100644 --- a/polynome.py +++ b/polynome.py @@ -4,46 +4,46 @@ import math class polynome(): - def __init__(self, coefs : list): - self.coefs = coefs - self.prime_mod = 229 + def __init__(self, coefs : list): + self.coefs = coefs + self.prime_mod = 229 - def show(self): - for i in range(len(self.coefs) - 1, -1, -1): - power = "" - if self.coefs[i] != 0: - coef = str(self.coefs[i]) - if i != 0: # its not 0's degree - power = f"x^{i} + " - else: - coef = "" - print(f"{coef}{power}", end="") - print() # new line - - def add(self, poly_2): - coeff_poly_1 = self.coefs - if len(coeff_poly_1) > len(poly_2.coefs): - while len(coeff_poly_1) > len(poly_2.coefs): - poly_2.coefs.append(0) - else: - while len(coeff_poly_1) < len(poly_2.coefs): - coeff_poly_1.append(0) - - for i in range(0, len(coeff_poly_1)): - coeff_poly_1[i] = (coeff_poly_1[i] + poly_2.coefs[i]) % self.prime_mod - - return polynome(coeff_poly_1) + def show(self): + for i in range(len(self.coefs) - 1, -1, -1): + power = "" + if self.coefs[i] != 0: + coef = str(self.coefs[i]) + if i != 0: # its not 0's degree + power = f"x^{i} + " + else: + coef = "" + print(f"{coef}{power}", end="") + print() # new line + + def add(self, poly_2): + coeff_poly_1 = self.coefs + if len(coeff_poly_1) > len(poly_2.coefs): + while len(coeff_poly_1) > len(poly_2.coefs): + poly_2.coefs.append(0) + else: + while len(coeff_poly_1) < len(poly_2.coefs): + coeff_poly_1.append(0) + + for i in range(0, len(coeff_poly_1)): + coeff_poly_1[i] = (coeff_poly_1[i] + poly_2.coefs[i]) % self.prime_mod + + return polynome(coeff_poly_1) - def mul(self, poly_2): - coeff_poly_res = [0] * (len(self.coefs) + len(poly_2.coefs) - 1) - for index_1, value_1 in enumerate(self.coefs): - for index_2, value_2 in enumerate(poly_2.coefs): - coeff_poly_res[index_1 + index_2] += (value_1 * value_2) % self.prime_mod - return polynome(coeff_poly_res) - - def evaluate(self, x): - # Using horner method - res = 0 - for i in range(len(self.coefs) - 1, -1, -1): - res = (res * x + self.coefs[i]) - return (res % self.prime_mod) + def mul(self, poly_2): + coeff_poly_res = [0] * (len(self.coefs) + len(poly_2.coefs) - 1) + for index_1, value_1 in enumerate(self.coefs): + for index_2, value_2 in enumerate(poly_2.coefs): + coeff_poly_res[index_1 + index_2] += (value_1 * value_2) % self.prime_mod + return polynome(coeff_poly_res) + + def evaluate(self, x): + # Using horner method + res = 0 + for i in range(len(self.coefs) - 1, -1, -1): + res = (res * x + self.coefs[i]) + return (res % self.prime_mod) diff --git a/reed_solomon.py b/reed_solomon.py index 0e7efb1facec1883663457e7528209a5b3c9ce95..1183dc3180cea2cb3da1ded62f04b32ae51d54d1 100644 --- a/reed_solomon.py +++ b/reed_solomon.py @@ -3,7 +3,7 @@ from polynome import * from inverse_mult import * from itertools import combinations -def get_possibilities(l: list): +def get_possibilities(l: list, index: int): # Transforme the list in list of tupples with their indexes for x, _ in enumerate(l): @@ -11,8 +11,8 @@ def get_possibilities(l: list): # ! la valeur 20 est hardcodée. Paramètre de fonction ?? - l_fixe = l[20:] # Liste contenant aucune erreur - l_posi = l[:20] # Liste contenant des erreurs, + l_fixe = l[index:] # Liste contenant aucune erreur + l_posi = l[:index] # Liste contenant des erreurs, p = list(combinations(l_posi, 2))