-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecode.py
45 lines (43 loc) · 1.45 KB
/
decode.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import sys
import os
from PIL import Image
def decodeImage():
image = Image.open(image_name)
pixels = image.load()
width = image.size[0]
height = image.size[1]
data = ""
for y in range(height):
for x in range(width):
pixel = pixels[x, y]
red = pixel[0]
green = pixel[1]
blue = pixel[2]
data += bin(red)[7]
data += bin(green)[7]
data += bin(blue)[7]
data = [data[i:i+8] for i in range(0, len(data), 8)]
decoded_data = ""
test_data = ""
for byte in data:
if byte != "00000000" and byte != "0000000" and byte != "000000" and byte != "00000" and byte != "0000" and byte != "000" and byte != "00" and byte != "0":
test_data += chr(int(byte, 2))
if test_data[-11:] == "[ENDOFDATA]":
test_data = test_data[:-11]
break
else:
charlist = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_+{}|:"<>?`~-=[]\;\',./ '
if str(chr(int(byte, 2))) in charlist:
decoded_data += str(chr(int(byte, 2)))
else:
pass
else:
break
decoded_data = decoded_data[:-10]
print(decoded_data)
file_name = input("Enter the name of the file including the extension: ")
file_type = file_name.split('.')[1]
if file_type == "png":
decodeImage()
else:
print('Error')