求一个信息隐藏大佬帮忙分析一哈这个代码?

weixin_43613566 2020-05-13 02:05:47
加精
clc
clear all;
close all;

%messagename=input('Enter message file name with extension:','s');
covername='1.jpg';
messagename='2.jpg';
cover=imread(covername);


sz=size(cover);
rows=sz(1,1);
cols=sz(1,2);
colors=max(max(cover));

fd=fopen(messagename,'r');%fd是通过fopen函数打开文件后得到的一个整型的文件标识
message=fgetl(fd);%fgetl从这个文件中读取一行数据并丢弃其中的换行符。如果读取成功
%message容纳了读取到的文本字符串,如果遇到文件末尾的结束标志(EOF),则函数返回-1,即message值为-1
%message='hello world';
messagelength=length(message);

%figure(1),imshow(cover);title('OriginalImage(CoverImage)');
message=uint8(message);
coverzero = cover;

%cover=rgb2gray(cover);

blocksize=8;
quant_multiple=1;
DCT_quantizer=...
[16 11 10 16 24 40 51 61;...
12 12 14 19 26 58 60 55;...
14 13 16 24 40 57 6 956;...
14 17 22 29 51 87 80 62;...
18 22 37 56 68 109 103 77;...
24 35 55 64 81 104 113 92;...
49 64 78 87 103 121 120 101;...
72 92 95 98 112 100 103 99];

figure(2);imshow(coverzero);
title('OriginalImage');

pad_cols=(1-(cols/blocksize-floor(cols/blocksize)))*blocksize; %floor向下取整
if pad_cols==blocksize,pad_cols=0;
end
pad_rows=(1-(rows/blocksize-floor(rows/blocksize)))*blocksize;
if pad_rows==blocksize,pad_rows=0;
end

for extra_cols=1:pad_cols
coverzero(1:rows,cols+extra_cols)=coverzero(1:rows,cols);
end
cols=cols+pad_cols;%coverzeroisnowpad_colswider
for extra_rows=1:pad_rows
coverzero(rows+extra_rows,1:cols)=coverzero(rows,1:cols);
end

rows= rows+pad_rows;

for row=1:blocksize:rows %i=1;i<rows;i+blocksize;
for col= 1:blocksize:cols
DCT_matrix=coverzero(row:row+blocksize-1,col:col+blocksize-1);
DCT_matrix=dct2(DCT_matrix); %quantizeit(levelsstoredinDCT_quantizermatrix):
%DCT_matrix=floor(DCT_matrix...
% ./(DCT_quantizer(1:blocksize,1:blocksize)*quant_multiple)+0.5);
DCT_matrix_test=(DCT_matrix./(DCT_quantizer(1:blocksize,1:blocksize)* quant_multiple));
DCT_matrix=round(DCT_matrix./(DCT_quantizer(1:blocksize,1:blocksize)* quant_multiple));%round四舍五入
%DCT_matrix=round(DCT_matrix);
%placeitintothecompressed-imagematrix:
%./是相同位置的数进行相除
jpeg_img_test(row:row+blocksize-1,col:col+blocksize-1)=DCT_matrix_test;
jpeg_img(row:row+blocksize-1,col:col+blocksize-1)=DCT_matrix;
end
end

%DCT figures
figure(3);hist(jpeg_img);
figure(4);imshow(jpeg_img);

bitlength=1;
orijpeg=jpeg_img;
for i=1:messagelength
for imbed=1:8
messageshift=bitshift(message(i),8-imbed);%左移8-imbed
showmess=uint8(messageshift);
showmess=bitshift(showmess,-7);%左侧加7个0
messagebit(bitlength)=showmess;
bitlength=bitlength+1;
end
end

%embedding JSteg
i=1;
for row=1:rows
for col=1:cols
x=jpeg_img(row,col);
if (x~=0) && (x~=1)
r=mod(x,2);
if r==0
if messagebit(i)==1
x=x+1;
end
else
if messagebit(i)==0
x=x-1;
end
end
i=i+1;
end
jpeg_img(row,col)=x;
if i==bitlength
break;
end
end
if i==bitlength
break;
end
end
%jsteg hist
figure(5);hist(jpeg_img);
orijpeg=orijpeg-jpeg_img;
%Reconstructing Image

