Skip to content
Snippets Groups Projects
Commit d9480900 authored by nicolas.albanesi's avatar nicolas.albanesi
Browse files

Changed indentation to tabs, modified get_possibilities

parents 66a3bb06 15076478
No related branches found
No related tags found
No related merge requests found
# MAIN FILE TO TEST FUNCTIONS
from polynome import *
from reed_solomon 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
reed_solomon = reed_decode([115, 117, 101, 118, 122, 116, 57, 108, 32, 224, 62, 116, 115, 140, 32, 108, 153, 83, 169, 117, 108, 112, 32, 110, 101, 55, 96, 61, 160, 218, 228, 156, 224, 203, 12, 75, 180, 23, 220, 211, 137, 139, 206])
# reed_solomon = reed_decode([2, 3 ,4])
reed_solomon.show()
......@@ -9,8 +9,6 @@ def get_possibilities(l: list, index: int):
for x, _ in enumerate(l):
l[x] = (x, l[x])
# ! la valeur 20 est hardcodée. Paramètre de fonction ??
l_fixe = l[index:] # Liste contenant aucune erreur
l_posi = l[:index] # Liste contenant des erreurs,
......@@ -38,15 +36,20 @@ def lagrange_compute(l: list) -> polynome:
def check_nb_error(l: list, p: polynome) -> int:
nbr_error = 0
for _, item in enumerate(l):
if (item % p.prime_mod) != (p.evaluate(_) % p.prime_mod):
print(f"DEBUG PURPOSES ONLY {item} != p.evaluate({_}) = {p.evaluate(_)}")
for item in l:
if (item[1] % p.prime_mod) != (p.evaluate(item[0]) % p.prime_mod):
print(f"DEBUG PURPOSES ONLY {item[1]} != p.evaluate({item[0]}) = {p.evaluate(item[0])}")
nbr_error += 1
return nbr_error
def reed_decode(l: list) -> polynome:
# print("test")
for points in get_possibilities(l):
if (check_nb_error(l, lagrange_compute(points)) <= 9):
# print(f"{points}")
# lagrange_compute(points).show()
err = check_nb_error(l, lagrange_compute(points))
print(f"{err=}")
if ((err) <= 9):
# Possibilité d'optimiser en evitant de compute 2 fois le poly
return lagrange_compute(points)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment