if "-debug" in sys.argv: debug_mode = True #Récupération de l'exposant server = Server(BASE_URL) e = server.query(GET_CHALLENGE + login)['e'] #Choix de p et q p = 1 q = 1 phi_n = 1 #Vérification de p et q - ok si p != q et que si e est premier avec phi_n while ((p == q) or (PGCD(e, phi_n) != 1)): p = get_primal_number() q = get_primal_number() phi_n = get_phi(p,q) #Calcul de n, en fonction de p et q choisis n = p * q #Calcul de d, inverse de e mod (phi_n) d = (mod_inv(e, phi_n)) % phi_n if debug_mode: print("e: {0}".format(e)) print("p: {0}".format(p)) print("q: {0}".format(q)) print("n: {0}".format(n)) print("d: {0}".format(d))
def compute_y(): global m global n global p global q global U global y p = 1 q = 1 #Tant que p et de q ne sont pas congruents à 3 % 4... while (not is_congruent(p) or not is_congruent(q)): if not is_congruent(p): p = get_primal_number() if not is_congruent(q): q = get_primal_number() if debug_mode: print('p: {0} - prime: {1}'.format(p, is_probable_prime(p))) print('q: {0} - prime: {1}'.format(q, is_probable_prime(q))) n = get_Rabin_PK(p,q) if debug_mode: print('n: {0}'.format(n)) m = server.query(GET_CHALLENGE + login, {'n' : n})['m'] #Conversion de m en hexadécimal m = int(m, base=16) if debug_mode: print('m: {0}'.format(m)) #Apport d'un padding de 2^256 U = random.randint(2, pow(2, 256)) sha256 = hashlib.sha256() sha256.update("{0:08x}".format(m).encode()) sha256.update("{0:08x}".format(U).encode()) y = int(sha256.hexdigest(), base=16) #y est-il un carré modulo p? if not is_square_mod(y, p): if debug_mode: print("{0} is not a square mod {1}".format(y, p)) return False else: if debug_mode: print("{0} is a square mod {1}".format(y, p)) #y est-il un carré modulo q? if not is_square_mod(y, q): if debug_mode: print("{0} is not a square mod {1}".format(y, q)) return False else: if debug_mode: print("{0} is a square mod {1}".format(y, q)) return True