First commit

This commit is contained in:
Lukian 2025-01-23 17:57:15 +01:00
commit 43a72c3fb7
12 changed files with 213 additions and 0 deletions

21
lib/diffie_hellman.py Normal file
View file

@ -0,0 +1,21 @@
# Python Diffie-Hillman implémentation
import random
import lib.miller_rabin as miller
import lib.arithmetics as arithm
def get_p_and_g(n: int) -> (int, int):
p = miller.get_random_prime(n)
g = random.randint(2**(n-1), p)
return (p, g)
def get_x(n: int) -> int:
return random.randint(2**(n-1), 2**n - 1)
def get_X(x: int, p: int, g: int) -> int:
return arithm.modpow(g, x, p)
def get_K(X: int, y: int, p: int):
return arithm.modpow(X, y, p)