recon_img= coverzero-coverzero;

for row=1:blocksize:rows
for col=1:blocksize:cols
IDCT_matrix=jpeg_img(row:row+blocksize-1,col:col+blocksize-1);
IDCT_matrix=round(idct2(IDCT_matrix.*(DCT_quantizer(1:blocksize,1:blocksize)*quant_multiple)));
recon_img(row:row+blocksize-1,col:col+blocksize-1)=IDCT_matrix;
end
end

endrows=rows-pad_rows;
cols=cols-pad_cols;
recon_img=recon_img(1:rows,1:cols);

figure(6);imshow(recon_img);

pad_cols=(1-(cols/blocksize-floor(cols/blocksize)))*blocksize;
if pad_cols==blocksize,pad_cols=0;end
pad_rows=(1-(rows/blocksize-floor(rows/blocksize)))*blocksize;
if pad_rows==blocksize,pad_rows=0;end

for extra_cols=1:pad_cols
recon_img(1:rows,cols+extra_cols)=recon_img(1:rows,cols);
end

cols=cols + pad_cols;

for extra_rows=1:pad_rows
recon_img(rows+extra_rows,1:cols)=recon_img(rows,1:cols);
end

rows=rows+pad_rows;

%coverzeroisnowpad_rowstaller

jpeg_img=jpeg_img-jpeg_img;

for row=1:blocksize:rows
for col=1:blocksize:cols
DCT_matrix=recon_img(row:row+blocksize-1,col:col+blocksize-1);
DCT_matrix=dct2(DCT_matrix); %quantizeit(levelsstoredinDCT_quantizermatrix):%DCT_matrix=floor(DCT_matrix...% ./(DCT_quantizer(1:blocksize,1:blocksize)* quant_multiple)+0.5);
DCT_matrix=round(DCT_matrix./(DCT_quantizer(1:blocksize,1:blocksize)* quant_multiple));
%DCT_matrix=round(DCT_matrix);
%placeitintothecompressed-imagematrix:jpeg_img(row:row+blocksize-1,col:col+blocksize-1)=DCT_matrix;
jpeg_img(row:row+blocksize-1,col:col+blocksize-1)=DCT_matrix;
end
end

stego=jpeg_img;

figure(7);imshow(stego);
figure(8);hist(stego);

stegoindex=1;
imbed=1;
messagechar=0;
messageindex=1;
for row=1:rows
for col=1:cols
stegomessage = stego(row,col);
if (stegomessage~=0) && (stegomessage~=1)
r=mod(stegomessage,2);
if(r==0)
showmess=0;
else
showmess=1;
end

showmess=uint8(showmess);
showmess=bitshift(showmess,(imbed-1));
messagechar=uint8(messagechar+showmess);

stegoindex = stegoindex + 1;

imbed = imbed +1;
if(imbed==9)
messagestring(messageindex)=messagechar;
messageindex=messageindex+1;
messagechar=0;
imbed=1;
end
end
if(stegoindex==messagelength*8+1)
break;
end
end
if(stegoindex==messagelength*8+1)
break;
end
end

disp(messagestring);
...全文
20546 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_28697193 2021-03-08
  • 打赏
  • 举报
回复
学习学习学习
m0_55087227 2021-02-01
  • 打赏
  • 举报
回复
。。。。。。。。。。。。。。。。
牙膏皮哥哥 2020-07-13
  • 打赏
  • 举报
回复
DCT相关隐藏设置
左手の明天 2020-06-16
  • 打赏
  • 举报
回复
DCT图形嵌入隐藏
schlafenhamster 2020-06-16
  • 打赏
  • 举报
回复
搜索 “DCT隐藏信息”
Genji520 2020-06-01
  • 打赏
  • 举报
回复
.....................
liuyanbinll 2020-05-21
  • 打赏
  • 举报
回复
说分析一下,又没说要做什么?实现什么东西,遇到什么困难,表述不明确。
weixin_43613566 2020-05-14
  • 打赏
  • 举报
回复
说是Jsteg隐写,但是看起来好像又不是
clever101 2020-05-13
  • 打赏
  • 举报
回复
这个代码是干嘛的

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