合肥工业大学信息隐藏实验报告 完整代码版.docx
- 文档编号:10211559
- 上传时间:2023-02-09
- 格式:DOCX
- 页数:73
- 大小:516.05KB
合肥工业大学信息隐藏实验报告 完整代码版.docx
《合肥工业大学信息隐藏实验报告 完整代码版.docx》由会员分享,可在线阅读,更多相关《合肥工业大学信息隐藏实验报告 完整代码版.docx(73页珍藏版)》请在冰豆网上搜索。
合肥工业大学信息隐藏实验报告完整代码版
计算机与信息学院
信息隐藏实验报告
专业班级
信息安全13-1班
学生姓名及学号
马骏2013211869
课程教学班号
任课教师
郑淑丽
实验指导教师
郑淑丽
实验地点
20~20学年第学期
实验1BMP位图信息隐藏
一、实验目的
学习BMP格式文件,并编程实现对位图文件信息隐藏
二、实验要求
将TXT文件嵌入BMP文件中
三、问题描述
1、BMP位图文件的格式?
2、有哪几种方法隐藏信息,分别采用什么样的数据结构
3、随机选取如何避免“碰撞”的出现
四、算法思想
1、BMP位图文件格式
0000h~0001h2字节-------------------------bm的ASC码
0002h~0005h4字节-------------------------文件大小102718字节
0006h~0009h4字节-------------------------全为0
000Ah~000Dh4字节-------------------------偏移量118字节
000Eh~0011h4字节-------------------------位图信息块大小40字节
0012h~0015h4字节-------------------------宽450
0016h~0019h4字节-------------------------高450
001Ah~001Bh2字节-------------------------恒为01h00h
001Ch~001Dh2字节-------------------------颜色所占二进制位数值04h00h=416色位图
001Eh~0021h4字节-------------------------压缩方式=0无压缩
0022h~0025h4字节-------------------------图像数据区大小102600字节
0026h~0029h4字节-------------------------水平每米多少像素39个
002Ah~002Dh4字节-------------------------垂直每米多少像素39个
002Eh~0031h4字节-------------------------图像所用颜色数=0
0032h~0035h4字节-------------------------重要颜色数=0
0036h~0076h64字节-------------------------颜色表
0077h~1913Dh102600字节-------------------------图像数据区
2、
(1)、在图片图像数据区的一个连续的数据区采用整字节替换的方法
(2)、在图像数据的最后增加文本信息的字节
(3)、顺序选取每个文本信息字节的每一位替换图像数据区的一个连续的数据区每个字节的最后一位。
(4)、顺序选取每个文本信息字节的每一位替换图像数据区随机选取一个字节的最后一位。
(5)、首先对颜色表排序,比对顺序选取每个文本信息字节的每一位与图像数据区的一个连续的数据区每个字节的最后一位,如果不一致则不断选取相近的颜色,直到颜色序号二进制最后一位与文本信息的字节最后一位一致。
(6)首先对颜色表排序,比对顺序选取每个文本信息字节的每一位与图像数据区的随机选取的数据区每个字节的最后一位,如果不一致则不断选取相近的颜色,直到颜色序号二进制最后一位与文本信息的字节最后一位一致。
3、为了避免“碰撞”则隐藏程序和解密程序需要通过一个协议,规定一个像素点只能使用一次,即隐藏时对使用过的像素点做记录,如果像素点使用过,则产生下一个随机数。
5、模块划分
constintmax=500000;
charhuancun[max];//从文件中读入的字符
chartxthuancun[max];//txt中的字符
charwritehuancun[max];//可以写进文件中的字符串
longintwritehuancunnumber=0;//准备写入文件中的个数
longinthuancunnumber=0;//从文件中读出字符个数
longinttxthuancunnumber=0;
voidread(constchar*realfile)//读入huancun[]
voidtxtread(constchar*realfile)//读入txthuancun[]
voidwrite(constchar*yasuofile)
voiddeal8bit(charkp)//仅仅是显示二进制文件的函数
voideasyswitch()//简单的从100开始置换
voidendswitch()
intcalculate8bit(charkp,intbyte)//返回一个字符第byte位为0或1从右往左数
intgetbegin()//得到偏移量的大小下一个就是数据区的开始即begin的值
charchang8bit(charinputtxt,charbmp,intbyte)//txt的第byte被bmp第八位代替从左向右
charchangelastbyte(charbmpinput,chartxt,intbyte)//bmp字节的第8位被txt字节的第byte位代替从左向右
voidmiddleswitch()
voidhighswitch()//还没有解决碰撞问题
intcaculatechar4(charfun[4])//计算4个char的十进制大小权重132
intcaculatelastbit4(charzifu)//计算字节的最后四位代表的十进制数
charcalculateaddlast4bit(charpt,intcolornumber)//第一个字符的前四位保留后四位用这个int改成的二进制替换
classcolor16//16色颜色元
{public:
charbit4[4];
intmyposision;
intbitnumber;//charbit[4]10进制
intcolornumber;//第几个颜色0到15号颜色
};
classcolortable16//16色颜色表
{public:
colortable16()
voidsetcolortable(charfun[4],intcolornumber)
voidexchange()//排序
intgetnextcolornumber(charzifu)//得到相近颜色的颜色好
intmycolortable16number;
color16mycolortable16[17];
};
voidmiddlehidepluspower132()
voidhighhidepluspower132()
voiddiscodehighhidepluspower132()//解密函数
6、测试数据
隐藏信息:
hellomarkchalse,
thisisasecret
number6424155
pleaseputthisinancode
小刀司令
程序过程:
程序效果:
源文件
整字节替换
顺序字节末位替换
随机字节末位替换
文件末位增加字节
选择相近颜色顺序字节末位替换
选择相近颜色随机字节末位替换
源文件
整字节替换
顺序字节末位替换
随机字节末位替换
文件末位增加字节
选择相近颜色顺序字节末位替换
选择相近颜色随机字节末位替换
程序分析:
在整字节替换中得到的图片产生偏移,而直接对字节末位做替换的程序,会使像素点的颜色反差较大,如果是在颜色表选择相近颜色再对字节末位做替换效果较好,但在纯色区域表现不佳。
在图像数据区后增加字节,没有和原图产生差异,但文件的大小有增加,而且是明文容易被发现。
7、源程序(见附录)
8、总结
此次实验,使我在学习信息隐藏技术原理的基础上,进一步学习了对位图文件的编程。
更加深了我对信息隐藏的理解。
但程序中依然存在着很多不足,希望在以后的学习中加以完善。
附录:
Hidemessage1.cpp
/*基本要求:
txt嵌入bmp文件中*/
#include
#include
#include
#include
#include
usingnamespacestd;
constchar*readbmpfile="n666.bmp";
constchar*writefile="n888.bmp";
constchar*readtxtfile="n2.txt";
constchar*writetxtfile="n999.txt";
constintmax=500000;
charhuancun[max];//从文件中读入的字符
chartxthuancun[max];//txt中的字符
charwritehuancun[max];//可以写进文件中的字符串
longintwritehuancunnumber=0;//准备写入文件中的个数
longinthuancunnumber=0;//从文件中读出字符个数
longinttxthuancunnumber=0;
voidread(constchar*realfile)//读入huancun[]
{
huancunnumber=0;
ifstreaminputfile;
inputfile.open(realfile);
if(!
inputfile)
{
cout<<"nofile"< } chara; while(! inputfile.eof()) { a=inputfile.get(); huancun[huancunnumber]=a; huancunnumber++; } inputfile.close(); } voidtxtread(constchar*realfile)//读入txthuancun[] { txthuancunnumber=0; ifstreaminputfile; inputfile.open(realfile); if(! inputfile) { cout<<"nofile"< } chara; while(! inputfile.eof()) { a=inputfile.get(); txthuancun[txthuancunnumber]=a; txthuancunnumber++; } inputfile.close(); for(intx=0;x cout< cout< } voidwrite(constchar*yasuofile) { ofstreamoutputfile; outputfile.open(yasuofile); longintx; for(x=0;x { outputfile< } outputfile.close(); } voiddeal8bit(charkp)//仅仅是显示二进制文件的函数 { charn1,n2,n3,n4,n5,n6,n7,n8; charkk; _asm { movn1,10000000b; movn2,01000000b; movn3,00100000b; movn4,00010000b; movn5,00001000b; movn6,00000100b; movn7,00000010b; movn8,00000001b; } kk=kp; _asm { andkk,10000000b; } if(kk==n1) { cout<<"1"; } elsecout<<"0"; kk=kp; _asm { andkk,01000000b; } if(kk==n2) { cout<<"1"; } elsecout<<"0"; kk=kp; _asm { andkk,00100000b; } if(kk==n3) { cout<<"1"; } elsecout<<"0"; kk=kp; _asm { andkk,00010000b; } if(kk==n4) { cout<<"1"; } elsecout<<"0"; kk=kp; _asm { andkk,00001000b; } if(kk==n5) { cout<<"1"; } elsecout<<"0"; kk=kp; _asm { andkk,00000100b; } if(kk==n6) { cout<<"1"; } elsecout<<"0"; kk=kp; _asm { andkk,00000010b; } if(kk==n7) { cout<<"1"; } elsecout<<"0"; kk=kp; _asm { andkk,00000001b; } if(kk==n8) { cout<<"1"; } elsecout<<"0"; }; voideasyswitch()//简单的从100开始置换 { intx; cout< cout<<"------------------------------easyswitchprogram-------------------------------"< writehuancunnumber=huancunnumber; for(x=0;x writehuancun[x]=huancun[x]; for(x=0;x writehuancun[x+1500]=txthuancun[x]; } voidendswitch() { intend=huancunnumber,x;//最后就指数据区的最后 cout<<"------------------------------endswitchprogram-------------------------------"< writehuancunnumber=huancunnumber; for(x=0;x writehuancun[x]=huancun[x]; for(x=0;x { writehuancun[writehuancunnumber]=txthuancun[x]; writehuancunnumber++; } } intcalculate8bit(charkp,intbyte)//返回一个字符第byte位为0或1从右往左数 { charn1,n2,n3,n4,n5,n6,n7,n8; charkk; _asm { movn1,10000000b; movn2,01000000b; movn3,00100000b; movn4,00010000b; movn5,00001000b; movn6,00000100b; movn7,00000010b; movn8,00000001b; } if(byte==8) { kk=kp; _asm { andkk,10000000b; } if(kk==n1) { //cout<<"1"; return1; } else { //cout<<"0"; return0; } } if(byte==7) { kk=kp; _asm { andkk,01000000b; } if(kk==n2) { //cout<<"1"; return1; } else { //cout<<"0"; return0; } } if(byte==6) { kk=kp; _asm { andkk,00100000b; } if(kk==n3) { //cout<<"1"; return1; } else { //cout<<"0"; return0; } } if(byte==5) { kk=kp; _asm { andkk,00010000b; } if(kk==n4) { //cout<<"1"; return1; } else { //cout<<"0"; return0; } } if(byte==4) { kk=kp; _asm { andkk,00001000b; } if(kk==n5) { //cout<<"1"; return1; } else { //cout<<"0"; return0; } } if(byte==3) { kk=kp; _asm { andkk,00000100b; } if(kk==n6) { //cout<<"1"; return1; } else { //cout<<"0"; return0; } } if(byte==2) { kk=kp; _asm { andkk,00000010b; } if(kk==n7) { //cout<<"1"; return1; } else { //cout<<"0"; return0; } } if(byte==1) { kk=kp; _asm { andkk,00000001b; } if(kk==n8) { //cout<<"1"; return1; } else { //cout<<"0"; return0; } } } intgetbegin()//得到偏移量的大小下一个就是数据区的开始即begin的值 { intpianyi=0,x; charpianyi1=huancun[10];//从第11个字节开始的四个字节 charpianyi2=huancun[11]; charpianyi3=huancun[12]; charpianyi4=huancun[13]; for(x=0;x<8;x++) { if(calculate8bit(pianyi1,x+1))//一定要注意: 直观上的第8位实际上只是数字的最低位第几位这个是从左往右还是从右往左要一致 { intkk=1;//这里按从右往左算没有第0位这个说法所以还要x+1 for(intt=0;t kk=kk*2; pianyi+=kk; } } for(x=0;x<8;x++) { if(calculate8bit(pianyi2,x+1))//这里按从右往左算没有第0位这个说法所以还要x+1 { intkk=1; for(intt=0;t kk=kk*2; pianyi+=kk; } } for(x=0;x<8;x++) { if(calculate8bit(pianyi3,x+1))//这里按从右往左算没有第0位这个说法所以还要x+1 { intkk=1; for(intt=0;t kk=kk*2; pianyi+=kk; } } for(x=0;x<8;x++) { if(calculate8bit(pianyi4,x+1))//这里按从右往左算没有第0位这个说法所以还要x+1 { intkk=1; for(intt=0;t kk=kk*2; pianyi+=kk; } } returnpianyi; } charchang8bit(charinputtxt,charbmp,intbyte)//txt的第byte被bmp第八位代替从左向右 { chartxt=inputtxt; charn1,n2,n3,n4,n5,n6,n7,n8,ntrue,nfalse; _asm { movn1,10000000b; movn2,0
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 合肥工业大学信息隐藏实验报告 完整代码版 合肥 工业大学 信息 隐藏 实验 报告 完整 代码