http://bmzclub.cn/challenges#2020sdnisc-%E5%B7%A6%E4%B8%8A%E8%A7%92%E7%9A%84%E7%A7%98%E5%AF%86
enc.py
# encoding=utf-8
flag_enc = open("flag_enc.hex", "wb")
def file_encode(flag):
i = 1
while True:
byte_str = flag.read(1)
if (byte_str == b''):
exit()
byte_str = hex_encode(byte_str)
file_write(flag_enc, byte_str)
# print(byte_str, end="")
i = i + 1
def hex_encode(byte_str):
tmp = int.from_bytes(byte_str, byteorder="big")
if (tmp % 2 == 0):
tmp = (tmp + 1) ^ 128
else:
tmp = (tmp - 1) ^ 128
tmp = bytes([tmp])
return tmp
def file_write(flag_enc, byte_str):
flag_enc.write(byte_str)
if __name__ == '__main__':
with open("./flag.png", "rb") as flag:
file_encode(flag)
flag_enc.close()
flag_enc.hex
逆向处理一下数据
with open('flag.png','wb') as flag:
with open('flag_enc.hex','rb') as f:
for i in f.read():
if (i % 2 == 0):
i = (i + 1) ^ 128
else:
i = (i - 1) ^ 128
i = bytes([i])
flag.write(i)
得到flag.png
使用PS
打开,查看左上角
依此取色块色号的十六进制
015a01
026d02
037803
046804
055a05
063306
077407
086a08
094e09
0a6d0a
0b550b
0c300c
0d590d
0e7a0e
0f6b0f
103510
115911
125412
135913
147a14
154f15
164416
176817
186a18
194e19
1a571a
1b511b
1c791c
1d591d
1e541e
1f6c1f
206820
215a21
225422
235a23
246c24
255a25
266a26
275a27
286828
294f29
2a442a
2b512b
2c7a2c
2d592d
2e322e
2f562f
306830
314e31
326e32
333033
343d34
Python处理
from base64 import *
base64str = ''
with open('data.txt') as f:
for i in f.readlines():
i = chr(int(i[2:4],16))
base64str = base64str + i
flag = b64decode(base64str)
print(base64str)
print(flag)
flag{c6e4c99a6388c5d2a9ae6ef6a843cea6}