Extracting a hidden message from an image by using LSB algorithm

51 次查看(过去 30 天)
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 个评论
Rik
Rik 2021-6-1
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.

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2021-5-18
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 个评论
Shahrin Rahman
Shahrin Rahman 2021-5-18
编辑:Shahrin Rahman 2021-5-21
Thank you again for taking a look into my problem. I appreciate it a lot that you are still helping me.
Image Analyst
Image Analyst 2021-5-20
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.

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2021-5-16
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 个评论
Image Analyst
Image Analyst 2024-4-20,12:21
@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:

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by