Saataa andagii !

This commit is contained in:
Lukian 2025-01-23 19:06:47 +01:00
parent 43a72c3fb7
commit 75d0a97501
6 changed files with 10 additions and 8 deletions

View file

@ -1,8 +1,5 @@
# Python RSA implementation
import random
import sys
import lib.arithmetics as arithm
import lib.miller_rabin as miller
@ -16,15 +13,21 @@ def get_p_and_q(n: int) -> (int, int):
return (p, q)
def get_keys(l: int) -> int:
# Get p and q
p, q = get_p_and_q(l // 2)
# Compute n and phy(n)
n = p * q
phy_n = (p - 1) * (q - 1)
# Chose e = 65537
e = 65537
# Ensure e fits with the others numbers
while arithm.gcd(e, phy_n) != 1:
p, q = get_p_and_q(l // 2)
n = p * q
phy_n = (p - 1) * (q - 1)
# Compute d
d = arithm.mod_inverse(e, phy_n)
# Return e, d and n
return (e, d, n)
def encrypt(m: int, e: int, n: int) -> int: