隐写术(Steganography):是关于信息隐藏,即不让计划的接收者之外的任何人知道信息的传递事件(而不只是信息的内容)的一门技巧与科学
1、随便找两张图
2、利用python实现将图ctf.png 隐藏到图1539.jpg中
python:
from PIL importImagefrom skimage importcolorimportnumpy as npimportmatplotlib.pyplot as pltimportmath
img=np.array(Image.open(‘1539.jpg‘))
mark=np.array(Image.open(‘ctf.png‘))
rows,cols,dims=mark.shapefor i inrange(0,dims):for j in range(0,rows*2):for k in range(0,cols*2):
img[j,k,i]=img[j,k,i]&252
for i inrange(0,dims):for j inrange(0,rows):for k inrange(0,cols):
img[2*j,2*k,i]=img[2*j,2*k,i]+(mark[j,k,i]&192)//64img[2*j,2*k+1,i]=img[2*j,2*k+1,i]+(mark[j,k,i]&48)//16img[2*j+1,2*k,i]=img[2*j+1,2*k,i]+(mark[j,k,i]&12)//4img[2*j+1,2*k+1,i]=img[2*j+1,2*k+1,i]+(mark[j,k,i]&3)
img=Image.fromarray(img)
img.save(‘C:\1539_with_ctf.png‘)
得:
3、从图1539_with_ctf.png中提取隐藏的图ctf.png
python:
from PIL importImagefrom skimage importcolorimportnumpy as npimportmatplotlib.pyplot as pltimportmath
imgwmark=np.array(Image.open(‘1539_with_ctf.png‘))
result=imgwmark
rows,cols,dims=imgwmark.shape
rows=rows//2cols=cols//2
for i inrange(0,dims):for j in range(0,rows*2):for k in range(0,cols*2):
imgwmark[j,k,i]=imgwmark[j,k,i]&3
for i inrange(0,dims):for j inrange(0,rows):for k inrange(0,cols):
result[j,k,i]=imgwmark[2*j,2*k,i]*64+imgwmark[2*j,2*k+1,i]*16
+imgwmark[2*j+1,2*k,i]*4+imgwmark[2*j+1,2*k+1,i]
mark_get=Image.fromarray(result)
mark_get.save(‘mark_get.png‘)
得:
注:本段代码需要用到python的pillow和skimage库,skimage库的详细安装见http://www.cnblogs.com/xdjun/p/7874794.html
----------------------------------------------------------------分割线---------------------------------------------------------
ps:萌新一枚,本文纯为学习笔记,以防某日犯傻忘记--。如有不妥处,望大佬们赐教~
原文地址:http://www.cnblogs.com/xdjun/p/7875048.html