diff --git a/algo.py b/algo.py index 2d27308cdf171248497ec3bfb4247a39ab739aff..44a45ee9f5654ca66ae2fe5a2aa1924053be8db1 100644 --- a/algo.py +++ b/algo.py @@ -56,7 +56,7 @@ def exponentiation_rapide(a, exp, n): n (uint): the modulo Returns: - uint: An array with the pgdc and the coefficients of bachet_bezout, [pgdc, u, v] + uint: The result of of the quick explanation """ if (a == 0): @@ -72,7 +72,7 @@ def exponentiation_rapide(a, exp, n): b = (b**2) % n exp = exp // 2 - return r + return int(r) def is_square(a): """Check if a number is a perfect square, using the Newton methode @@ -115,7 +115,7 @@ def fermat_factorization(n): b2 = a**2 - n if (is_square(b2)): - b = math.sqrt(b2) + b = int(math.sqrt(b2)) break a += 1 diff --git a/main.py b/main.py index 87b3ba9d709a51fe1f817d465650f7348382884b..4b6203e51a58f702d84fb25468ef303784f58754 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,7 @@ -from ast import For, arguments, parse -from cProfile import label -from operator import truediv -import sys from algo import * def main(): - mu = { + mu = [ 416687707, 420774592, 1078076801, @@ -29,36 +25,37 @@ def main(): 1895548977, 1274512749, 712992858 - } #encrypted message - n = 1989929159 #first element public key - e = 2203 #second element public key + ] # encrypted message + n = 1989929159 # first element public key + e = 2203 # second element public key - length = length(mu) + length = len(mu) # --- private element --- - M = [] #decriypted message - msg = "" #message (string) - p, q = 0 #primes numbers - d = 0 #private key + M = [] # decriypted message + msg = "" # message (string) + p = 0 # fisrt prime number + q = 0 # second prime number + d = 0 # private key #--- crack RSA --- a, b = fermat_factorization(n) - + p = a + b q = a - b - - print(n == p * q, "\n") - + fi = (p - 1) * (q - 1) d = inverse_modulaire(e, fi) # --- decode mu & initialise msg --- for i in range(length): - M[i] = exponentiation_rapide(mu[i], d, n) + M.append(exponentiation_rapide(mu[i], d, n)) for m in M: - print(decode_msg(m), end='') + msg += decode_msg(m) + print("p, q :", p, q, "\nfi :", fi, "\nd :", d, "\nmsg :", msg) + if __name__ == "__main__": main() \ No newline at end of file