通過調試無法弄清楚,爲什麼我的隱藏字符串前面有b
?python中的錯誤解碼結果
我在結果得到這個字符串: '1101000011001010110110001101100011'
def retr(filename):
img = Image.open(filename)
binary = ''
if img.mode in ('RGBA'):
img = img.convert('RGBA')
datas = img.getdata()
for item in datas:
digit = decode(rgb2hex(item[0], item[1], item[2]))
if digit == None:
pass
else:
binary = binary + digit
if (binary[-16:] == '1111111111111110'):
# print("Success")
return bin2str(binary[:-16])
return str(bin2str(binary))
return "Incorrect Image Mode, Couldn't Retrieve"
,反而會導致控制檯是:b'hello'
。 b
從哪裏來?
做一些預溫控功能之前retr()
:
def rgb2hex(r, g, b):
return '#{:02x}{:02x}{:02x}'.format(r, g, b)
def hex2rgb(hexcode):
return int(hexcode[1:3], 16), int(hexcode[3:5], 16), int(hexcode[5:7], 16)
def str2bin(message):
binary = bin(int(binascii.hexlify(message.encode("ascii")), 16))
return binary[2:]
def bin2str(binary):
message = binascii.unhexlify('%x' % (int('0b' + binary, 2)))
return message
幫助,請趕上那b
..
一個'B'前綴表示你有一個字節串,看到的是https:// docs.python.org/3/library/stdtypes.html#bytes – cssko
@cssko,我不能刪除它? – x24
你爲什麼要「刪除」它? –