Use Python for simple picture steganography

Source: Internet
Author: User

steganography (steganography): A technique and science for information hiding, that is, not letting anyone outside of the program know the delivery event of information (not just the content of the information)

1, randomly looking for two pictures

2, the use of Python implementation of the figure ctf.png hidden in figure 1539.jpg

Python:

 fromPILImportImage fromSkimageImportColorImportNumPy as NPImportMatplotlib.pyplot as PltImportmathimg=np.array (Image.open ('1539.jpg')) Mark=np.array (Image.open ('Ctf.png')) Rows,cols,dims=Mark.shape forIinchRange (0,dims): forJinchRange (0,rows*2):         forKinchRange (0,cols*2): Img[j,k,i]=img[j,k,i]&252 forIinchRange (0,dims): forJinchRange (0,rows): forKinchRange (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')

Have

3, extract the hidden figure from the figure 1539_with_ctf.png ctf.png

Python:

 fromPILImportImage fromSkimageImportColorImportNumPy as NPImportMatplotlib.pyplot as PltImportMathimgwmark=np.array (Image.open (' 1539_with_ctf.png') ) Result=Imgwmarkrows,cols,dims=imgwmark.shaperows=rows//2cols=cols//2 forIinchRange (0,dims): forJinchRange (0,rows*2):         forKinchRange (0,cols*2): Imgwmark[j,k,i]=imgwmark[j,k,i]&3 forIinchRange (0,dims): forJinchRange (0,rows): forKinchRange (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')

Have

Note: This code needs to use Python's pillow and skimage libraries, the Skimage library detailed installation See http://www.cnblogs.com/xdjun/p/7874794.html

----------------------------------------------------------------Split Line------------------------------------------------------ ---

PS: Meng New one, this article purely for study notes, in case a day silly forget--。 If there is something wrong, look at the big boys enlighten ~

Use Python for simple picture steganography

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.