-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecode.py
More file actions
30 lines (27 loc) · 862 Bytes
/
decode.py
File metadata and controls
30 lines (27 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from PIL import Image
import sys
def decode_image(img):
"""
check the red portion of an image (r, g, b) tuple for
hidden message characters (ASCII values)
"""
width, height = img.size
msg = ""
index = 0
for row in range(height):
for col in range(width):
try:
r, g, b = img.getpixel((col, row))
except ValueError:
# need to add transparency a for some .png files
r, g, b, a = img.getpixel((col, row))
# first pixel r value is length of message
if row == 0 and col == 0:
length = r
elif index <= length:
msg += chr(r)
index += 1
return msg
image = Image.open(sys.argv[1])
decoded_text = decode_image(image)
print("your hidden message is:\n{}".format(decoded_text))