forked from dnc1994/Stanford-Cryptography-I
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pa5.py
34 lines (26 loc) · 913 Bytes
/
pa5.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
29
30
31
32
33
34
from gmpy2 import mpz, powmod, f_mod
p = mpz('134078079299425970995740249982058461274793658205923933\
77723561443721764030073546976801874298166903427690031\
858186486050853753882811946569946433649006084171')
g = mpz('11717829880366207009516117596335367088558084999998952205\
59997945906392949973658374667057217647146031292859482967\
5428279466566527115212748467589894601965568')
h = mpz('323947510405045044356526437872806578864909752095244\
952783479245297198197614329255807385693795855318053\
2878928001494706097394108577585732452307673444020333')
B = 2 ** 20
hash = {}
print 'start building...'
for x1 in range(B):
if x1 % 10000 == 0:
print '%d completed.' % x1
left = f_mod(h * powmod(g, -x1, p), p)
hash[left] = x1
for x0 in range(B):
if x0 % 10000 == 0:
print '%d completed.' % x0
right = powmod(g, x0 * B, p)
if right in hash:
x = x0 * B + hash[right]
print 'Solution:\t', x
break