chào các bạn mình đang thực hiện đề tài giấu tin trong ảnh qua ngôn ngữ matlab, cũng tham khảo code của web nước ngoài được đoạn code giấu và tách tin, nhưng vấn đề ở chỗ khi tách tin thì phần thông điệp nhận được chỉ là chuỗi kí tự mã hóa, ai biết lỗi code chỗ nào giúp mình với
code giấu
code tách
code giấu
Code:
%reads a image into a matrix 'c'
%must be in freemat start folder
c = imread('image.bmp');
%Enter Message
message = getline('Enter a message to be embedded:');
message = strtrim(message); %trim extra 0's
%m is the length of the message in bits
m = length(message) * 8;
%Convert Message to binary vector
AsciiCode = uint8(message); %Message in Ascii int form
binaryString = transpose(dec2bin(AsciiCode,8));
binaryString = binaryString(:);
N = length(binaryString);
b = zeros(N,1); %b is a vector of bits
for k = 1:N
if(binaryString(k) == '1')
b(k) = 1;
else
b(k) = 0;
end
end
%Set Up for LSB
s = c;
height = size(c,1);
width = size(c,2);
%LSB Algorithm
%This goes to each byte, if the least significant bit is not the bit of the message position, flip it, else do nothing
k = 1;
for i = 1 : height
for j = 1 : width
LSB = mod(double(c(i,j)), 2);
if (k>m || LSB == b(k))
s(i,j) = c(i,j);
else
if(LSB == 1)
s(i,j) = c(i,j) - 1;
else
s(i,j) = c(i,j) + 1;
end
k = k + 1;
end
end
%Write image
imwrite(s, 'hiddenmsgimage.bmp');
end;
Code:
s = imread('hiddenmsgimage.bmp');
height = size(s,1);
width = size(s,2);
%For this example the max size is 100 bytes, or 800 bits, (bytes * = bits
m = 800;
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,100);
display(binMatrix);
textString = char(binValues*binMatrix);
disp(textString);

Comment