Last active
May 21, 2018 06:58
-
-
Save crookm/3255b936812b4b46506a2f1146e1cafc to your computer and use it in GitHub Desktop.
Python program to extract the text stored in a stego image, that uses LSB row-major - requires PIL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
stream = [] | |
with open('image.png', 'rb') as img_file: | |
im = Image.open(img_file) | |
px = im.load() | |
x = 0 | |
y = 0 | |
end = False | |
while not end: | |
for pixel in px[x,y]: | |
stream.append(pixel) | |
if x+1 == im.width-1: | |
if y+1 == im.height-1: end = True | |
else: y += 1 | |
x = 0 | |
else: x += 1 | |
length = int(''.join([str(bit % 2) for bit in stream[0:31][::-1]]), 2) | |
chars = [str(bit % 2) for bit in stream[32:32+(length*8)]] # slice of the stream | |
chars = [int(''.join(chars[i:i + 8][::-1]), 2) for i in range(0, len(chars), 8)] # grouped into characters | |
print(chars) | |
print(''.join(chr(char) for char in chars)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment