2 minutes
Steganography - Recover data hidden with the “Least Significant Bit” algorithm

Taking the Pat1_.bmp file shown above and reading the file in as binary (“rb”). Seeking forward 84 bytes to skip the header information (should be 54 bytes). Using binascii.hexlify, I converted to hexadecimal and then to binary (filling in any missing or leading zeros). Looping through each binary string, I took the last bit of every byte and append that to the LSB_binary string.
When I tried to convert from binary to hex, the length of the LSB_binary string was not a multiple of 8. So I removed the last few bits to allow for the conversion to hex to occur. Doing quick research, the start and end of JPEG I found that “ffd8ff” is the usual starting hex and “ffd9” is the ending hex. Limiting my converted hex string to the start and end index of JPEG, I unhexelify the hex string. Finally, I write a new JPEG file using write binary (wb) to create the final hidden image. As shown below.
