资源简介

基于LSB算法的BMP图片隐写,python实现,取RGB的最后一位存取信息

资源截图

代码片段和文件信息

#!/usr/bin/env python
#coding=utf-8
“““
    Author:         Anemone
    Filename:       new.py
    Last modified:  2015-09-26 15:31
    E-mail:         anemone@82flex.com

“““
import sys
import struct

reload(sys)
sys.setdefaultencoding(“utf-8“)
def encrypt(rawImgtestStr):
    testStr=testStr+“\0“
    img=open(rawImg‘rb‘)
    # bfType=struct.unpack(“<2s“img.read(2))
    # print bfType
    # bfSize=struct.unpack(“>I“img.read(4))
    # print hex(bfSize)
    

    bfHeader=img.read(14)
    bfTypebfSizebfReserved1bfReserved2bfOffBits=struct.unpack(“<2sI2Hi“bfHeader)
    print bfTypebfSizebfOffBits
    biHeader=img.read(40)
    biSizebiWidthbiHeightbiPlanesbiBitCountbiCompressionbiSizeImagebiXPelsPerMeterbiYPelsPerMterbiClrUsedbiClrImportant\
            =struct.unpack(“<3I2H6I“biHeader)
    print biSizebiWidthbiHeightbiPlanesbiBitCountbiCompressionbiSizeImagebiXPelsPerMeterbiYPelsPerMterbiClrUsedbiClrImportant
    if biBitCount<16:
        img.seek(4)
    count=0
    # while count        # rgb=struct.unpack(“<3B“img.read(3))
        # count+=1

    # encrypt
    count=0
    imgEn=open(‘fin.bmp‘‘wb‘)
    imgEn.write(bfHeader)
    imgEn.write(biHeader)
    sEncrypt=struct.pack(“%ds“%len(testStr)testStr)
    for eachAlpha in testStr:
        eachAlphaBins=bin( ord(ea

评论

共有 条评论

相关资源