0


[HUST]多媒体安全实验:图像隐写JSTEG,F4,F5的实现

引言:在变换域进行隐写相比于直接隐写在图像的像素值信息中的方法,具有更好的鲁棒性,也更难从肉眼上被察觉。

本次实验使用MATLAB进行编写,由于在此之前我基本没有使用过MATLAB进行变成,因而可能会有很多不雅观的地方,希望各位能多多包容。而且因为本人水平有限,所以还望大家包容指正。

1.JSTEG

  1. 相对于直接嵌入灰度而言,选择使用DCT隐写的一大原因有是因为DCT系数表示的是各种图像变化的程度,因而,从理论上而言,一张自然图像的DCT图像应该呈现一种山峰形的变化趋势。以0对称,左右逐渐下降的形状。

JSTEG的隐写方法是直接更改DCT绝对值大于1的系数的最低位,将信息通过这种方式嵌入图像之中。在解析时跳过绝对值小于等于1的DCT系数,便可以直接读出隐写的信息。

这种方法显然足够简单,而缺点是JSTEG由于直接更改了最低位,因而会产生值对现象,打个比方,从理论上来说,1出现的频次应该会比2高上很多,但是如果选择了JSTEG方法的话,就会发现,1和2的出现频次会随着嵌入的信息变多,而越来越接近,因而如果分析者发现了这种值对现象,便不难发现了这些图像被处理过。

原图像DCT系数直方图:

而嵌入之后的图像可以看到明显的值对现象:

不难看出之间的差距。

F4嵌入:

  1. 对于F4而言,他将用正奇数和负偶数代表秘密消息1、负奇数和正偶数代表秘密消息0。一旦不一致则将绝对值-1.
  2. 这种做法的优点是相较于JSTEG而言,不会发生值对现象(毕竟他相当于全方位的平移)。

F5嵌入:

  1. F5F4的一种直接改进,对于F5而言,他可以有很多有很多形式,具体而言,他可以用2^(n+1)-1位来表示n个比特信息,对于n=1而言,第一个比特信息是b1=a1a2,b2=a2a3,那么,无论何种情况,你只需要在3DCT系数中修改一个,即可以表示两个字符,这样子的好处是大大增加了DCT嵌入效率,坏处是对于同样要嵌入2个比特信息,正常只需要2DCT系数,而在这里则需要3个,这就是所谓的有得必有失吧。

JSTEG代码实现:

  1. 首先去这个网站下载:http://dde.binghamton.edu/download/nsf5simulator/

