Skip to content

Commit bc770f0

Browse files
committed
add some solver
1 parent 1bcd0dd commit bc770f0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env sage
2+
# coding: utf-8
3+
4+
import yaml # if you don't have, run 'sage -pip install pyyaml'
5+
from Crypto.Cipher import AES
6+
from Crypto.Util.number import long_to_bytes
7+
8+
a, b, z, n = yaml.safe_load(open('pubkey'))
9+
enc_key, encrypted_flag = yaml.safe_load(open('encrypted_flag'))
10+
11+
m = matrix(ZZ, len(a) + 1, len(a) + 2)
12+
l = 30 # lambda
13+
for i in xrange(len(a)):
14+
m[i, i] = 1
15+
m[i, len(a)] = -l * a[i]
16+
m[len(a), len(a)] = l * enc_key
17+
m[len(a), len(a) + 1] = 1
18+
19+
m = m.LLL()
20+
21+
for row in m:
22+
if row[-2] == 0 and row[-1] == 1:
23+
print 'Found key candidate'
24+
key = sum([x * y for x, y in zip(b, list(row[0:len(a)]))]) % z
25+
aes = AES.new(long_to_bytes(key).rjust(16, "\0"), AES.MODE_CBC, long_to_bytes(enc_key).rjust(16, "\0")[0:16])
26+
print repr(encrypted_flag)
27+
print aes.decrypt(encrypted_flag.encode('latin-1')) #

0 commit comments

Comments
 (0)