23 views (last 30 days)

Show older comments

I have an image that has a hidden message embedded in it, which should be extracted by using the LSB algorithm. However, the extracted hidden message that I obtained through the attached code does not make sense. It would be appreciated if anyone could point out what I am doing wrong here.

I used the following code to extract the hidden message:

s = imread('image_result.bmp');

height = size(s,1);

width = size(s,2);

m = double( s(1:1:1) ) * 8 ;

k = 1;

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,[]);

textString = char(binValues*binMatrix);

disp(textString);

And the extracted message that I got:

Image Analyst
on 18 May 2021

It looks like the hidden message is encoded into the last two rows of the image:

I tried a couple of ways of decoding it

- Using a single color channel
- Using all 3 color channels.

clc; % Clear command window.

clear; % Delete all variables.

close all; % Close all figure windows except those created by imtool.

workspace; % Make sure the workspace panel is showing.

powerOf2Values = [128 64 32 16 8 4 2 1];

rgbImage = imread('image_result.bmp');

nexttile

imshow(rgbImage, [], 'InitialMagnification', 800);

axis('on', 'image');

[r, g, b] = imsplit(rgbImage);

r2 = mod(r, 2);

nexttile

imshow(r2, [], 'InitialMagnification', 800);

axis('on', 'image');

g2 = mod(g, 2);

nexttile

imshow(g2, [], 'InitialMagnification', 800);

axis('on', 'image');

b2 = mod(g, 2);

nexttile

imshow(b2, [], 'InitialMagnification', 800);

axis('on', 'image');

% Get last 2 lines of each channel

last2LinesR = r2(end-1:end, :);

last2LinesG = g2(end-1:end, :);

last2LinesB = b2(end-1:end, :);

%-------------------------------------------------------------------

% Try to (guess at) extract message from a single color channels

% Reshape into one long row vector

last2LinesR = reshape(last2LinesR, 1, []);

% Reshape into one long column vector

% last2Lines = reshape(last2Lines, [], 1);

% Reshape into an N-by-8 matrix where each row is an character value.

last2LinesR = reshape(last2LinesR, [], 8)

for row = 1 : size(last2LinesR, 1)

thisRow = double(last2LinesR(row, :));

value = thisRow .* powerOf2Values;

asciiValue(row) = uint16(sum(value));

end

asciiValue

fprintf('------------------------------------------------------------\n');

fprintf('%c', asciiValue);

fprintf('\n');

fprintf('------------------------------------------------------------\n');

%-------------------------------------------------------------------

% Try to (guess at) extract message from all 3 channels

% Reshape into one long row vector

last2LinesR = reshape(last2LinesR, 1, []);

last2LinesG = reshape(last2LinesG, 1, []);

last2LinesB = reshape(last2LinesB, 1, []);

% Stack vertically

m = [last2LinesR; last2LinesG; last2LinesB];

% Reshape into one long row vector

m = reshape(m, 1, []);

% Reshape into an N-by-8 matrix where each row is an character value.

last2LinesR = reshape(m, [], 8)

for row = 1 : size(last2LinesR, 1)

thisRow = double(last2LinesR(row, :));

value = thisRow .* powerOf2Values;

asciiValue(row) = uint16(sum(value));

end

asciiValue

fprintf('------------------------------------------------------------\n');

fprintf('%c', asciiValue);

fprintf('\n');

fprintf('------------------------------------------------------------\n');

Neither way seems to produce a sensible message so I must now be guessing the correct way to decode it. Are you sure you don't know it either? We could spend hours guessing.

Image Analyst
on 20 May 2021

Image Analyst
on 16 May 2021

Maybe you're not extracting the hidden message in the proper way for the way that they hid it in the image. Do you have the code that was used to hide the watermark message in the cover image?

I'm attaching two demos for you to study and adapt if you want.

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

Start Hunting!