clc;
clear variables;
len=str2double(input('Enter the length (character count) of the message you are looking for: ','s'));
len = len*8;
image_hide = imread('output.png');
[rows,columns,channels] = size(image_hide);
if channels > 1
image_hide = rgb2gray(image_hide);
end
count=1;
bitseq='';
for i=1:rows
for j=1:columns
if count<=len
LSB=mod(image_hide(i,j),2);
bitseq(count,1) = LSB;
count=count+1;
end
end
end
weights = [ 128 64 32 16 8 4 2 1 ];
message_matrix = reshape(bitseq,8,len/8);
original_message = char(weights*message_matrix);
disp(['The original message is: ',original_message]);