我在學習隱寫術以及它是如何實現的。我看着一些代碼上Github,但我無法理解的代碼的以下部分:爲什麼在隱寫信息的末尾添加了某個字符串
def hide(filename, message):
img = Image.open(filename)
binary = str2bin(message) + '1111111111111110'
if img.mode in ('RGBA'):
img = img.convert('RGBA')
datas = img.getdata()
newData = []
digit = 0
temp = ''
for item in datas:
if (digit < len(binary)):
newpix = encode(rgb2hex(item[0],item[1],item[2]),binary[digit])
if newpix == None:
newData.append(item)
else:
r, g, b = hex2rgb(newpix)
newData.append((r,g,b,255))
digit += 1
else:
newData.append(item)
img.putdata(newData)
img.save(filename, "PNG")
return "Completed!"
return "Incorrect Image Mode, Couldn't Hide"
正如你所看到的,筆者消息(文本)轉換成二進制時添加字符串'1111111111111110'
串。他爲什麼這樣做,爲什麼除了最後一位是0之外都是1呢?