Question

I read about LSB insertion online, but it only introduces about how to insert bits to LSB, but it didn't describe how to extract the bits. This is the article I read about LSB insertion.

I understand the method they use below, but how do you extract the bits?

Was it helpful?

Solution

Here's an algorithm for getting the encrypted message:

  1. Read image.
  2. Iterate over pixels.
  3. Decompose pixel into RGB values (one byte for R, one for G, one for B)
  4. 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
  5. Get the LSB from green. Place this in the next highest bit.
  6. Get the LSB from blue. Place this in the next bit down.
  7. Read the next pixel and decompose into RGB bytes.
  8. 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.
  9. Continue iterating over pixels and their RGB values until you've processed all pixels.
  10. 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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top