Extracting a hidden message from an image by using LSB algorithm

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:

6 comentarios

If you just look at the image, you can see the encoded block:
inpict = imread('lsbwm.bmp');
bp = mod(inpict,2);
imshow(double(bp))
My guess based on the vector length (476b) is that the message is probably encoded in 7 bpc instead of 8. How it's arranged across channels is anybody's guess.
I don't know. I assume that the encoded block would be arranged into a single row like
bp = flipud(bp(end-1:end,:,:));
bp = [bp(1,:,:) bp(2,:,:)];
but even if that's a correct assumption, that still leaves a lot of unknowns. Is the data arranged along channels (RRRRRR...GGGGGG....BBBBBB...) or across channels (RGBRGBRGB or some other sequence)? Is it 8b per char or 7b? What's the bit order? Are we to assume that the values are ASCII? What if it's something else? What if an offset had been applied?
Just playing around with it for a few minutes, I didn't see anything obvious, but the big zero block at the beginning of the stripe makes me curious. I'm assuming that the first few bits encode something meaningful for the process of decoding.
Regarding your flag ("This is a school assignment. That's why this question should be removed."): This is a public forum. You can get help here with your homework, but you should not hand in the work of others as you own. That is academic fraud and could (and should, IMHO) get you expelled from your university.
If you posted copyrighted content, you should not have done so. You should not post things on a public forum if you are not sure if you're allowed to.
I have made a capture of this page to the Wayback Machine in case you try to vandalize it, but it seems I'm already too late.
I can confirm that my question, indeed, includes my own work, but it also contains answers of the assignment I worked on and hence, it should be removed to refrain people from copying my work.
You already gave people permission to copy your code when you posted your question:
"You agree that Content that you contribute to Discussions will be licensed under the Creative Commons Attribution Share Alike 3.0 license." [Terms of Use]
If people pass off your code as their own they are violating the attribution part of the CC license, and they are probably commiting academic fraud. Neither of the two is necessarily your problem. If you didn't want your work being public, you shouldn't have posted it.
(Answers Dev) Restored edit

Iniciar sesión para comentar.

 Respuesta aceptada

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
  1. Using a single color channel
  2. 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.

2 comentarios

Shahrin Rahman
Shahrin Rahman el 18 de Mayo de 2021
Editada: Shahrin Rahman el 21 de Mayo de 2021
Thank you again for taking a look into my problem. I appreciate it a lot that you are still helping me.
OK. Good luck. I tried that with the second half of my code where I took one bit from the red, one from the green, and one from the blue. It didn't make any sense. But maybe the bits need to be flipped from what I had, or maybe the order was BGR instead of RGB, so there are still some things you can try by adapting my code.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 16 de Mayo de 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.

5 comentarios

Shahrin Rahman
Shahrin Rahman el 16 de Mayo de 2021
Editada: Shahrin Rahman el 21 de Mayo de 2021
Thank you for the demos. I studied the demos as they were also attached by you in other steganography related question threads. Unfortunately I do not have the code that was used to hide the message. This problem is a part of my assignment.
Well you can get the LSB of an image with bitget(). See attached demo. But since it's not an image, but a text, you're going to have to take every 8 pixels (either in a row or column) and convert it to an ASCII character or a unicode character. You might have to try all 4 permutations to see which way gives sensible text. Then when you see the text stop making sense, that is probably where the hidden image ends and where the normal image values begin. I think you can do it, right?
Thank you again very much for such a broad answer. However, unfortunately I'm quite not sure how I can try the 4 permutations in my code. On the other hand, I tried to make modifications a number of times in my given code, but I still made no progress.
hello i need some help
@faiz ul amin If you have any questions, then ask them in a new discussion thread, and attach your data and code to read it in with the paperclip icon after you read this:

Iniciar sesión para comentar.

Categorías

Preguntada:

el 16 de Mayo de 2021

Comentada:

el 20 de Abr. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by