Help embedding secret message using lwt .cannot extract the secret message correctly
1 view (last 30 days)
Show older comments
plz help.. here is my code at below
i embedded the secret message in the 1 LSB of each CA
then i did ilwt for CA, CD and converted to uint8
BUT.. when i do lwt again ..then extracting the message from 1LSB of each CA..the extracted message is not the same as the input
BUt it is the same if i did not covert the ilwt to uint8...why?..i should convert it to uint8 because in the advanced code i will assign the result to the row of the image again
% reading the image
img=imread('c:\head4.tif');
% the row (the host row) in which i want to embed the secret message as an example at row
% 305 and start column 3 to end column 570
row_img=img(305,3:570);
% secret message is a vector
secret=[100,200,20,40,50,80,60,230,140,1,2,0,210,205,190,9,0,32,80,100,200,201,202,203,199,189,187,180,170,0,1,0,1,0,100];
secret_bin=dec2bin(secret,8);
secret_bin=secret_bin';
length_secret = size(secret_bin,1)*size(secret_bin,2);
wname = liftwave('haar','int2int');
host_row=double(row_img);
[CA, CD]=lwt(host_row,wname);
length_CA = size(CA,2);
c = 1;
% embedding the secret_bin in the last signficant bit of each CA ( 1 LSB of CA )
for b = 1:1:length_CA
if b <= length_secret
xb=CA(1,c);
if xb < 0
xb= abs(xb);
if strcmp(secret_bin(b), '0')
xb=bitset(xb,1,0);
else
xb=bitset(xb,1,1);
end
CA(1,c)=-xb;
else
if strcmp(secret_bin(b), '0')
CA(1,c) = bitset(CA(1,c),1,0);
else
CA(1,c) = bitset(CA(1,c),1,1);
end
end% end if xb<0
c = c+ 1;
if (c > length_CA)
c = 1;
end
end % if b <= length_secret
end % end for loop b=8:-1:1
stego_host_uint8 = uint8(ilwt(CA,CD,wname));
stego_host_dble = (ilwt(CA,CD,wname));
% Extracting the secret vector from the stego_host_uint8
watermarked_host=double(stego_host_uint8);
[CA_ex, CD_ex] = lwt(watermarked_host,wname);
length_CA_ex = size(CA_ex,2);
c = 1;
secret_bits_ex = zeros(1,length_secret);
for b = 1:1:length_CA_ex
if b <= length_secret
xb=CA_ex(1,c);
if xb < 0
xb= abs(xb);
end
secret_bits_ex(b) = bitget(xb,1);
%letter = bitset(letter,b,bitget(xb,1));
c = c + 1;
end
end
% function i created
secret_ex=binRoundC2Dec(secret_bits_ex,8);
% comparison between the input secret vector and the extracted
message=secret';
if secret_ex == message
disp('yes equal');
else
disp('No Equal');
end
% the extracted output [100;200;20;40;114;80;60;230;140;1;2;0;210;205;190;9;0;32;80;100;200;201;202;203;199;189;187;180;162;0;1;0;1;0;100]
% the input secret [100;200;20;40;50;80;60;230;140;1;2;0;210;205;190;9;0;32;80;100;200;201;202;203;199;189;187;180;170;0;1;0;1;0;100]
% they are diffrent at positions 5 , 29 ...why?
% Extracting the secret vector from the stego_host_dble
watermarked_host_dbl=double(stego_host_dble);
[CA_ex_dbl, CD_ex_dbl] = lwt(watermarked_host_dbl,wname);
length_CA_ex = size(CA_ex_dbl,2);
c = 1;
secret_bits_ex_dbl = zeros(1,length_secret);
for b = 1:1:length_CA_ex
if b <= length_secret
xb=CA_ex_dbl(1,c);
if xb < 0
xb= abs(xb);
end
secret_bits_ex_dbl(b) = bitget(xb,1);
%letter = bitset(letter,b,bitget(xb,1));
c = c + 1;
end
end
% function i created
secret_ex_dbl=binRoundC2Dec(secret_bits_ex_dbl,8);
% comparison between the input secret vector and the extracted
message=secret';
if secret_ex_dbl == message
disp('yes equal from stego dble');
else
disp('No Equal from stego dble');
end
% the extracted output [100;200;20;40;50;80;60;230;140;1;2;0;210;205;190;9;0;32;80;100;200;201;202;203;199;189;187;180;170;0;1;0;1;0;100]
% the input secret [100;200;20;40;50;80;60;230;140;1;2;0;210;205;190;9;0;32;80;100;200;201;202;203;199;189;187;180;170;0;1;0;1;0;100]
% they are equal when extracting directly from double lwt without conversion to uint8
9 Comments
rizky alvarez
on 17 Mar 2021
excuseme shimaa, do you find the solution for this problem?
i have same problem with the code
Answers (2)
Walter Roberson
on 6 May 2017
With that head4.tif file, there are three places where stego_host_uint8 is different from stego_host_dble . In two of the places, stego_host_dble is -1, which is outside of the range of uint8 and would be converted to 0 when you used uint8(). The other different location is 256, which is also outside of the range of uint8 and would be converted to 255 when you used uint8()
Your code contains a mistaken assumption: the assumption that if you take the wavelet coefficients of an image in the range 0 to 255, and you alter the wavelet coefficients by no more than +/- 1 in each position, that when you take the inverse wavelet transform with the resulting coefficients that the result will be strictly in the range 0 to 255.
Another way of phrasing this is you assume that every original matrix host_row that has a value outside of the range 0 to 255 will definitely result in a CA that has a value outside of that range -- because if there is an original matrix host_row that has values outside of that range that transforms into a CA that has values strictly inside the range, then the implication is that a modified CA transformed through inverse wavelet can end up having values outside of the desired range.
My tests show that is not the case: that there are simple matrices with values outside 0 to 255 that transform into a CA that has values strictly inside the range.
Simple example:
home_row = zeros(1, 568); home_row(1) = 255;
[CA, CD] = lwt(home_row, wname);
CA(1) %will be 128
CA(1) = CA(1)+1; %make it 129
back = iwt(CA, CD, wname);
back(1) %will be 256
So, although it is sometimes possible to alter the coefficients by +/- 1 and have the result of the ilwt be strictly 0 to 255, it is not always possible to do so. I do not know what the conditions are under which it can work.
4 Comments
Ashmiya Stephen
on 27 Dec 2019
I`m beginner in matlab. I used the same code for extraction and embedding process and it resulted in error. please hep me.. the error code is as follows
img=imread('frame1.jpg');
row_img=img(305,3:570);
secret='h';
secret_bin=dec2bin(secret);
disp(secret_bin);
length_secret = size(secret_bin,1)*size(secret_bin,2);
wname = liftwave('haar','int2int');
host_row=double(row_img);
[CA, CD]=lwt(host_row,wname);
length_CA = size(CA,2); c = 1;
% embedding the secret_bin in the last signficant bit of each CA ( 1 LSB of CA )
for b = 1:1:length_CA if b <= length_secret xb=CA(1,c);
if xb < 0 xb= abs(xb); if strcmp(secret_bin(b), '0') xb=bitset(xb,1,0); else xb=bitset(xb,1,1);
end
CA(1,c)=-xb;
else if strcmp(secret_bin(b), '0') CA(1,c) = bitset(CA(1,c),1,0);
else CA(1,c) = bitset(CA(1,c),1,1);
end
end% end if xb<0 c = c+ 1;
if (c > length_CA) c = 1;
end end % if b <= length_secret
end % end for loop b=8:-1:1 stego_host_uint8 = uint8(ilwt(CA,CD,wname)); stego_host_dble = (ilwt(CA,CD,wname));
% Extracting the secret vector from the stego_host_uint8 watermarked_host=double(stego_host_uint8);
[CA_ex, CD_ex] = lwt(watermarked_host,wname);
length_CA_ex = size(CA_ex,2);
c = 1; secret_bits_ex = zeros(1,length_secret);
for b = 1:1:length_CA_ex if b <= length_secret xb=CA_ex(1,c);
if xb < 0 xb= abs(xb);
end secret_bits_ex(b) = bitget(xb,1); %letter = bitset(letter,b,bitget(xb,1));
c = c + 1; end end % function i created result=secret_bits_ex; disp("extracted binary") disp(result);
a = char(bin2dec(result))
disp(a);
Walter Roberson
on 29 Dec 2019
As we do not have yur input image to test with, you will need to tell us exactly what the error message is.
PRATAP MANDAL
on 25 Dec 2020
I have tried to execute the code, but the code is not working. It is saying "undefined function or variable 'binRoundC2Dec' ". Can anybody help me in this regard ?
1 Comment
Walter Roberson
on 25 Dec 2020
It was posted in https://www.mathworks.com/matlabcentral/answers/338974-help-embedding-secret-message-using-lwt-cannot-extract-the-secret-message-correctly#comment_451639
You may need to Expand Comments
See Also
Categories
Find more on Discrete Multiresolution Analysis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!