香山杯 [rev] easy_py

逆向PYC文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def encode(enc, length):
if length == 0:
return 0
for i in range(length):
enc[length + i] ^= enc[i]
encode(enc, length >> 1)

tmp = [100, 5, 87, 2, 86, 0, 3, 84, 80, 2, 87, 80, 80, 86, 85, 2, 85, 87, 7, 0, 87, 4, 3, 3, 5, 84, 84, 11, 81, 5, 6, 13]
flag = "?"

if len(flag) != 32:
exit(0)
enc = map(ord, flag)
encode(enc, len(enc) >> 1)
if tmp == enc:
print("yes")
else:
print("wrong")

解密:

1
2
3
4
5
6
def decode(enc, length):
if length > 16:
return 0
for i in range(length):
enc[length + i] ^= enc[i]
decode(enc, length << 1)

今日教训:比赛摸鱼不好好看题,痛失一血= =。