You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
811 B
37 lines
811 B
import sympy
|
|
import time
|
|
from Crypto.PublicKey import RSA
|
|
from Crypto.Util.number import inverse
|
|
from math import gcd
|
|
|
|
|
|
file_public_key = input("Entrer le chemin de la clé publique: ")
|
|
|
|
with open(file_public_key, "r") as f:
|
|
key = RSA.importKey(f.read())
|
|
|
|
n = ... # trouver le n de la clé
|
|
e = ... # trouver le e de la clé
|
|
|
|
chrono = time.time()
|
|
|
|
factors = sympy.factorint(n)
|
|
print("Found factors in", time.time() - chrono, "seconds")
|
|
|
|
p, q = list(factors.keys())
|
|
|
|
print(f"p={p}, q={q}")
|
|
|
|
phi = ... # Trouver phi
|
|
|
|
d = ... # trouver d
|
|
|
|
|
|
private_key = RSA.construct((n, e, d, p, q))
|
|
private_key_pem = private_key.export_key()
|
|
|
|
private_key_file = "private_key.pem"
|
|
with open(private_key_file, "wb") as f:
|
|
f.write(private_key_pem)
|
|
|
|
print(f"Clé privée générée et sauvegardée dans '{private_key_file}'") |