Extracting a hidden message from an image by using LSB algorithm

조회 수: 27 (최근 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.
Rena Berman
Rena Berman 2021년 6월 29일
(Answers Dev) Restored edit

댓글을 달려면 로그인하십시오.

채택된 답변

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일
@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에서 Neuromicroscopy에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by