BUILDS A STRING FROM THE LSB BITS OF EACH PIXEL

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:

  1. // Revelation core, returns a message with the secret content of the image
  2. // SINGLE CHANNEL (R), SINGLE BIT PER CHANNEL, NO MAGIC NUMBER.
  3. // SIMPLY BUILDS A STRING FROM THE LSB BITS OF EACH PIXEL.
  4. message reveal(const char *img){
  5.     int i,j;
  6.     RGBQUAD pixel;
  7.     FIBITMAP *image1= open_image(TESTIMAGE);
  8.     unsigned w,h;
  9.     int end = 0; //use as flag when found magic number, if not updated we reveal all the pixels
  10.     w = FreeImage_GetWidth(image1);
  11.     h = FreeImage_GetHeight(image1);
  12.     int len = (h*w/8);
  13.     message m;  // message is struct{ char chars[]; }
  14.     m.chars= (char*)malloc(sizeof(char)*len);
  15.     char bits[h*w];
  16.     couple indexes;
  17.     unsigned char tmp;
  18.     int n = 0, b=0;
  19.  
  20.     for (i=0; i<h; i++){
  21.         for (j=0; j<w; j++){    
  22.             if(b%8==0)b=0;
  23.             indexes = mindex_direct(n,w,h);  //returns couple (x,y) of n-th pixel in Direct order
  24.             if(readBit(image1,indexes,0))
  25.                 m.chars[n/8] = set_bit(m.chars[n/8],7-b);
  26.             else
  27.                 m.chars[n/8] = unset_bit(m.chars[n/8],7-b);
  28.             n++;
  29.             b++;
  30.         }
  31.     }
  32. }


Learn More :