-
Notifications
You must be signed in to change notification settings - Fork 1
/
encode.m
45 lines (37 loc) · 985 Bytes
/
encode.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
c = imread('[YOUR_PATH_HERE]\images\earth.bmp'); %The path for the grayscale bmp cover image
id = fopen('[YOUR_PATH_HERE]\secret_message.txt', 'r');
spec = '%c';
message = fscanf(id,spec);
m = length(message) * 8;
% Message in Ascii int form
ascii = uint8(message);
binary = transpose(dec2bin(ascii,8));
binary = binary(:);
LSB=0;
num = length(binary);
b = zeros(num,1); %b is a vector of bits
for k = 1:num
if(binary(k) == '1')
b(k) = 1;
else
b(k) = 0;
end
end
s = c;
height = size(c,1);
width = size(c,2);
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
s(i,j)=c(i,j)+b(k) -LSB;
end
k = k + 1;
end
end
% Write image
disp('Done encoding message');
imwrite(s,'[YOUR_PATH_HERE]\encodedImg.bmp','bmp'); %write the new image with the hidden image in it to 's' or disk.