通过jpg图片隐藏文件

比如我们现在有一个视频Video.mkv,我们想隐藏它,那么我们可以找一张背景图片谣言.jpg, 把他们放在同一目录下:

Video.mkv打包成压缩包Video.rar,为什么要打包呢? 因为这是为后面解压服务得~

在该目录下编写bat文件:

copy  /b  谣言.jpg+Video.rar 谣言2.jpg

双击运行压缩.bat,我们可以看到目录下生成了一张谣言2.jpg的图片,看看大小,整合等于压缩包文件和图片文件总和~

最后,那如何还原原文件呢?? 很简单,直接将文件后缀改为rar压缩包文件进行解压就可以了,因为rar解压有个专属的开始位置,解压程序会读到开始位置的标识符才执行解压程序,应该前面的jpg二进制会被忽略。

当然如果你希望获得更强大的加密可以自己编写加密解密策略。

附上Python代码: github地址 加密

#coding:utf-8

import click
import random

@click.command()
@click.option('--background', prompt=True, help='输入用于隐藏的背景图片文件.')
@click.option('--encryptfile', prompt=True, help='输入需要加密的文件.')
def encryptfile(background, encryptfile):
    seed = random.randint(1024, 2048)
    seeds = []
    for i in range(seed):
        seeds.append(random.randint(1, 128))
    confusion = bytes(seeds)

    with open(background, 'rb') as fr_bg:
        bg_body = fr_bg.read()

    with open(encryptfile, 'rb') as fr_enc:
        enc_body = fr_enc.read()

    confusion_bytes_index = random.randint(1, len(enc_body)//2)

    objectfile = "encry_%d_%d_%d_"%(len(bg_body), len(confusion), confusion_bytes_index) + background
    data = bg_body + confusion + enc_body[confusion_bytes_index:] + confusion + enc_body[:confusion_bytes_index]

    print(len(bg_body)+len(confusion))
    print(len(enc_body[confusion_bytes_index:]))
    print(len(enc_body[:confusion_bytes_index]))
    print(len(bg_body)+2*len(confusion)+len(enc_body[confusion_bytes_index:]))
    print(len(data))

    with open(objectfile, "wb") as fw_obf:
        fw_obf.write(data)

if __name__ == "__main__":
    encryptfile()

解密:

#coding:utf-8

import click

@click.command()
@click.option('--inputfile', prompt=True, help='输入文件名及路径.')
@click.option('--outputfile', prompt=True, help='输出文件名及路径.')
def decryptFile(inputfile, outputfile):
    decryptfile = outputfile
    encryptfile = inputfile

    encrypt = encryptfile.split("_")
    bg_length, confuse_length, confusion_bytes_index = int(encrypt[1]), int(encrypt[2]), int(encrypt[3])
    headerindex = bg_length + confuse_length

    with open(decryptfile, "wb") as fw:
        with open(encryptfile, "rb") as fr:
            data = fr.read()
            frist_data_num = len(data)-(headerindex + confusion_bytes_index + confuse_length)
            frist_data = data[-confusion_bytes_index:]
            second_data = data[headerindex:headerindex+frist_data_num]
            print(headerindex + confusion_bytes_index + confuse_length)
            print(len(frist_data),len(second_data))
            fw.write(frist_data+second_data)

if __name__ == "__main__":
    decryptFile()

转载于:https://my.oschina.net/Kanonpy/blog/3028513

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值