From c62223d98c934e78f96f55bbbbb21287f72474ad Mon Sep 17 00:00:00 2001 From: boyreau Date: Sat, 14 Nov 2026 13:25:54 +0100 Subject: [PATCH] =?UTF-8?q?public=5Fkey=5Fcryptography=20course=20-=20chal?= =?UTF-8?q?lenge=208=20-=20pourquoi=20utiliser=202=20nombres=20premiers=20?= =?UTF-8?q?au=20lieu=20d'un\=20On=20retrouve=20facilement=20phi(N)=20donc?= =?UTF-8?q?=20on=20peut=20facilement=20calculer=20la=20cl=C3=A9=20priv?= =?UTF-8?q?=C3=A9=20et=20inverser=20le=20chiffrement.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public_key_cryptography.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) 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))