corCTF2021 复盘

babyrev

  1. memfrob函数:将字符串的每个字符与42进行异或实现加密。 解密脚本:
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
def is_prime(n: int) -> bool:
if n <= 1:
return False
i = 2
while i <= n // 2:
if n % i == 0:
return False
i += 1
return True


def rot_n(c, n):
ASCII_UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ASCII_LOWER = 'abcdefghijklmnopqrstuvwxyz'

if c in ASCII_UPPER:
return ASCII_UPPER[(ASCII_UPPER.index(c) + n) % 26]
elif c in ASCII_LOWER:
return ASCII_LOWER[(ASCII_LOWER.index(c) + n) % 26]
else:
return c


check = [0x5f, 0x40, 0x5a, 0x15, 0x75, 0x45, 0x62, 0x53, 0x75, 0x46, 0x52, 0x43, 0x5f, 0x75, 0x50, 0x52, 0x75, 0x5f,
0x5c, 0x4f]
# memfrob
check = [c ^ 42 for c in check]
flag = []

for i in range(len(check)):
p = 4 * i
while not is_prime(p):
p += 1
print(rot_n(chr(check[i]), -p), end='')