数字水印的嵌入

代码是用matlab写的

基于空域的最低有效位替换算法(LSBR)#

采用LSBR,将秘密分别顺序隐藏到rgb图像的r、g、b各个层,将秘密的每一位嵌入到载体各像素的最低的一位
载体

秘密

含有秘密的载体

提取的秘密

隐藏代码:

Copy
cover=imread('C:\Users\Desktop\c.bmp'); secret=imread('C:\Users\Desktop\s.bmp'); coverr=cover(:,:,1); coverg=cover(:,:,2); coverb=cover(:,:,3); [p,q]=size(secret); p=uint32(p); q=uint32(q); for i=1:p for j=1:q switch(mod(j,3)) case 1 coverr(i,j)=bitor(bitshift (bitshift(coverr(i,j),-1),1) ,uint8(secret(i,j))); case 2 coverg(i,j)=bitor(bitshift (bitshift(coverg(i,j),-1),1) ,uint8(secret(i,j))); case 0 coverb(i,j)=bitor(bitshift (bitshift(coverb(i,j),-1),1) ,uint8(secret(i,j))); end end end imwrite(cat(3,coverr,coverg,coverb),'C:\Users\Desktop\ste.bmp');

提取代码:

Copy
ste=imread('C:\Users\Desktop\ste.bmp'); ster=ste(:,:,1); steg=ste(:,:,2); steb=ste(:,:,3); s=[256,256]; for i=1:256 for j=1:256 switch(mod(j,3)) case 1 s(i,j)=bitshift(bitshift(ster(i,j),7),-7); case 2 s(i,j)=bitshift(bitshift(steg(i,j),7),-7); case 0 s(i,j)=bitshift(bitshift(steb(i,j),7),-7); end end end imwrite(s,'C:\Users\Desktop\secret.bmp');

Jsteg算法的实现#

在JPEG图像的DCT系数上进行LSB替换,实现秘密信息的嵌入
Jpg的图像相比bmp隐写容量更小,开始选的256*256的图像就不能完全嵌入。在量化后的dct系数上嵌入时要注意dc系数不嵌,0与1也不嵌。
载体

秘密

含有秘密的载体

提取的秘密

嵌入代码:

Copy
cover=jpeg_read('C:\Users\Desktop\c.jpg'); secret=imread('C:\Users\Desktop\t.bmp'); secret1=reshape(secret,1,[]); [p,q]=size(cover.coef_arrays{1,1}); p=uint32(p); q=uint32(q); %cover1=reshape(cover.coef_arrays{1,1},1,[]); %hist(cover1,20); num=1; for i=1:p for j=1:q if(num==64*64+1) break; else if ( mod(i,8) == 1 && mod(j,8) == 1) continue; elseif (cover.coef_arrays{1,1}(i,j) == 0) continue; elseif(cover.coef_arrays{1,1}(i,j) == 1) continue; else cover.coef_arrays{1,1}(i,j) = cover.coef_arrays{1,1}(i,j) - mod(cover.coef_arrays{1,1}(i,j), 2) + secret1(num); num=num+1; end end end end jpeg_write(cover,'C:\Users\Desktop\ste.jpg');

提取代码:

Copy
cover=jpeg_read('C:\Users\Desktop\ste.jpg'); [p,q]=size(cover.coef_arrays{1,1}); %ste=reshape(cover.coef_arrays{1,1},1,[]); %hist(ste,20); p=uint32(p); q=uint32(q); num=1; for i=1:p for j=1:q if(num==64*64+1) break; else if ( mod(i,8) == 1 && mod(j,8) == 1) continue; elseif (cover.coef_arrays{1,1}(i,j) == 0) continue; elseif(cover.coef_arrays{1,1}(i,j) == 1) continue; else secret(num) = mod(cover.coef_arrays{1,1}(i,j), 2); num=num+1; end end end end secret1=reshape(secret,[64,64]); imwrite(secret1,'C:\Users\Desktop\secretste.bmp');

隐写分析方法—卡方统计分析#

在上一步jsteg嵌入和提取代码中分别加入下面代码即可:
cover1=reshape(cover.coef_arrays{1,1},1,[]);
hist(cover1,20);
ste=reshape(cover.coef_arrays{1,1},1,[]);
hist(ste,20);
因为在嵌入时选择的图像过小,卡方分析可能效果不明显。但当时选大了,又嵌不进去。
对载体的统计直方图:

对含有秘密的载体的统计直方图:

posted @   启林O_o  阅读(581)  评论(0编辑  收藏  举报
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
点击右上角即可分享
微信分享提示
CONTENTS