Python base64 解码错误: TypeError: argument should be a bytes-like object or ASCII string, not 'int'
The error occurs because the flag variable is an integer, not a bytes-like object or ASCII string. To fix the error, you need to convert the flag variable to a bytes-like object before passing it to the base64.b64decode() function. Here's the corrected code:
import base64
data = [0x7C, 0x7B, 0x77, 0x21, 0x99, 0x44, 0x73, 0x42, 0x79, 0x4C, 0x75, 0x42, 0xA0, 0x5C, 0x7F, 0x42, 0x93, 0x76, 0x22, 0x03, 0x79, 0x56, 0x91, 0x4C, 0x9F, 0x03, 0x9D, 0x49, 0x7C, 0x44, 0x87, 0x41]
flag = b''
for i in range(len(data)):
if (i%2 == 0) or (data[i] == 33):
data[i] = data[i] - 33
else:
data[i] = data[i] + 0x03
flag = flag + bytes([data[i] ^ 0x35])
print(chr(data[i] ^ 0x35), end="")
# base64 decoding
flag = base64.b64decode(flag)
print(flag)
This code first converts the flag variable to a bytes-like object using b''. Then, instead of directly assigning flag to data[i] ^ 0x35, it appends the result to the flag variable using flag = flag + bytes([data[i] ^ 0x35]). Finally, the base64.b64decode() function is called with the correct flag parameter.
原文地址: https://www.cveoy.top/t/topic/o7eC 著作权归作者所有。请勿转载和采集!