Here's an algorithm for getting the encrypted message:
- Read image.
- Iterate over pixels.
- Decompose pixel into RGB values (one byte for R, one for G, one for B)
- Take the LSB from red. If the LSB is in bit zero, you can
AND
the red value with a mask of 1 (bits 000000001). So,lsbValue = rvalue & 0x01
. Place the lsbValue (it will only be one or zero) in the highest bit - Get the LSB from green. Place this in the next highest bit.
- Get the LSB from blue. Place this in the next bit down.
- Read the next pixel and decompose into RGB bytes.
- Stuff the LSB of the color components into bit positions until you've filled a byte. This is the first byte of your encrypted mesage.
- Continue iterating over pixels and their RGB values until you've processed all pixels.
- Inspect the bytes you've decrypted. The actual message should be obvious. Anything beyond the encrypted message will just be noise, i.e, the LSB of the actual image pixels.