First commit
This commit is contained in:
commit
43a72c3fb7
12 changed files with 213 additions and 0 deletions
21
lib/diffie_hellman.py
Normal file
21
lib/diffie_hellman.py
Normal 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)
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue