steganography Algorithm

Steganography is a cryptographic technique that involves hiding secret information within seemingly innocuous digital files such as images, audio, or video. The primary goal of steganography is to ensure that the hidden information remains undetectable to anyone who is not the intended recipient. One of the most popular steganography algorithms is the Least Significant Bit (LSB) algorithm, which exploits the concept of modifying the least significant bits of the digital data to embed the secret information in a way that does not noticeably affect the host file. The LSB algorithm works by replacing the least significant bits of the host file's data with bits from the secret information. In the case of images, for example, the algorithm can modify the color values of individual pixels, which are typically represented as 8-bit numbers in the RGB color space. By changing just the least significant bit of each pixel, the algorithm can embed the secret information without significantly altering the appearance of the image. Similarly, for audio and video files, the algorithm can modify the least significant bits of the sample values or video frames to incorporate the secret message. The key advantage of the LSB algorithm is its simplicity and effectiveness in concealing the hidden information while maintaining the quality of the host file. However, the method is susceptible to attacks such as statistical analysis, which may reveal the presence of hidden information if not carefully implemented.
clc;
clear variables;
% Load the image and convert to grayscale if it is RGB
I=imread('input.png');
[rows, columns, numberOfColorChannels] = size(I);
if numberOfColorChannels > 1
    I = rgb2gray(I);
end
L=256;
image_hide=I;

message=input('Please enter the message you want to hide: ','s');
% Each character occupies a byte, so total bits can be found by multiplying
% string length by 8
len=strlength(message)*8; 
ascii_values=uint8(message);   
ascii2binary=dec2bin(ascii_values,8);

% Append all binary equivalents of ascii values into one string
binary_sequence='';  
for i=1:strlength(message)
    binary_sequence=append(binary_sequence,ascii2binary(i,:));
end

% To track how many bits of message have been hidden
bitCount=1;

for i=1:rows
    for j=1:columns
        
        if bitCount<=len
            %Obtain the LSB of the grey level of the pixel
            LSB=mod(I(i,j),2);
            
            %Convert the bit from the message to numeric form
            a=str2double(binary_sequence(bitCount));

            %Perform XOR operation between the bit and the LSB
            temp=double(xor(LSB,a));
            
            %Change the bit of the image_hide accordingly
            image_hide(i,j)=I(i,j)+temp;
            
            bitCount=bitCount+1;
        end
    end
end

subplot(1,2,1);
imshow(I);
title('Input Image');

subplot(1,2,2);
imshow(image_hide);
title('Image with Hidden Data');

imwrite(image_hide,'output.png')

LANGUAGE:

DARK MODE: