相关文章推荐
豪气的消防车  ·  医学信息学中心_临床医学高等研究院·  5 月前    · 
深情的椅子  ·  QQ音乐-千万正版音乐海量无损曲库新歌热歌天 ...·  1 年前    · 
兴奋的熊猫  ·  船建学院关于2019届研究生办理离校工作的通 ...·  1 年前    · 
刚分手的鼠标  ·  叉鱼少女 - 萌娘百科 万物皆可萌的百科全书·  2 年前    · 
安静的打火机  ·  如何评价《斗罗大陆4终极斗罗》的结局? - 知乎·  2 年前    · 
Code  ›  通过jpg图片隐藏文件开发者社区
隐藏文件 jpg
https://cloud.tencent.com/developer/article/1525474
失眠的荒野
2 年前
作者头像
机械视角
0 篇文章

通过jpg图片隐藏文件

前往专栏
腾讯云
开发者社区
文档 意见反馈 控制台
首页
学习
活动
专区
工具
TVP
文章/答案/技术大牛
发布
首页
学习
活动
专区
工具
TVP
返回腾讯云官网
社区首页 > 专栏 > Tensorbytes > 通过jpg图片隐藏文件

通过jpg图片隐藏文件

作者头像
机械视角
发布 于 2019-10-23 11:16:17
810 0
发布 于 2019-10-23 11:16:17
举报

比如我们现在有一个视频 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]
 
推荐文章
豪气的消防车  ·  医学信息学中心_临床医学高等研究院
5 月前
深情的椅子  ·  QQ音乐-千万正版音乐海量无损曲库新歌热歌天天畅听的高品质音乐平台!
1 年前
兴奋的熊猫  ·  船建学院关于2019届研究生办理离校工作的通知-上海交通大学船舶海洋与建筑工程学院
1 年前
刚分手的鼠标  ·  叉鱼少女 - 萌娘百科 万物皆可萌的百科全书
2 年前
安静的打火机  ·  如何评价《斗罗大陆4终极斗罗》的结局? - 知乎
2 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号