Day 20

A Python Image Stenography for Decrypting Messages

Unfortunately, you can't run this in the browser here

This program reads from the filesystem, so it must be run locally — it cannot run in the browser.

Run python main.py in a directory that contains at least one image file with encrypted message inside.


Description


This is a stenography tool that decrypts messages hidden in photos that was written in the previous day.

View the source code


from PIL import Image
photo_name = "photo.png"
img = Image.open(photo_name)
pixels = img.load()
width,height = img.size
message = ""
for y in range(height):
 for x in range(width):
  binary_data = ""
  r,g,b = pixels[x,y]
  bit = b & 1
  binary_data += str(bit)
  if len(binary_data) == 8:
   char_code = int(binary_data,2)
   if char_code == 0:
    print(message)
    break
   message += chr(char_code)
print(message)

Previous Day
Next Day