diff --git a/public_key_cryptography.py b/public_key_cryptography.py index f18c046..fa44e7f 100644 --- a/public_key_cryptography.py +++ b/public_key_cryptography.py @@ -64,21 +64,8 @@ def prime_factorization(N: int): # Challenge PK-crypto-8 -def _find_single_prime_RSA_private_key(N: int, d: int): - # N = x² - # p = sqrt(N) -> on factorise facilement p - # phi(N) = phi(p²) = p * (p-1) - # phi(N) = sqrt(N) * (sqrt(N) - 1) = p * (p - 1) - # d*e = 1 mod phi(N) - # Il ne reste plus qu'à trouver l'inverse modulaire de e mod Phi(N) pour avoir d - p = int(sqrt(N)) - phi_N = p * (p - 1) - e = pow(d, -1, phi_N) - print(f"N: {N}, p: {p}, phi_N: {phi_N}, e: {e}") - return e - - def reverse_single_prime_RSA_cipher(c: int, N: int, d: int): # On calcule la clé privée puis on applique la formule de déchiffrement - e = _find_single_prime_RSA_private_key(N, d) + # N est premier donc phi(N) = N - 1 donc on peut facilement calculer la clé privée. + e = pow(d, -1, (N - 1)) return long_to_bytes(pow(c, e, N))