2020网鼎杯密码学解题,easy_ya有视频讲解

点击观看

easy_ya

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
a = 2291239296
b = 2293340064
c = 3215425945
d = 2994836927

ans = [
0x26bbe454a9dbf80485c4f,
0x69cc8f5d153d97c6e66aa,
0xf23f65e553cec51caced8,
0x98703fcde292536d4183,
0x909b3ae5f9e82cbad2e23,
]

def limit(n): return n & 0xffffffff

confirm_z = []
for i in ans:
confirm_z.append(i & 0xfffff)

confirm_y = []
for i in ans:
confirm_y.append(i >> 52)

confirm_pads = []
for i in ans:
confirm_pads.append((i % 2 ** 52) >> 32 << 12)
mid = []
for i in ans:
mid.append((i & 0xffffffff) >> 20)


flag = [[] for i in range(5)]
for k in range(len(ans)):
for i in tqdm(range(2 ** 12)):
for j in range(2 ** 5):
pads = confirm_pads[k] + i
y = confirm_y[k]
z = ((i ^ mid[k]) << 20) + confirm_z[k]
pad = (j << 27) + (pads >> 5)
for m in range(32):
z = limit(z - ((y*16 + c) ^ (y + pads) ^ ((y >> 5) + d)))
y = limit(y - ((z*16 + a) ^ (z + pads) ^ ((z >> 5) + b)))
pads = limit(pads - pad)
tmp = long_to_bytes(y) + long_to_bytes(z)

for q in tmp:
if chr(q) in string.digits + string.ascii_letters + '{' + '}' or q == 0:
check = True
else:
check = False
break
if check == True:
flag[k].append(tmp)
# print(flag)
for i in flag:
print(i)
>>>
[b'flag{1d8']
[b'abac2ddf']
[b'Bt0KDI8e', b'87ac396a', b'o5WSow2y']
[b'5f11e839']
[b'3KsR0AIJ', b'xL{6dmne', b'a1012}\x00\x00', b'c755pB0e', b'9n9B}M}w', b'TzCDCRG5']

Boom

MD5查值,三元一次方程,一元二次方程

you raise me up

1
2
from sympy.ntheory import discrete_log
print(n2s(discrete_log(p,a,b)))

评论