%
%  Least Significant Bit Steganography
%  
%  Takes in two filenames and their formats 
% 
%  This works on two images of same pixel resolution
%  and hides the secret image in other image designated
%  as the cover image by substituting the LSB 
%  of the cover image with the MSB of the secret image
%
%  This is explained in the documentation section
%
function lsb_stego(origfile, orig_fmt, stegofile, stego_fmt, number_bits)

% original image i.e the cover image
imorig  = imread(origfile,  orig_fmt);
imstego = imread(stegofile, stego_fmt);

% number of bits to susbtitute
n = number_bits;


% this image matrix contains the number of
% lsb bits specified by n removed from
% each of its pixels. see removelsb for 
% implementation
tmp_matrix = removelsb(imorig, n);

% uint8 images to be converted to double for
% operations on them
tmp_matrix = double(tmp_matrix);

% hide the secret image inside in the removed LSB
% bits of the original image
stego     = (tmp_matrix + double(imstego) / 2^(8 - n));
stego     = uint8(stego);


% show the original image, the secret image
% and the original image after its modified
% to contain the secret image
figure; 
subplot(2,2,1);imshow(imorig);
subplot(2,2,3);imshow(imstego);
subplot(2,2,2);imshow(stego);

% extract process is simple
% we just need to throw away 
% the top 8-n bits of the pixel
% so bitshift will help us here
stego = bitshift(stego, 8-n);
extracted = uint8(stego);
subplot(2,2,4);imshow(extracted);

