Can someone help me with my project based on image steganography in C language only. I need to use Least significant bit algorithm to hide the user data into a BMP image. I know what the algorithm is but i am not getting how to implement it.
Please help me to encrypt the data into a BMP image using LSB technique in C language.
LSB algo:
The letter 'A' has an ASCII code of 65(decimal),
which is 01000001 in binary.
It will need three consecutive pixels for a
24-bit image to store an 'A':
Let's say that the pixels before the insertion are:
R G B
P1-10000000.10100100.10110101,
P2-10110101.11110011.10110111,
P3-11100111.10110011.00110011
Then their values after the insertion of an 'A' will be:
10000000.10100101.10110100,
10110100.11110010.10110110,
11100110.10110011.00110011
What I have tried:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
long asciiToBinary(int n);
long asciiToBinary(int n) {
int remainder;
long binary = 0, i = 1;
while(n != 0) {
remainder = n%2;
n = n/2;
binary= binary + (remainder*i);
i = i*10;
}
return binary;
}
typedef struct {
unsigned int width;
unsigned int height;
unsigned int size;
} BITMAPINFOHEADER;
typedef struct {
unsigned char blue;
unsigned char green;
unsigned char red;
} PIXEL;
int main(){
FILE *image;
char fpath[1000],mydata[100];
BITMAPINFOHEADER bih;
int i=0,b[8],g[8],r[8];
double asciiTobinary;
printf("Enter BMP file path");
scanf("%s",fpath);
image=fopen(fpath,"rb");
while(image==NULL){
printf("Error! Enter path again:");
scanf("%s",fpath);
}
fseek(image,2,SEEK_SET); fread(&bih.size,4,1,image);
printf("\n \n Size of the image=%d\n",bih.size);
fseek(image,18,SEEK_SET);
fread(&bih.width,4,1,image);
fseek(image,22,SEEK_SET);
fread(&bih.height,4,1,image);
printf("\n \n Width of the image =%d \n Height of the image =%d \n pixel = b | g | r \n \n",bih.width,bih.height);
PIXEL pic[bih.width*bih.height*2],p;
while(!feof(image)){ fread(&p.blue,sizeof(p.blue),1,image);
fread(&p.green,sizeof(p.green),1,image);
fread(&p.red,sizeof(p.red),1,image);
pic[i]=p;
printf(" %d= %u | %u | %u ",i+54,pic[i].blue,pic[i].green,pic[i].red);
i++;
}
fclose(image);
return 0;
}