LSB Steganography: by Tejasram (A046) & Soham Nanavati (A039)
LSB Steganography: by Tejasram (A046) & Soham Nanavati (A039)
The word steganography is derived from a Greek words Steganos- “covered” and graphia- “Writing”.
Steganography is to hide messages in such a way no one apart from the intended recipient knows the existence of
the message.
This can be achieved by concealing existence of information within seemingly harmless carriers or covers ( text,
image, video, etc)
Steganography is different from cryptography. Cryptography involves creation of ciphers while steganography
hides messages.
FLOWCHART FOR LSB STEGANOGRAPHY
ALGORITHM
Algorithm to embed the text message:-
Step 1: Read the cover image and the text message which is to be hidden in the cover image.
Step 2: Convert the text message in binary format.
Step 3: Calculate the LSB of each pixel of the cover image.
Step 4: Replace the cover image of the LSB with each bit of secret message one by one.
Step 5: Write stego image
Step 6: Calculate the Mean square Error (MSE) and the Peak signal to noise ratio (PSNR) of the stego image.
Algorithm to retrieve text message:-
Step 1: Read the stego image.
Step 2: Calculate LSB of each pixels of stego image.
Step 3: Retrieve bits and convert each 8 bit into character.
ENCODE FILE
clc
im1 = imread('image.png');
message = fileread('message.txt');
message_binary = reshape(dec2bin(message, 8)', 1, []);
message_size = length(message_binary);
[l,w,b] = size(im1);
cover_size = l*w*b
if (message_size > cover_size)
disp('Message too large for image.');
end
ENCODE FILE
im2 = im1;
i = 1; j = 1; k=1;
for a = 1 : length(message_binary)
if (k > 3)
k = 1;
j = j + 1;
end
if (j > w)
i = i + 1;
j = 1;
end
ENCODE FILE
imwrite(im2, 'stego.png');
figure;
subplot(1,2,1), imshow(im1), title('Original Image');
subplot(1,2,2), imshow(im2), title('Secret Image');
OUTPUT- ENCODE FILE
DECODE FILE
delimiter = '%';
clc
im1 = imread('stego.png');
% figure(1), imshow(im1); title('Original Image');
[l,w,b] = size(im1);
cover_size = l*w*b;
message = '';
char_stream = '';
i = 1; j = 1; k=1;
DECODE FILE
while (true)
if (k > 3)
k = 1;
j = j + 1;
end
if (j > w)
i = i + 1;
j = 1;
end
if (i > l)
break;
end
DECODE FILE
temp_pixel = dec2bin(im1(i, j, k), 8);
LSB = temp_pixel(8);
char_stream = strcat(char_stream, num2str(LSB));
if length(char_stream) == 8
new_char = char(bin2dec(char_stream));
message = horzcat(message, new_char);
if (new_char == delimiter)
break;
end
char_stream = '';
end
k = k + 1;
DECODE FILE
secret_file = fopen('secret.txt','wb');
fwrite(secret_file, message);
fclose(secret_file);
disp(message);
OUTPUT- DECODE FILE
APPLICATIONS
https://www.mathworks.com/matlabcentral/fileexchange/41326-steganography-using-lsb-substitution
Research paper by Rahul Joshi, Lokesh Gagani, Saloney pandey. Published in IJARCET
http://ijarcet.org/wp-content/uploads/IJARCET-VOL-2-ISSUE-1-228-229.pdf
Research paper by Champakamala .B.S, Padmini.K, Radhika .D. K . Published in IJACT
http://ijact.org/volume3issue4/IJ0340004.pdf