crzcas

decoding message

Jan 2nd, 2021 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. #Import Image module from PIL library
  2. from PIL import Image
  3.  
  4. #Path to image containing message here
  5. image = Image.open('encoded_image.png')
  6.  
  7. #Convert to RGB
  8. rgb_image = image.convert('RGB')
  9.  
  10. #Assign the image width and height to variables
  11. width, height = image.size
  12.  
  13. i = 0
  14.  
  15. output_bits = ""
  16. output_text = ""
  17.  
  18. #Set up loops to address each pixel in the image
  19. for row in range(height):
  20.     for col in range(width):
  21.       r, g, b = rgb_image.getpixel((col, row))
  22.       bin_r = bin(r)
  23.      
  24.      
  25. end = False
  26. while end == False:
  27.     byte = int(output_bits[:8],2)
  28.     print(byte)
  29.     if byte == 0:
  30.         end = True
  31.     else:
  32.         output_text = output_text + chr(byte)
  33.         output_bits = output_bits[8:]
  34.  
  35. print(output_text)      
Add Comment
Please, Sign In to add comment