From 0a12ae2d13a52b1bc92ab2b1a164ab5d03a01dbb Mon Sep 17 00:00:00 2001 From: gbucchino Date: Mon, 22 Dec 2025 16:40:27 +0100 Subject: [PATCH] add dlp script --- dlp.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 dlp.py diff --git a/dlp.py b/dlp.py new file mode 100644 index 0000000..113b615 --- /dev/null +++ b/dlp.py @@ -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