How to write a C Program to BUILDS A STRING FROM THE LSB BITS OF EACH PIXEL in C Programming Language ?
This C Program BUILDS A STRING FROM THE LSB BITS OF EACH PIXEL.
Solution:
- // Revelation core, returns a message with the secret content of the image
- // SINGLE CHANNEL (R), SINGLE BIT PER CHANNEL, NO MAGIC NUMBER.
- // SIMPLY BUILDS A STRING FROM THE LSB BITS OF EACH PIXEL.
- message reveal(const char *img){
- int i,j;
- RGBQUAD pixel;
- FIBITMAP *image1= open_image(TESTIMAGE);
- unsigned w,h;
- int end = 0; //use as flag when found magic number, if not updated we reveal all the pixels
- w = FreeImage_GetWidth(image1);
- h = FreeImage_GetHeight(image1);
- int len = (h*w/8);
- message m; // message is struct{ char chars[]; }
- m.chars= (char*)malloc(sizeof(char)*len);
- char bits[h*w];
- couple indexes;
- unsigned char tmp;
- int n = 0, b=0;
- for (i=0; i<h; i++){
- for (j=0; j<w; j++){
- if(b%8==0)b=0;
- indexes = mindex_direct(n,w,h); //returns couple (x,y) of n-th pixel in Direct order
- if(readBit(image1,indexes,0))
- m.chars[n/8] = set_bit(m.chars[n/8],7-b);
- else
- m.chars[n/8] = unset_bit(m.chars[n/8],7-b);
- n++;
- b++;
- }
- }
- }