dlp/dlp.py
2025-12-23 08:58:57 +01:00

31 lines
577 B
Python

#!/usr/bin/env python3
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 = 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