def dechiffre(keys): X, Y = [], [] for ind, key in enumerate(keys): key = b64decode(key) uidxor, x ,y = key.split(":") uid = polynome.combine(uidxor, y) if ind == 0: uidsuite = uid need = len(uid) - 1 X.append(int(x)) Y.append(int(y)) else: if uid == uidsuite : if need > 0: X.append(int(x)) Y.append(int(y)) need-=1 else: break else: print "La clé numéro " + str(ind+1) +" ne correspond pas" sys.exit() if need > 0: print "Nombre de clés insuffisant" sys.exit() pol = lagrange(X, Y) return int2String(int(pol.eval(0)))
def chiffre(chaine, degre, nb_cle): pol = genPoly(string2Int(chaine), degre) keys = genKeys(pol, genListe(nb_cle)) randpool = ascii_letters + digits uid = "".join([random.choice(randpool) for k in range(degre+1)]) return [b64encode(polynome.combine(uid,y)+":"+str(x)+":"+str(y)) for x,y in keys]