add dlp script
This commit is contained in:
parent
ef3890934c
commit
0a12ae2d13
34
dlp.py
Normal file
34
dlp.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from Cryptotools.Numbers.primeNumber import isPrimeNumber
|
||||||
|
from Cryptotools.Groups.cyclic import Cyclic
|
||||||
|
from math import log, ceil
|
||||||
|
|
||||||
|
def ope(a, b, n):
|
||||||
|
return (a ** b) % n
|
||||||
|
|
||||||
|
n = 7919
|
||||||
|
group = list()
|
||||||
|
for x in range(1, n):
|
||||||
|
group.append(x)
|
||||||
|
|
||||||
|
cyclic = Cyclic(group, n, ope)
|
||||||
|
g = cyclic.getPrimitiveRoot()
|
||||||
|
|
||||||
|
print(f"g: {g}")
|
||||||
|
|
||||||
|
#secretKey = 3257
|
||||||
|
#secretKey = 134
|
||||||
|
secretKey = 4057
|
||||||
|
|
||||||
|
publicKey = ope(g, secretKey, n)
|
||||||
|
print(f"Public key: {publicKey}")
|
||||||
|
|
||||||
|
|
||||||
|
# Now, we need to find the secret key based on the DLP
|
||||||
|
for x in range(1, n):
|
||||||
|
l = log(x, g)
|
||||||
|
h = ceil(g ** l)
|
||||||
|
if ope(g, h, n) == publicKey:
|
||||||
|
print(f"Secret key found: {h}")
|
||||||
|
break
|
||||||
Loading…
Reference in New Issue
Block a user