LSB steganography : i can't extract the original messages

the code is:
embedding code:
c = imread('lena.jpg');
message = 'hellokarthick';
message = strtrim(message);
m = length(message) * 8;
AsciiCode = uint8(message);
binaryString = transpose(dec2bin(AsciiCode,8));
binaryString = binaryString(:);
N = length(binaryString);
b = zeros(N,1); %b is a vector of bits
for k = 1:N
if(binaryString(k) == '1')
b(k) = 1;
else
b(k) = 0;
end
end
s = c;
height = size(c,1);
width = size(c,2);
k = 1;
for i = 1 : height
for j = 1 : width
LSB = mod(double(c(i,j)), 2);
if (k>m || LSB == b(k))
s(i,j) = c(i,j);
else
s(i,j) = c(i,j) + b(k);
k = k + 1;
end
end
end
imwrite(s, '111.jpg');
Extraction:
for i = 1 : height
for j = 1 : width
if (k <= m)
b(k) = mod(double(s(i,j)),2);
k = k + 1;
end
end
end
binaryVector = b;
binValues = [ 128 64 32 16 8 4 2 1 ];
binaryVector = binaryVector(:);
if mod(length(binaryVector),8) ~= 0
error('Length of binary vector must be a multiple of 8.');
end
binMatrix = reshape(binaryVector,8,100);
display(binMatrix);
textString = char(binValues*binMatrix);
disp(textString);
The output is:

Answers (1)

Arjun - I suspect the problem is with the line
imwrite(s, '111.jpg');
You are saving s, the image with the secret message, as a jpeg which is a lossy compression method. This means that you are most likely losing information when you save s in this manner. You can prove this by comparing s with that data which is returned by
sp = imread('111.jpg');
s and sp are most likely not identical and so the LSB extraction method (from above) will fail.
I think that you can do one of two things - save the image as bitmap or set the compression to none as
imwrite(s,'111.jpg','Compression','none');
Try the above and see what happens!

4 Comments

Yup.
More advanced steganography mimics the way that JPEG compresses files and embeds the data in the compression coefficients and then transforms back. In this way the image produced will survive JPEG compression, provided that the Quality factor is not set lower than is accounted for.
To be robust, you need to hide a bit stream that has redundancy so that it can be reconstructed if it gets corrupted. Error Correcting Codes (ECC) are used for this purpose. See Forward Error Correction.
Good steganography accounts for the possibility of the image being resized, and accounts for possibilities like the image to be decoded being a photograph (or screen capture) of the image that has the hidden information.
its not working... its error...
i also try with .bmp format... i extracted text is unreadable...
Use 'mode', 'lossless' on the imwrite() instead of 'Compression', 'none'.

Sign in to comment.

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Asked:

on 16 May 2015

Commented:

on 17 May 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!