Steganography,位操作实现图片隐藏

来源:互联网 发布:dos命令查看mac地址 编辑:程序博客网 时间:2024/06/06 10:50

通过图片最后两位的提取和数学计算得到隐藏在其中的另一张图片

首先先将一张图的uint8数值变化到三以内,然后替换掉另一张图的最后两位,实现隐藏

from PIL import Imageimport numpy as npori = np.asarray(Image.open('Steganography_original.png'))ori=ori>>2ori=ori<<2print("ori:")print(ori)to_add = np.asarray(Image.open('Steganography_recovered.png').convert('RGB'))print("to add:")print(to_add)to_add=to_add/85print("to add /85:")print(to_add)result=np.bitwise_or(ori.astype(int), to_add.astype(int))print("result:")print(result)im = Image.fromarray(np.uint8(result))im.show()im.save('Steganography_added.png')
逆操作就可以找到里面的猫
from PIL import Imageimport numpy as npI=Image.open('Steganography_added.png')stego = np.asarray(I)extracted = stego & 0b00000011extracted *= int(255 / 3)print("what we get:")print(extracted)im = Image.fromarray(np.uint8(extracted))im.show()im.save('Steganography_get.png')

图片使用了经典猫和树

原创粉丝点击