-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdlog_brute.py
30 lines (21 loc) · 998 Bytes
/
dlog_brute.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import gmpy2
from gmpy2 import c_mod,mpz,powmod,f_mod
import sys
p=mpz(13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084171)
h=mpz(3239475104050450443565264378728065788649097520952449527834792452971981976143292558073856937958553180532878928001494706097394108577585732452307673444020333)
g=mpz(11717829880366207009516117596335367088558084999998952205599979459063929499736583746670572176471460312928594829675428279466566527115212748467589894601965568)
B = mpz(2)**mpz(20)+1
hash_tables = {} #dictionary
for x1 in range(0,B):
g_x1_inv = powmod(g,mpz(x1)*-1,p)
left_hash = h* mpz(g_x1_inv)
left_hash = f_mod(left_hash,p)
hash_tables[left_hash] = mpz(x1)
for x0 in range(0,B):
lookup = powmod(powmod(g,B,p),mpz(x0),p)
if lookup in hash_tables:
print hash_tables[lookup]
print x0
x = x0 * B + hash_tables[lookup]
print "The solution to disrete log problem is ",x
sys.exit()