def count(n: list):
'''用来统计出现次数最多的字符,以此来排除乱码'''
res = ""
for i in range(0,len(n[0]),2):
tmp = {}
for j in n:
if j[i:i+2] in tmp:
tmp[j[i:i+2]] += 1
else:
tmp[j[i:i+2]] = 1
counts = 0
hexs = ""
for key, value in tmp.items():
if value > counts:
hexs,counts = key,value
res += chr(int(hexs,16))
return res
def read_file_in_hex(file_path):
with open(file_path, 'rb') as file:
content = file.read()
hex_output = content.hex()[:18000] # 截取一段恰当长度,后面都是乱码+重复
ans = ""
for i in range(0,len(hex_output),2):
ans += str(hex_output[i+1])
result=""
while int(ans[0:8],2) != 0x30: # 第一次输出时发现是乱码,要处理移位,根据flag猜测第一位是0
ans = ans[1:]
for i in range(0,len(ans),8):
result += str(hex(int(ans[i:i+8],2))[2:])
result = result[:-(len(result)%88)]
uuid = []
for i in range(0,len(result),88):
uuid += [result[i:i+88]]
print(count(uuid))
file_path = 'flag.txt'
read_file_in_hex(file_path)