将该文件拖入你的工作目录中即可正常运行(也就是当前脚本的文件夹)

  1. 你需要一个原始的图像,并且将它命名为cover.jpg(当然你也可以跟随代码进行改动)
  2. 你修改后的图像是stego.jpg
  3. 代码实现:
  1. %%% setup
  2. COVER = 'cover.jpg'; % cover image (grayscale JPEG image)
  3. STEGO = 'stego.jpg'; % resulting stego image that will be created
  4. SEED=99;
  5. myInformation='Hello,Matlab'
  6. msgBin = de2bi(int8(myInformation),8,'left-msb');
  7. len = size(msgBin,1).*size(msgBin,2);
  8. myInfo = reshape(double(msgBin).',len,1).';
  9. tic;
  10. [nzAC] = nsf5_simulation(COVER,STEGO,myInfo);
  11. T = toc;
  12. fprintf('-----\n');
  13. fprintf('nsF5 simulation finished\n');
  14. fprintf('cover image: %s\n',COVER);
  15. fprintf('stego image: %s\n',STEGO);
  16. fprintf('PRNG seed: %i\n',SEED);
  17. %fprintf('relative payload: %.4f bpac\n',ALPHA);
  18. fprintf('number of nzACs in cover: %i\n',nzAC);
  19. fprintf('elapsed time: %.4f seconds\n',T);
  20. function [AC]=nsf5_simulation(COVER,STEGO,message)
  21. try
  22. jobj=jpeg_read(COVER);
  23. DCT=jobj.coef_arrays{1}
  24. catch
  25. error('ERROR (problem with the cover image)');
  26. end
  27. AC=numel(DCT)-numel(DCT(1:8:end,1:8:end));%计算AC系数数量,每个DCT分块是8*8
  28. if(length(message)>AC)
  29. error('ERROR (too long message)');
  30. end
  31. %打乱Changeable的排列顺序
  32. idD=1;
  33. len=length(message);
  34. for id=1:len
  35. while(abs(DCT(idD))<=1)
  36. message(id);
  37. DCT(idD)=0;
  38. idD=idD+1;
  39. if(idD>=AC)
  40. break;
  41. end
  42. end
  43. if(DCT(idD)<0)
  44. message(id)
  45. DCT(idD)
  46. if(message(id)==mod(DCT(idD),2))
  47. if(mod(DCT(idD),2)==1)
  48. DCT(idD)=DCT(idD)-sign(DCT(idD));
  49. else
  50. DCT(idD)=DCT(idD)+sign(DCT(idD));
  51. end
  52. end
  53. else
  54. message(id)
  55. DCT(idD)
  56. if(message(id)~=mod(DCT(idD),2))
  57. if(mod(DCT(idD),2)==1)
  58. DCT(idD)=DCT(idD)-sign(DCT(idD));
  59. else
  60. DCT(idD)=DCT(idD)+sign(DCT(idD));
  61. end
  62. end
  63. end
  64. idD=idD+1;
  65. end
  66. try
  67. jobj.coef_arrays{1}=DCT;
  68. jobj.optimize_coding=1;
  69. jpeg_write(jobj,STEGO);
  70. catch
  71. error('ERROR (problem with saving the stego image)')
  72. end
  73. end
  74. function res=invH(y)
  75. to_minimize=@(x) (H(x)-y)^2;
  76. res=fminbnd(to_minimize,eps,0.5-eps);
  77. end
  78. function res=H(x)
  79. res=-x*log2(x)-(1-x)*log2(1-x);
  80. end

F4代码实现:

  1. %%% setup
  2. COVER = 'cover.jpg'; % cover image (grayscale JPEG image)
  3. STEGO = 'stego.jpg'; % resulting stego image that will be created
  4. SEED=99;
  5. output=fopen("test.txt","w");
  6. myInformation='SEEYOUINHE'
  7. msgBin = de2bi(int8(myInformation),8,'left-msb');
  8. len = size(msgBin,1).*size(msgBin,2);
  9. myInfo = reshape(double(msgBin).',len,1).';
  10. tic;
  11. [nzAC] = nsf5_simulationF4(COVER,STEGO,myInfo);
  12. T = toc;
  13. fprintf('-----\n');
  14. fprintf('nsF5 simulation finished\n');
  15. fprintf('cover image: %s\n',COVER);
  16. fprintf('stego image: %s\n',STEGO);
  17. fprintf('PRNG seed: %i\n',SEED);
  18. %fprintf('relative payload: %.4f bpac\n',ALPHA);
  19. fprintf('number of nzACs in cover: %i\n',nzAC);
  20. fprintf('elapsed time: %.4f seconds\n',T);
  21. function [AC]=nsf5_simulationF4(COVER,STEGO,message)
  22. output=fopen("test.txt","w");
  23. try
  24. jobj=jpeg_read(COVER);
  25. DCT=jobj.coef_arrays{1}
  26. catch
  27. error('ERROR (problem with the cover image)');
  28. end
  29. AC=numel(DCT)-numel(DCT(1:8:end,1:8:end));%计算AC系数数量,每个DCT分块是8*8
  30. if(length(message)>AC)
  31. error('ERROR (too long message)');
  32. end
  33. %打乱Changeable的排列顺序
  34. idD=1;
  35. len=length(message)
  36. for id=1:len
  37. while(abs(DCT(idD))<=1)
  38. if(DCT(idD)<0 && message(id)==1)
  39. DCT(idD)=0
  40. elseif(DCT(idD)>0 && message(id)==0)
  41. DCT(idD)=0
  42. elseif(DCT(idD)~=0)
  43. message(id)
  44. DCT(idD)
  45. break
  46. else
  47. end
  48. idD=idD+1;
  49. if(idD>=AC)
  50. break;
  51. end
  52. end
  53. if(DCT(idD)<=-1)
  54. if(message(id)==mod(DCT(idD),2))
  55. fprintf("%d",id);
  56. message(id)
  57. sign(DCT(idD));
  58. DCT(idD)=DCT(idD)+1;
  59. DCT(idD)
  60. idD=idD+1;
  61. continue
  62. end
  63. message(id)
  64. DCT(idD)
  65. fprintf(output,"%d\n",DCT(idD));
  66. idD=idD+1;
  67. continue
  68. end
  69. if(DCT(idD)>=1)
  70. if(message(id)~=mod(DCT(idD),2))
  71. message(id)
  72. sign(DCT(idD));
  73. DCT(idD)=DCT(idD)-1;
  74. DCT(idD)
  75. idD=idD+1;
  76. continue;
  77. end
  78. message(id)
  79. DCT(idD)
  80. fprintf(output,"%d\n",DCT(idD));
  81. idD=idD+1;
  82. continue
  83. end
  84. end
  85. try
  86. jobj.coef_arrays{1}=DCT;
  87. jobj.optimize_coding=1;
  88. jpeg_write(jobj,STEGO);
  89. catch
  90. error('ERROR (problem with saving the stego image)')
  91. end
  92. end
  93. function res=invH(y)
  94. to_minimize=@(x) (H(x)-y)^2;
  95. res=fminbnd(to_minimize,eps,0.5-eps);
  96. end
  97. function res=H(x)
  98. res=-x*log2(x)-(1-x)*log2(1-x);
  99. end

F5代码实现:

  1. %%% setup
  2. COVER = 'cover.jpg'; % cover image (grayscale JPEG image)
  3. STEGO = 'stego.jpg'; % resulting stego image that will be created
  4. SEED=99;
  5. output=fopen("test.txt","w");
  6. myInformation='HELLOWOLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824HELLOWORLDU201911824';
  7. msgBin = de2bi(int8(myInformation),8,'left-msb');
  8. len = size(msgBin,1).*size(msgBin,2);
  9. myInfo = reshape(double(msgBin).',len,1).';
  10. Extend=2-mod(len,2)
  11. for extend=1:Extend
  12. myInfo(len+extend)=0
  13. end
  14. [nzAC] = nsf5_simulationF5(COVER,STEGO,myInfo);
  15. T = toc;
  16. fprintf('-----\n');
  17. fprintf('nsF5 simulation finished\n');
  18. fprintf('cover image: %s\n',COVER);
  19. fprintf('stego image: %s\n',STEGO);
  20. fprintf('PRNG seed: %i\n',SEED);
  21. %fprintf('relative payload: %.4f bpac\n',ALPHA);
  22. fprintf('number of nzACs in cover: %i\n',nzAC);
  23. fprintf('elapsed time: %.4f seconds\n',T);
  24. function [mba1,mba2,mba3]=my_AND(a1,a2,a3,b1,b2)
  25. if(a1>0)
  26. m1=mod(a1,2);
  27. else
  28. ma1=a1*-1+1;
  29. m1=mod(ma1,2);
  30. end
  31. if(a2>0)
  32. m2=mod(a2,2);
  33. else
  34. ma2=a2*-1+1;
  35. m2=mod(ma2,2);
  36. end
  37. if(a3>0)
  38. m3=mod(a3,2);
  39. else
  40. ma3=a3*-1+1;
  41. m3=mod(ma3,2);
  42. end
  43. mb1=mod(m1+m2,2);
  44. mb2=mod(m2+m3,2);
  45. if(mb1~=b1&&mb2==b2)
  46. mba2=a2;
  47. mba3=a3;
  48. mba1=a1-sign(a1);
  49. elseif(mb1==b1&&mb2~=b2)
  50. mba3=a3-sign(a3);
  51. mba1=a1;
  52. mba2=a2;
  53. elseif(mb1~=b1&&mb2~=b2)
  54. mba2=a2-sign(a2);
  55. mba1=a1;
  56. mba3=a3;
  57. else
  58. mba1=a1;
  59. mba2=a2;
  60. mba3=a3;
  61. end
  62. end
  63. function [AC]=nsf5_simulationF5(COVER,STEGO,message)
  64. output=fopen("test.txt","w");
  65. try
  66. jobj=jpeg_read(COVER);
  67. DCT=jobj.coef_arrays{1}
  68. catch
  69. error('ERROR (problem with the cover image)');
  70. end
  71. AC=numel(DCT)-numel(DCT(1:8:end,1:8:end));%计算AC系数数量,每个DCT分块是8*8
  72. AC=AC/(3/2);
  73. if(length(message)>AC)
  74. error('ERROR (too long message)');
  75. end
  76. idD=1;
  77. len=length(message)
  78. for id=1:2:len
  79. place1=0;
  80. place2=0;
  81. place3=0;
  82. value1=0;
  83. value2=0;
  84. value3=0;
  85. Value1=0;
  86. Value2=0;
  87. Value3=0;
  88. a1=message(id);
  89. a2=message(id+1);
  90. while(abs(DCT(idD))<=0)
  91. DCT(idD)=0;
  92. idD=idD+1;
  93. if(idD>=AC)
  94. break;
  95. end
  96. end
  97. place1=idD;
  98. value1=DCT(idD);
  99. idD=idD+1;
  100. while(abs(DCT(idD))<=0)
  101. DCT(idD)=0;
  102. idD=idD+1;
  103. if(idD>=AC)
  104. break;
  105. end
  106. end
  107. place2=idD;
  108. value2=DCT(idD);
  109. idD=idD+1;
  110. while(abs(DCT(idD))<=0)
  111. DCT(idD)=0;
  112. idD=idD+1;
  113. if(idD>=AC)
  114. break;
  115. end
  116. end
  117. place3=idD;
  118. value3=DCT(idD);
  119. idD=idD+1;
  120. [Value1,Value2,Value3]=my_AND(value1,value2,value3,a1,a2);
  121. while(Value1==0||Value2==0||Value3==0)
  122. if(Value1==0&&Value2~=0&&Value3~=0)
  123. DCT(place1)=0;
  124. value1=value2;
  125. place1=place2;
  126. place2=place3;
  127. value2=value3;
  128. while(abs(DCT(idD))<=0)
  129. DCT(idD)=0;
  130. idD=idD+1;
  131. if(idD>=AC)
  132. break;
  133. end
  134. end
  135. value3=DCT(idD)
  136. place3=idD
  137. idD=idD+1;
  138. [Value1,Value2,Value3]=my_AND(value1,value2,value3,a1,a2);
  139. elseif(Value1~=0&&Value2==0&&Value3~=0)
  140. DCT(place2)=0;
  141. place2=place3;
  142. value2=value3;
  143. while(abs(DCT(idD))<=0)
  144. DCT(idD)=0;
  145. idD=idD+1;
  146. if(idD>=AC)
  147. break;
  148. end
  149. end
  150. value3=DCT(idD);
  151. place3=idD;
  152. idD=idD+1;
  153. [Value1,Value2,Value3]=my_AND(value1,value2,value3,a1,a2);
  154. elseif(Value1~=0&&Value2~=0&&Value3==0)
  155. DCT(place3)=0;
  156. while(abs(DCT(idD))<=0)
  157. DCT(idD)=0;
  158. idD=idD+1;
  159. if(idD>=AC)
  160. break;
  161. end
  162. end
  163. value3=DCT(idD)
  164. place3=idD
  165. idD=idD+1;
  166. [Value1,Value2,Value3]=my_AND(value1,value2,value3,a1,a2);
  167. elseif(Value1==0&&Value2==0&&Value3~=0)
  168. DCT(place1)=0;
  169. DCT(place2)=0;
  170. value1=value3
  171. place1=place3
  172. while(abs(DCT(idD))<=0)
  173. DCT(idD)=0;
  174. idD=idD+1;
  175. if(idD>=AC)
  176. break;
  177. end
  178. end
  179. value2=DCT(idD)
  180. place2=idD
  181. idD=idD+1;
  182. while(abs(DCT(idD))<=0)
  183. DCT(idD)=0;
  184. idD=idD+1;
  185. if(idD>=AC)
  186. break;
  187. end
  188. end
  189. value3=DCT(idD);
  190. place3=idD;
  191. idD=idD+1;
  192. [Value1,Value2,Value3]=my_AND(value1,value2,value3,a1,a2);
  193. elseif(Value1==0&&Value2~=0&&Value3==0)
  194. DCT(place1)=0;
  195. DCT(place3)=0;
  196. value1=value2
  197. place1=place2
  198. while(abs(DCT(idD))<=0)
  199. DCT(idD)=0;
  200. idD=idD+1;
  201. if(idD>=AC)
  202. break;
  203. end
  204. end
  205. value2=DCT(idD)
  206. place2=idD
  207. idD=idD+1;
  208. while(abs(DCT(idD))<=0)
  209. DCT(idD)=0;
  210. idD=idD+1;
  211. if(idD>=AC)
  212. break;
  213. end
  214. end
  215. value3=DCT(idD)
  216. place3=idD
  217. idD=idD+1;
  218. [Value1,Value2,Value3]=my_AND(value1,value2,value3,a1,a2);
  219. elseif(Value1~=0&&Value2==0&&Value3==0)
  220. DCT(place2)=0;
  221. DCT(place3)=0;
  222. while(abs(DCT(idD))<=0)
  223. DCT(idD)=0;
  224. idD=idD+1;
  225. if(idD>=AC)
  226. break;
  227. end
  228. end
  229. value2=DCT(idD)
  230. place2=idD
  231. idD=idD+1;
  232. while(abs(DCT(idD))<=0)
  233. DCT(idD)=0;
  234. idD=idD+1;
  235. if(idD>=AC)
  236. break;
  237. end
  238. end
  239. value3=DCT(idD)
  240. place3=idD
  241. idD=idD+1;
  242. [Value1,Value2,Value3]=my_AND(value1,value2,value3,a1,a2);
  243. else
  244. DCT(place1)=0;
  245. DCT(place2)=0;
  246. DCT(place3)=0;
  247. while(abs(DCT(idD))<=0)
  248. DCT(idD)=0;
  249. idD=idD+1;
  250. if(idD>=AC)
  251. break;
  252. end
  253. end
  254. value1=DCT(idD)
  255. place1=idD
  256. idD=idD+1;
  257. while(abs(DCT(idD))<=0)
  258. DCT(idD)=0;
  259. idD=idD+1;
  260. if(idD>=AC)
  261. break;
  262. end
  263. end
  264. value2=DCT(idD)
  265. place2=idD
  266. idD=idD+1;
  267. while(abs(DCT(idD))<=0)
  268. DCT(idD)=0;
  269. idD=idD+1;
  270. if(idD>=AC)
  271. break;
  272. end
  273. end
  274. value3=DCT(idD)
  275. place3=idD
  276. idD=idD+1;
  277. [Value1,Value2,Value3]=my_AND(value1,value2,value3,a1,a2);
  278. end
  279. end
  280. temp1=message(id);
  281. temp2=message(id+1);
  282. DCT(place1)=Value1;
  283. DCT(place2)=Value2;
  284. DCT(place3)=Value3;
  285. end
  286. try
  287. jobj.coef_arrays{1}=DCT;
  288. jobj.optimize_coding=1;
  289. jpeg_write(jobj,STEGO);
  290. catch
  291. error('ERROR (problem with saving the stego image)')
  292. end
  293. end
  294. function res=invH(y)
  295. to_minimize=@(x) (H(x)-y)^2;
  296. res=fminbnd(to_minimize,eps,0.5-eps);
  297. end
  298. function res=H(x)
  299. res=-x*log2(x)-(1-x)*log2(1-x);
  300. end

JSTEG内容提取:

  1. STEGO='stego.jpg';
  2. output=fopen("secret.txt","w");
  3. SEED=99;
  4. mlen=80;
  5. tic;
  6. messageste=nsf5_extract(STEGO,mlen);
  7. length(messageste)
  8. for j=1:length(messageste)
  9. if(rem(j,8)==0)
  10. fprintf(output,"%d",messageste(j));
  11. %fprintf(output,'\r\n');
  12. continue
  13. end
  14. fprintf(output,"%d",messageste(j));
  15. end
  16. %fscanf(output,'%s',messageste);
  17. T=toc;
  18. fprintf('-------\n');
  19. fprintf('nsF5 extract finished\n');
  20. fprintf('elapsed time:%.4f seconds\n',T);
  21. fclose(output);
  22. function message=nsf5_extract(STEGO,mlen)
  23. try
  24. jobj=jpeg_read(STEGO);
  25. DCT=jobj.coef_arrays{1};
  26. catch
  27. error('ERROR (problem with the STEGO image)');
  28. end
  29. AC=numel(DCT)-numel(DCT(1:8:end,1:8:end));
  30. idD=1;
  31. for id=1:mlen
  32. while(abs(DCT(idD))<=1)
  33. idD=idD+1;
  34. end
  35. if(DCT(idD)>0)
  36. if(mod(DCT(idD),2)==1)
  37. message(1,id)=1;
  38. else
  39. message(1,id)=0;
  40. end
  41. else
  42. if(mod(DCT(idD),2)~=1)
  43. message(1,id)=1;
  44. else
  45. message(1,id)=0;
  46. end
  47. end
  48. idD=idD+1;
  49. end
  50. end

F4内容提取

  1. STEGO='stego.jpg';
  2. output=fopen("secret.txt","w");
  3. SEED=99;
  4. mlen=80;
  5. tic;
  6. messageste=nsf5_extractF4(STEGO,mlen);
  7. length(messageste)
  8. for j=1:length(messageste)
  9. if(rem(j,8)==0)
  10. fprintf(output,"%d",messageste(j));
  11. %fprintf(output,'\r\n');
  12. continue
  13. end
  14. fprintf(output,"%d",messageste(j));
  15. end
  16. %fscanf(output,'%s',messageste);
  17. T=toc;
  18. fprintf('-------\n');
  19. fprintf('nsF5 extract finished\n');
  20. fprintf('elapsed time:%.4f seconds\n',T);
  21. fclose(output);
  22. function message=nsf5_extractF4(STEGO,mlen)
  23. try
  24. jobj=jpeg_read(STEGO);
  25. DCT=jobj.coef_arrays{1};
  26. catch
  27. error('ERROR (problem with the STEGO image)');
  28. end
  29. AC=numel(DCT)-numel(DCT(1:8:end,1:8:end));
  30. idD=1;
  31. for id=1:mlen
  32. while(DCT(idD)==0)
  33. idD=idD+1;
  34. end
  35. DCT(idD)
  36. if(DCT(idD)<0)
  37. if(mod(DCT(idD),2)==1)
  38. message(1,id)=0;
  39. end
  40. if(mod(DCT(idD),2)==0)
  41. message(1,id)=1;
  42. end
  43. end
  44. if(DCT(idD)>0)
  45. if(mod(DCT(idD),2)==1)
  46. message(1,id)=1;
  47. end
  48. if(mod(DCT(idD),2)==0)
  49. message(1,id)=0;
  50. end
  51. end
  52. idD=idD+1;
  53. end
  54. end

F5内容提取

  1. STEGO='stego.jpg';
  2. output=fopen("secret.txt","w");
  3. SEED=99;
  4. mlen=80;
  5. tic;
  6. messageste=nsf5_extractF5(STEGO,mlen);
  7. length(messageste)
  8. for j=1:length(messageste)
  9. if(rem(j,8)==0)
  10. fprintf(output,"%d",messageste(j));
  11. %fprintf(output,'\r\n');
  12. continue
  13. end
  14. fprintf(output,"%d",messageste(j));
  15. end
  16. %fscanf(output,'%s',messageste);
  17. T=toc;
  18. fprintf('-------\n');
  19. fprintf('nsF5 extract finished\n');
  20. fprintf('elapsed time:%.4f seconds\n',T);
  21. fclose(output);
  22. function message=nsf5_extractF5(STEGO,mlen)
  23. mlen=mlen+3-mod(mlen,3);
  24. try
  25. jobj=jpeg_read(STEGO);
  26. DCT=jobj.coef_arrays{1};
  27. catch
  28. error('ERROR (problem with the STEGO image)');
  29. end
  30. AC=numel(DCT)-numel(DCT(1:8:end,1:8:end));
  31. idD=1;
  32. for id=1:2:mlen
  33. while(DCT(idD)==0)
  34. idD=idD+1;
  35. end
  36. value1=DCT(idD)
  37. idD=idD+1;
  38. while(DCT(idD)==0)
  39. idD=idD+1;
  40. end
  41. value2=DCT(idD)
  42. idD=idD+1;
  43. while(DCT(idD)==0)
  44. idD=idD+1;
  45. end
  46. value3=DCT(idD)
  47. idD=idD+1;
  48. if(value1>0)
  49. m1=mod(value1,2);
  50. else
  51. m1=mod(value1+1,2);
  52. end
  53. if(value2>0)
  54. m2=mod(value2,2);
  55. else
  56. m2=mod(value2+1,2);
  57. end
  58. if(value3>0)
  59. m3=mod(value3,2);
  60. else
  61. m3=mod(value3+1,2);
  62. end
  63. message(id)=mod((m1+m2),2);
  64. message(id+1)=mod((m2+m3),2);
  65. end
  66. end
标签: matlab

本文转载自: https://blog.csdn.net/weixin_45695828/article/details/124211945
版权归原作者 弗里曼博士 所有, 如有侵权,请联系我们删除。

“[HUST]多媒体安全实验:图像隐写JSTEG,F4,F5的实现”的评论:

还没有评论