{"id":17,"date":"2026-06-07T12:02:27","date_gmt":"2026-06-07T12:02:27","guid":{"rendered":"https:\/\/www.tim.alchamaa.com\/?page_id=17"},"modified":"2026-06-07T12:02:27","modified_gmt":"2026-06-07T12:02:27","slug":"exp","status":"publish","type":"page","link":"https:\/\/www.tim.alchamaa.com\/?page_id=17","title":{"rendered":"exp"},"content":{"rendered":"\n<ol class=\"wp-block-list\">\n<li>Introduction to JPEG-based Steganography<br>Steganography is a data hiding technique that has been used in the applications of information<br>protection. It transmits a secret message by hiding it into a cover object in order to create a<br>hidden way of communication. Steganography has the same goal as cryptography since they aim<br>to protect sensitive information. But they differ in the way of working; Cryptography converts the<br>plain message into an unreadable encrypted message where the presence of the cryptography is<br>not concealed, while steganography smuggles the message by embedding it into an innocentlooking<br>object and thus creating an invisible communication channel.<br>The techniques of steganography have been developed in the field of digital objects such as JPEG<br>images, where we can make the JPEG image a container for a secret message by embedding the<br>message Bits within it. The JPEG image will represent a hidden communication channel, where<br>no one knows what it contains except the sender and intended receiver. Many JPEG-based<br>steganographic methods have been invented in the DCT domain, including the F5 algorithm<br>developed by Westfeld [1]. The F5 algorithm was born in 2001 and is still one of the more known<br>methods.<\/li>\n\n\n\n<li>F5 Steganographic Method<br>Many of the DCT-based methods are based on the idea of a hash function. The function hashes a<br>specific number (n) of quantized DCT coefficients (qDCT) to produce a specific number (k) of<br>Bits. When the sender wants to embed a secret (k) Bits message, the (n) qDCT coefficients<br>should be modified accordingly. Thus, when the receiver hashes the modified (n) qDCT<br>coefficients, the hidden message is then obtained. The modifications are always constrained by<br>requirements and rules depending on the considered algorithm.<br>The F5 algorithm was proposed by Westfeld [1]. It is based on the idea of the matrix encoding<br>(dmax, n, k) with dmax=1, where its goal is to minimize the number of changes made to the<br>qDCT coefficients. The F5 algorithm takes (n) qDCT coefficients and hashes them to (k) Bits<br>using a Xor-based hash function. When the sender needs a modification to embed the secret<br>message, only one coefficient is changed since the resulting (n) qDCT coefficients should not<br>have a hamming distance of more than dmax=1 from the original (n) qDCT coefficients. The (k)<br>and (n) are calculated based on the original image capacity as well as the message length.<\/li>\n\n\n\n<li>Matlab Implementation of F5 Algorithm<br>3.1 Huffman Coding and Decoding<br>The DCT-based steganographic methods are based on the idea of modifying the qDCT<br>coefficients in such a way allowing to embed a stream of Bits. Thus, we need to have the ability<br>to access the qDCT coefficients of a given JPEG file. The Matlab&#8217;s built-in functions used to<br>handle digital images provide only basic conversion between the given JPEG file and image<br>pixels. They don\u2019t give any access to the qDCT coefficients. In order to overcome this issue, we<br>use a dedicated Matlab JPEG Toolbox developed by Sallee [2]. The used JPEG Toolbox contains<br>special functions allowing to access and manipulate the qDCT coefficients of a given JPEG file.<br>6<br>The main two functions in the Sallee&#8217;s package \u201cjpeg_read\u201d and \u201cjpeg_write\u201d perform the steps<br>of the lossless compression applied to the qDCT coefficients including Huffman coding and<br>decoding. Thus, they provide more functionality, since they give the ability to gain direct access<br>to all the structural elements of a JPEG file from Matlab, including the matrices of qDCT<br>coefficients and the quantization tables.<br>3.2 Implementation of F5 Embedding Process<br>3.2.1 Steps of F5 Embedding Process<br>In this section, we present a block diagram showing the implementation steps of the F5 algorithm<br>on the sender side of the connection, where we hide the message file into a given JPEG image.<br>At first, the \u201cjpeg_read\u201d function reads the given JPEG file and performs the entropy decoding.<br>The \u201cjpeg_read\u201d function gives a Matlab structure containing the qDCT coefficients matrices,<br>quantization tables, and other information. Only the qDCT coefficients matrix of Y component is<br>used to embed the secret message because of its large size compared to those of the other two<br>components.<br>Before running the F5 embedding process, we should have two tasks completed:<br>1- We define the matrix encoding ME by calculating the size of the message file and the<br>number of Non-zero coefficients in the resulting Y matrix. The ME calculator gives the<br>initial value of the matrix encoding that we should use in the embedding process.<br>2- Typically, the embedding process should be protected and connected with a secret key.<br>Thus, we should use a key-based permutation generator. The generated permutation is<br>applied to the qDCT coefficients matrix of Y component before running the F5_ME<br>embedding process.<br>During the running of the F5 embedding process, we take into consideration the shrinkage of<br>Non-zero qDCT coefficients, thus a shrinkage tester is always running. The tester aims to detect<br>the occurrence of the shrinkage during the process, so the shrinking coefficient will be replaced<br>by another one. In addition, the tester aims to ensure that the message file was embedded entirely<br>according to the used ME, otherwise, the ME will be recalculated and the embedding process will<br>be repeated according to the new ME.<br>In the end, the resulting matrix is inversely permuted in order to get back the original order of the<br>Y matrix of qDCT coefficients. The resulting qDCT coefficients matrix of Y component will then<br>be in the same order as the original one, but<\/li>\n\n\n\n<li><\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Wassim Al Chamaa<br>MATLAB Implementation of the<br>Steganographic Algorithm F5<br>Matlab Codes for F5 Algorithm<br>Project Report<br>Computer Science<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bibliographic information published by the German National Library:<br>The German National Library lists this publication in the National Bibliography;<br>detailed bibliographic data are available on the Internet at http:\/\/dnb.dnb.de .<br>This book is copyright material and must not be copied, reproduced, transferred,<br>distributed, leased, licensed or publicly performed or used in any way except as<br>specifically permitted in writing by the publishers, as allowed under the terms and<br>conditions under which it was purchased or as strictly permitted by applicable<br>copyright law. Any unauthorized distribution or use of this text may be a direct<br>infringement of the author s and publisher s rights and those responsible may be<br>liable in law accordingly.<br>Imprint:<br>Copyright \u00a9 2018 GRIN Verlag<br>ISBN: 9783668933439<br>This book at GRIN:<br>https:\/\/www.grin.com\/document\/464340<br>Wassim Al Chamaa<br>MATLAB Implementation of the Steganographic Algorithm<br>F5<br>Matlab Codes for F5 Algorithm<br>GRIN Verlag<br>GRIN &#8211; Your knowledge has value<br>Since its foundation in 1998, GRIN has specialized in publishing academic texts by<br>students, college teachers and other academics as e-book and printed book. The<br>website www.grin.com is an ideal platform for presenting term papers, final papers,<br>scientific essays, dissertations and specialist books.<br>Visit us on the internet:<br>http:\/\/www.grin.com\/<br>http:\/\/www.facebook.com\/grincom<br>http:\/\/www.twitter.com\/grin_com<br>MATLAB Implementation of the Steganographic Algorithm F5<br>By<br>Wassim Al Chamaa<br>2<br>TABLE OF CONTENTS<br>ABSTRACT<br>LIST OF FIGURES<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Introduction to JPEG-based Steganography<\/li>\n\n\n\n<li>F5 Steganographic Method<\/li>\n\n\n\n<li>Matlab Implementation of F5 Algorithm<br>3.1 Huffman Coding and Decoding<br>3.2 Implementation of F5 Embedding Process<br>3.2.1 Steps of F5 Embedding Process<br>3.2.2 Main Script and Called Functions<br>3.2.3 Matlab Codes of F5 Embedding Process<br>3.2.3.1 F5Embed Matlab Main Script<br>3.2.3.2 Msgsize Matlab Function<br>3.2.3.3 Qdct2Img Matlab Function<br>3.2.3.4 MediCap Matlab Function<br>3.2.3.5 MatEncod Matlab Function<br>3.2.3.6 GetkBits Matlab Function<br>3.2.3.7 DoEmbed Matlab Function<br>3.2.3.8 DoStego Matlab Function<br>3.2.3.9 F5Hash Matlab Function<br>3.2.3.10 DoChange Matlab Function<br>3.2.3.11 HistPlot Matlab Function<br>3.3 Implementation of F5 Extracting Process<br>3.3.1 Steps of F5 Extracting Process<br>3.3.2 Main Script and Called Functions<br>3.3.3 Matlab Codes of F5 Extracting Process<br>3.3.3.1 F5Extract Matlab Main Script<br>3.3.3.2 MediCap Matlab Function<br>3.3.3.3 DoExtract Matlab Function<br>3.3.3.4 F5Hash Matlab Function<\/li>\n\n\n\n<li>Programming Notes<br>References<br>3<br>ABSTRACT<br>The F5 algorithm proposed by Westfeld is still one of the most known algorithms in the field of<br>DCT-based steganography. It can make a JPEG image a container of a secret message, where no<br>one knows the presence of the message except the sender and the intended receiver. In this<br>programming work, we show how to realize the F5 algorithm via Matlab. We will present the<br>block diagrams of embedding and extracting processes and the entire Matlab codes of the F5<br>algorithm.<br>4<br>LIST OF FIGURES<br>Figure 1: Block Diagram of F5 Embedding Process \u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026.7<br>Figure 2: Block Diagram of F5 Extraction Process \u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026..16<br>5<\/li>\n\n\n\n<li>Introduction to JPEG-based Steganography<br>Steganography is a data hiding technique that has been used in the applications of information<br>protection. It transmits a secret message by hiding it into a cover object in order to create a<br>hidden way of communication. Steganography has the same goal as cryptography since they aim<br>to protect sensitive information. But they differ in the way of working; Cryptography converts the<br>plain message into an unreadable encrypted message where the presence of the cryptography is<br>not concealed, while steganography smuggles the message by embedding it into an innocentlooking<br>object and thus creating an invisible communication channel.<br>The techniques of steganography have been developed in the field of digital objects such as JPEG<br>images, where we can make the JPEG image a container for a secret message by embedding the<br>message Bits within it. The JPEG image will represent a hidden communication channel, where<br>no one knows what it contains except the sender and intended receiver. Many JPEG-based<br>steganographic methods have been invented in the DCT domain, including the F5 algorithm<br>developed by Westfeld [1]. The F5 algorithm was born in 2001 and is still one of the more known<br>methods.<\/li>\n\n\n\n<li>F5 Steganographic Method<br>Many of the DCT-based methods are based on the idea of a hash function. The function hashes a<br>specific number (n) of quantized DCT coefficients (qDCT) to produce a specific number (k) of<br>Bits. When the sender wants to embed a secret (k) Bits message, the (n) qDCT coefficients<br>should be modified accordingly. Thus, when the receiver hashes the modified (n) qDCT<br>coefficients, the hidden message is then obtained. The modifications are always constrained by<br>requirements and rules depending on the considered algorithm.<br>The F5 algorithm was proposed by Westfeld [1]. It is based on the idea of the matrix encoding<br>(dmax, n, k) with dmax=1, where its goal is to minimize the number of changes made to the<br>qDCT coefficients. The F5 algorithm takes (n) qDCT coefficients and hashes them to (k) Bits<br>using a Xor-based hash function. When the sender needs a modification to embed the secret<br>message, only one coefficient is changed since the resulting (n) qDCT coefficients should not<br>have a hamming distance of more than dmax=1 from the original (n) qDCT coefficients. The (k)<br>and (n) are calculated based on the original image capacity as well as the message length.<\/li>\n\n\n\n<li>Matlab Implementation of F5 Algorithm<br>3.1 Huffman Coding and Decoding<br>The DCT-based steganographic methods are based on the idea of modifying the qDCT<br>coefficients in such a way allowing to embed a stream of Bits. Thus, we need to have the ability<br>to access the qDCT coefficients of a given JPEG file. The Matlab&#8217;s built-in functions used to<br>handle digital images provide only basic conversion between the given JPEG file and image<br>pixels. They don\u2019t give any access to the qDCT coefficients. In order to overcome this issue, we<br>use a dedicated Matlab JPEG Toolbox developed by Sallee [2]. The used JPEG Toolbox contains<br>special functions allowing to access and manipulate the qDCT coefficients of a given JPEG file.<br>6<br>The main two functions in the Sallee&#8217;s package \u201cjpeg_read\u201d and \u201cjpeg_write\u201d perform the steps<br>of the lossless compression applied to the qDCT coefficients including Huffman coding and<br>decoding. Thus, they provide more functionality, since they give the ability to gain direct access<br>to all the structural elements of a JPEG file from Matlab, including the matrices of qDCT<br>coefficients and the quantization tables.<br>3.2 Implementation of F5 Embedding Process<br>3.2.1 Steps of F5 Embedding Process<br>In this section, we present a block diagram showing the implementation steps of the F5 algorithm<br>on the sender side of the connection, where we hide the message file into a given JPEG image.<br>At first, the \u201cjpeg_read\u201d function reads the given JPEG file and performs the entropy decoding.<br>The \u201cjpeg_read\u201d function gives a Matlab structure containing the qDCT coefficients matrices,<br>quantization tables, and other information. Only the qDCT coefficients matrix of Y component is<br>used to embed the secret message because of its large size compared to those of the other two<br>components.<br>Before running the F5 embedding process, we should have two tasks completed:<br>1- We define the matrix encoding ME by calculating the size of the message file and the<br>number of Non-zero coefficients in the resulting Y matrix. The ME calculator gives the<br>initial value of the matrix encoding that we should use in the embedding process.<br>2- Typically, the embedding process should be protected and connected with a secret key.<br>Thus, we should use a key-based permutation generator. The generated permutation is<br>applied to the qDCT coefficients matrix of Y component before running the F5_ME<br>embedding process.<br>During the running of the F5 embedding process, we take into consideration the shrinkage of<br>Non-zero qDCT coefficients, thus a shrinkage tester is always running. The tester aims to detect<br>the occurrence of the shrinkage during the process, so the shrinking coefficient will be replaced<br>by another one. In addition, the tester aims to ensure that the message file was embedded entirely<br>according to the used ME, otherwise, the ME will be recalculated and the embedding process will<br>be repeated according to the new ME.<br>In the end, the resulting matrix is inversely permuted in order to get back the original order of the<br>Y matrix of qDCT coefficients. The resulting qDCT coefficients matrix of Y component will then<br>be in the same order as the original one, but with some modifications caused by the embedding<br>process of the F5 algorithm. At this point, we write the resulting matrix to the Matlab JPEG<br>structure and then use the \u201cjpeg_write\u201d function to perform the entropy coding in order to<br>produce the Stego JPEG file that contains the secret message file. A block diagram of the F5<br>embedding process is presented in Figure 1.<br>7<br>Fig 1: Block Diagram of F5 Embedding Process &#8211; Sender Side.<br>8<br>3.2.2 Main Script and Called Functions<br>Main Script Called Functions m Files<br>Msgsize Function Msgsize.m<br>Qdct2Img Function Qdct2Img.m<br>MediCap Function MediCap.m<br>MatEncod Function MatEncod.m<br>F5Embed Main Script &#8211; F5Embed.m GetkBits Function GetkBits.m<br>DoEmbed Function DoEmbed.m<br>DoStego Function DoStego.m<br>F5Hash Function F5Hash.m<br>DoChange Function DoChange.m<br>HistPlot Function HistPlot.m<br>3.2.3 Matlab Codes of F5 Embedding Process<br>In this section, we present the entire Matlab codes, main script and called functions, that realize<br>the embedding process of a secret message file whatever its extension.<br>3.2.3.1 F5Embed Matlab Main Script<br>clear all; close all; clc;<br>OriginalImg=&#8217;CoverImage.JPG&#8217;; % Original image file &#8211; Cover Image.<br>Messagefile=&#8217;Message.txt&#8217;; % Secret Message file, whatever the extension.<br>SteganoImg=&#8217;StegoImage.JPG&#8217;; % Resulting image file &#8211; Stego Image.<br>Msgbits=Msgsize(Messagefile);<br>JPG=jpeg_read(OriginalImg); % Reading original image file \/ Huffman decoding.<br>mat1=JPG.coef_arrays{1}; % Y component matrix<br>Qtb1=JPG.quant_tables{JPG.comp_info(1).quant_tbl_no};<br>img1= Qdct2Img(mat1,Qtb1);<br>figure(1);<br>imshow(img1); % showing Y component of the Original image.<br>Cap=MediCap(mat1); % Calculating Nonzero coefficients.<br>siz=size(mat1);<br>Rw=siz(1); % rows : Height.<br>Cl=siz(2); % columms : Width.<br>CoefNb=Cl<em>Rw; TmpBuff=zeros(1,CoefNb); % Temporary Buffer. RltBuff=zeros(1,CoefNb); % Resulting Buffer. % indx=0; for xx=1:Rw for yy=1:Cl indx=indx+1; TmpBuff(indx)=mat1(xx,yy); end end % Now, we have (indx=CoefNb). 9 % \u2026\u2026\u2026\u2026\u2026\u2026.. % At this point, a permutation should be applied to the Temporary Buffer : TmpBuff % \u2026\u2026\u2026\u2026\u2026\u2026.. Embrate= 100<\/em>(Msgbits\/Cap);<br>Encod=MatEncod(Embrate); % Calculating Matrix Encoding.<br>% \u2026\u2026\u2026\u2026\u2026\u2026.. Main Processing LOOP \u2026\u2026\u2026\u2026\u2026\u2026..<br>WrkCn=0; % Counter of work process<br>WrkDone=0;<br>while(WrkDone==0) % Main Processing LOOP<br>WrkCn=WrkCn+1;<br>% Available codewords number (Cap\/n).<br>AvalCdWd=(Cap-mod(Cap,Encod(2)))\/Encod(2);<br>% Needed codewords number (Msgbits\/k).<br>NeedCdWd=(Msgbits-mod(Msgbits,Encod(3)))\/Encod(3);<br>% Stego Operation, We have : AvalCdWd > NeedCdWd<br>SecData=GetkBits(Messagefile,Encod(3));<br>mBuff=zeros(1,1);<br>ShkgCn=0; % Shrinkage counter.<br>cont=0; % (n) nonzero counter.<br>indx=1;<br>ix=1;<br>CdWd=1; % Codeword index.<br>while ((CdWd&lt;=NeedCdWd) &amp;&amp; (indx &lt;= CoefNb)) while ((cont CoefNb) % The case where (indx) exceeded (CoefNb)<br>Embrate=100<em>(Encod(3)\/Encod(2)); Encod=MatEncod(Embrate); % Recalculating Encod WrkDone=0; % The work is NOT done end if (CdWd > NeedCdWd) % The case where the work is done WrkDone=1; end end % End of Main Processing LOOP % \u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026.. % \u2026\u2026\u2026\u2026\u2026End of Main Processing LOOP\u2026\u2026\u2026\u2026\u2026\u2026 % \u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026.. ChgMax=ShkgCn+NeedCdWd; % Maximum number of changes. BffLmt=indx-1; % Reached limit in TmpBuff. % End of Stego Operation % % Constructing Resulting Buffer : RltBuff Concat=[OutBuffs{1,1} OutBuffs{1,2}]; for i=3:NeedCdWd % Concatenation. Concat=[Concat OutBuffs{1,i}]; end Sz=size(Concat); for i=1:Sz(2) RltBuff(i)=Concat(i); end for i=Sz(2)+1:CoefNb RltBuff(i)=TmpBuff(i); end % \u2026\u2026\u2026\u2026\u2026\u2026.. % At this point, In case we used Permutation, The inverse Permutation % should be applied to the Resulting Buffer : RltBuff % \u2026\u2026\u2026\u2026\u2026\u2026.. % Histogram of resulting Buffer. figure(2); HH=HistPlot(RltBuff,25,0,0); % Constructing New Coefficients Matrix. siz=size(mat1); Rw=siz(1); % rows : Height. Cl=siz(2); % columms : Width. Nmat1=zeros(Rw,Cl); inx=0; for xx=1:Rw for yy=1:Cl inx=inx+1; Nmat1(xx,yy)=RltBuff(inx); end end % Now, we have (inx=CoefNb). % % Stego image Reconstruction JPG.coef_arrays{1}=Nmat1; % New Coefficients Matrix (Y component). jpeg_write(JPG,SteganoImg); % 11 % showing the Stego image (Y component). JPG=jpeg_read(SteganoImg); mat1=JPG.coef_arrays{1}; Qtb1=JPG.quant_tables{JPG.comp_info(1).quant_tbl_no}; img2= Qdct2Img(mat1,Qtb1); figure(3); imshow(img2); % 3.2.3.2 Msgsize Matlab Function function bitSize=Msgsize(msgfile) % fileObj = memmapfile(msgfile); siz = size(fileObj.data); FileSiz=siz(1); % File Size in Bytes. bitSize= FileSiz<\/em>8; % File Size in Bits.<br>%<br>3.2.3.3 Qdct2Img Matlab Function<br>function img_mat= Qdct2Img(qdct_mat,Qtbl)<br>% This function computes the Image<br>% matrix of the considered component.<br>demat=dequantize(qdct_mat,Qtbl);<br>img_mat0=ibdct(demat)+128;<br>img_mat=uint8(img_mat0);<br>%<br>3.2.3.4 MediCap Matlab Function<br>function Cap=MediCap(mat)<br>% mat : Y component matrix.<br>siz=size(mat);<br>Rw=siz(1); % rows : Height.<br>Cl=siz(2); % columms : Width.<br>% Calculating the number of<br>% Nonzero coefficients.<br>cout=0;<br>for xx=1:Rw<br>for yy=1:Cl<br>if (mat(xx,yy)~=0)<br>cout=cout+1;<br>end<br>end<br>end<br>Cap=cout;<br>%<br>12<br>3.2.3.5 MatEncod Matlab Function<br>function Encod=MatEncod(Embrate)<br>% Calculating the matrix encoding<br>Encod=[1 1 1];<br>k=0;<br>Diff=1;<br>while (Diff>0)<br>k=k+1;<br>R=100<em>(k \/((2^k)-1)); Diff=R-Embrate; end k=k-1; n=(2^k)-1; Encod(2)=n; Encod(3)=k; % 3.2.3.6 GetkBits Matlab Function function SecData=GetkBits(msgfile,k) % Distribute the information to be hidden on a matrix % Creating a matrix (SecData) including the Bits stream % of the secret message file according to (k) value. % msgfile : File name String. % k : Embeded data size. Frmt=[&#8216;ubit&#8217; int2str(k)]; Msgbits=Msgsize(msgfile); Nb=(Msgbits-mod(Msgbits,k))\/k; SecData=zeros(1,Nb); fid=fopen(msgfile,&#8217;r&#8217;); for idx=1:Nb SecData(idx)= fread(fid,1,Frmt); end fclose(fid); % 13 3.2.3.7 DoEmbed Matlab Function function MBuff_shk=DoEmbed(mBuff,m,n,DesiredVal) % mBuff has the size (m) and contains (m) qDCT coefficients. % mBuff contains (n) Nonzero qDCT coefficients. % m >= n % m : loop-changeable value. % n : the encoding value, Matrix Encoding =(1,n,k). % DesiredVal : the desired value to be embedded. % DesiredVal will be within [0,1,..,n], k Bits. nBuff=zeros(1,n); j=0; for i=1:m if (mBuff(i)~=0) % Nonzero values. j=j+1; nBuff(j)=mBuff(i); mBuff(i)=0.5; % Marking the Nonzero value locations. end end % Now, we have (j=n). NBuff=zeros(1,n); % Appling F5 algorithm on nBuff. if(j==n) NBuff=DoStego(nBuff,n,DesiredVal); end % Reforming mBuff. % Shrinkage Testing in steganographed NBuff. Shk=0; % Shrinkage Indicator. ShkPt=0; % Shrinkage Position. j=0; for i=1:m if (mBuff(i)==0.5) j=j+1; mBuff(i)=NBuff(j); if (NBuff(j)==0) % Shrinkage Test. Shk=1; % Shrinkage Indicator. ShkPt=i; % Shrinkage Position. end end end % Now, we have (j=n) % mBuff has been modified\/steganographed. % % Returning modified buffer % and shrinkage indicator. MBuff=mBuff; MBuff_shk={MBuff,Shk,ShkPt}; % 14 3.2.3.8 DoStego Matlab Function function stegoBuff=DoStego(Buff,n,DesiredVal) % Buff contains (n) qDCTs coefficients. % DesiredVal is the desired value to be embedded. % DesiredVal will be within [0,1,..,n]. % % Calculating the current Hash value. CurrentVal=F5Hash(Buff,n); % XORing desired and current values % in order to find bit location (S) to modify. S= bitxor(DesiredVal,CurrentVal); % Applying the (d=1) modification : % changing the buffer by One change NewBuff=DoChange(Buff,S); % Calculating the New Hash value. NewVal=F5Hash(NewBuff,n); % Comparing between % New and Desired values % Returning the stego Buffer. if (NewVal==DesiredVal) % Must be always true. stegoBuff=NewBuff; elseif (NewVal~=DesiredVal) stegoBuff=0; end % 3.2.3.9 F5Hash Matlab Function function Hash = F5Hash(Buff,n) % F5 algorithm Hash function % Buff contains (n) qDCTs coefficients. ABuff= abs(Buff); % (ai) Bits do not change. B=ones(1,n); a = bitand(ABuff,B); % Extracting (ai) Bits values. %%% indx=zeros(1,n); for i=1:n indx(i)=i; end %%% idx=a.<\/em>indx; % Multiplying element by element.<br>%%%<br>hsh=idx(1);<br>for i=2:n<br>hsh= bitxor(hsh,idx(i));<br>end<br>Hash=hsh; % Resulting Hash Value.<br>%<br>15<br>3.2.3.10 DoChange Matlab Function<br>function NewBuff=DoChange(Buff,S)<br>% (S) points to the bit location that must be changed<br>% Treatement Only in case of (S>0), If (S=0) there is NO changment.<br>if (S>0)<br>if (Buff(S)> 0) % Positive qDCT Value.<br>Buff(S)= Buff(S)-1;<br>elseif (Buff(S)&lt; 0) % Negative qDCT Value.<br>Buff(S) = (-1)<em>(abs(Buff(S))-1); end end NewBuff=Buff; % 3.2.3.11 HistPlot Matlab Function function HH=HistPlot(Vec,Rang,MaxCH,MaxCnt) HH=zeros(1,3); siz=size(Vec); [n,xout]=hist(Vec,-Rang:Rang); ToTNb=sum(n); HH(1)=ToTNb; XNb=(2<\/em>Rang)+1;<br>HH(2)=n(1)+n(XNb);<br>%%%<br>n(1)=0;<br>n(XNb)=0;<br>if (ToTNb==siz(2) &amp;&amp; MaxCH==1)<br>for i=1:XNb<br>if(xout(i)==0)<br>HH(3)=n(i);<br>n(i)=MaxCnt;<br>end<br>end<br>end<br>bar(xout,n);<br>%<br>16<br>3.3 Implementation of F5 Extracting Process<br>3.3.1 Steps of F5 Extracting Process<br>In this section, we present a block diagram showing the implementation steps of the F5 algorithm<br>on the receiver side of the connection, where we extract the hidden message file from the<br>received Stego JPEG file.<br>At first, the Stego JPEG file is read (red) by the \u201cjpeg_read\u201d Matlab function which gives a<br>Matlab structure containing the qDCT coefficients matrices. The qDCT coefficients matrix of Y<br>component is then permuted using the same permutation generator and key which were used in<br>the sender side. After permutation, we obtain the matrix in the same order that was used during<br>the embedding process. The F5 algorithm will then hash the permuted matrix using the same<br>matrix encoding ME that was used during the embedding process in order to get the hidden<br>message File. A block diagram of the F5 extraction process is presented in Figure 2.<br>Fig 2: Block Diagram of F5 Extraction Process &#8211; Receiver Side.<br>17<br>3.3.2 Main Script and Called Functions<br>Main Script Called Functions m Files<br>MediCap Function MediCap.m<br>F5Extract Main Script &#8211; F5Extract.m DoExtract Function DoExtract.m<br>F5Hash Function F5Hash.m<br>3.3.3 Matlab Codes of F5 Extracting Process<br>In this section, we present the entire Matlab codes, main script and called functions, that realize<br>the extracting process of the hidden message file. In order to extract the hidden file correctly, the<br>Value of the Matrix Encoding, must be set as calculated in the embedding process.<br>3.3.3.1 F5Extract Matlab Main Script<br>clear all;close all; clc;<br>% In order to extract the hidden file correctly, the Value<br>% of Encod (Matrix Encoding) must be set as calculated in<br>% the embedding process : F5Embed.m .<br>% Used Matrix Encoding<br>Encod=[1 15 4]; % [1 7 3],[1,31,5],[1,63,6],[1,255,8];<br>%<br>StegoIm=&#8217;StegoImage.JPG&#8217;; % Received Stego Image file.<br>Rcvmsg=&#8217;Extracted.txt&#8217;; % Extracted Hidden Message file.<br>%<br>JPG=jpeg_read(StegoIm);<br>mat1=JPG.coef_arrays{1};<br>Cap=MediCap(mat1);<br>% Available codewords number (Cap\/n).<br>AvalCdWd=(Cap-mod(Cap,Encod(2)))\/Encod(2);<br>%<br>siz=size(mat1);<br>Rw=siz(1); % rows : Height.<br>Cl=siz(2); % columms : Width.<br>CoefNb=Cl*Rw;<br>TmpBuff=zeros(1,CoefNb);<br>mBuff=zeros(1,1);<br>%<br>indx=0;<br>for xx=1:Rw<br>for yy=1:Cl<br>indx=indx+1;<br>TmpBuff(indx)=mat1(xx,yy);<br>end<br>end<br>18<br>% \u2026\u2026\u2026\u2026\u2026\u2026..<br>% At this point, we should apply the same permutation<br>% which was used in the embedding process to TmpBuff.<br>% \u2026\u2026\u2026\u2026\u2026\u2026..<br>cont=0;<br>CdWd=1;<br>indx=1;<br>ix=1;<br>ExVal=0;<br>while(CdWd&lt;=AvalCdWd) % Extraction LOOP<br>while (cont&lt;Encod(2))<br>if (TmpBuff(indx)==0)<br>mBuff(ix)=TmpBuff(indx);<br>indx=indx+1;<br>ix=ix+1;<br>elseif (TmpBuff(indx)~=0)<br>mBuff(ix)=TmpBuff(indx);<br>cont=cont+1;<br>indx=indx+1;<br>ix=ix+1;<br>end<br>end<br>m=ix-1; % The bufferd number.<br>ExVal=[ExVal DoExtract(mBuff,m,Encod(2))];<br>CdWd=CdWd+1;<br>mBuff=zeros(1,1);<br>ix=1;<br>cont=0;<br>end % End of Extraction LOOP<br>% \u2026\u2026\u2026\u2026\u2026\u2026.. % End of Extraction LOOP<br>% \u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026<br>% Writing extracted Bits stream to a file (secret message file).<br>k=Encod(3);<br>Frmt=[&#8216;ubit&#8217; int2str(k)];<br>fid=fopen(Rcvmsg,&#8217;w&#8217;);<br>for i=2:AvalCdWd+1<br>count = fwrite(fid,ExVal(i),Frmt); % Creating the output file.<br>end<br>fclose(fid);<br>%<br>3.3.3.2 MediCap Matlab Function<br>The function here is the same as in the section 3.2.3.4 .<br>19<br>3.3.3.3 DoExtract Matlab Function<br>function ExVal=DoExtract(mBuff,m,n)<br>%<br>nBuff=zeros(1,n);<br>j=0;<br>for i=1:m<br>if (mBuff(i)~=0) % Nonzero values.<br>j=j+1;<br>nBuff(j)=mBuff(i);<br>end<br>end<br>% Now, we have (j=n).<br>% Calculating the F5 Hash value.<br>ExVal=F5Hash(nBuff,n);<br>%<br>3.3.3.4 F5Hash Matlab Function<br>The function here is the same as in the section 3.2.3.9 .<\/li>\n\n\n\n<li>Programming Notes:<br>1- In the DCT-based steganography, we need to have direct access to qDCT coefficients.<br>The toolbox of Sallee made it easier for us to access and manipulate the qDCT<br>coefficients where the main two functions of the package perform the standard steps of<br>lossless compression including Huffman Coding and decoding. This toolbox provides<br>complete control over all internal contents of the JPEG image file, thus it can be used in<br>many applications especially in DCT-based steganography.<br>2- The embedding program starts from a given JPEG file stored on a digital storage unit and<br>ends with an output Stego JPEG file to be stored or to be sent over the network. Therefore,<br>Removing the codes of showing the images and histogram doesn\u2019t affect the main<br>function of the program.<br>3- The secret message file can be any file of any kind and whatever its extension. The<br>embedding and extracting programs deal with the message file as a series of Bits.<br>4- The shrinkage happening to qDCT coefficients during the embedding process is a subject<br>to probability. It may affect the capacity of the image since it causes a decrease in the<br>number of Non-zero qDCT coefficients. Therefore, the possibility of modifying the<br>initially calculated value of ME during the embedding process and thus repeating the<br>process should be taken into consideration.<br>5- In the presented program, the part related to the permutation is left blank where the<br>programmer can add his own codes accordingly. The programmer can build a permutation<br>generator based on a pseudo-random generator and connect it to a key.<br>20<br>References<br>[1] A. Westfeld. \u201cF5 \u2014 a steganographic algorithm \u2014 high capacity despite better<br>steganalysis\u201d: Information Hiding, Fourth International Workshop, Lecture Notes<br>in Computer Science vol. 2137, 289\u2013302, 2001.<br>[2] Phil Sallee. \u201cMatlab JPEG Toolbox\u201d: Original package: jpegtbx_1.4, Sep 2003.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Wassim Al ChamaaMATLAB Implementation of theSteganographic Algorithm F5Matlab Codes for F5 AlgorithmProject ReportComputer Science Bibliographic information published by the German National Library:The German National Library lists this publication in the National Bibliography;detailed bibliographic data are available on the Internet at http:\/\/dnb.dnb.de .This book is copyright material and must not be copied, reproduced, transferred,distributed, leased, licensed [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-17","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.tim.alchamaa.com\/index.php?rest_route=\/wp\/v2\/pages\/17","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tim.alchamaa.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.tim.alchamaa.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.tim.alchamaa.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tim.alchamaa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=17"}],"version-history":[{"count":1,"href":"https:\/\/www.tim.alchamaa.com\/index.php?rest_route=\/wp\/v2\/pages\/17\/revisions"}],"predecessor-version":[{"id":18,"href":"https:\/\/www.tim.alchamaa.com\/index.php?rest_route=\/wp\/v2\/pages\/17\/revisions\/18"}],"wp:attachment":[{"href":"https:\/\/www.tim.alchamaa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}