-
Notifications
You must be signed in to change notification settings - Fork 0
/
challenge_07.py
79 lines (64 loc) · 2.48 KB
/
challenge_07.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# coding=utf-8
#
# --------------------------------------------------------------------------------------
from PIL import Image
import os
import challenge_00
def get_image_data(path):
im = Image.open(path)
data = im.getdata()
for item in data:
print(item)
return data
def print_lowest_bits(path):
data = get_image_data(path)
#stuff = [format(item, '#010b')[-1] for item in data] # get LSB
stuff = [str(item & 0b00000001) for item in data]
collector = []
for index in range(0, len(stuff), 8):
num = ''.join(stuff[index:index + 8])
collector.append(chr(int(num, 2)))
print(''.join(collector))
print(len(collector))
def create_white_map_template(input_01, output_01, input_02):
im01 = Image.open(input_01)
im02 = Image.open(output_01)
im03 = Image.open(input_02)
data01 = im01.getdata()
data02 = im02.getdata()
data03 = im03.getdata()
for d in data03:
print(d)
count = 0
for x, y in zip(data01, data02):
print('[{}]'.format('w' if y == (255, 255, 255, 255) else 'b'), end='')
# print(count, '[{}]'.format('white' if y == (255, 255, 255, 255) else 'black'), x, end='')
if count != 0 and count % 112 == 0:
print()
count += 1
print(count)
whites = [col01 for col01, col02 in zip(data01, data02) if col02 == (255, 255, 255, 255)]
blacks = [col01 for col01, col02 in zip(data01, data02) if col02 == (0, 0, 0, 255)]
im = Image.new(im03.mode, im03.size)
pixels = []
for index, pixel in enumerate(data03):
if pixel in whites:
pixels.append((255, 255, 255, 255))
elif pixel in blacks:
pixels.append((0, 0, 0, 255))
else:
pixels.append((127, 127, 127, 255))
im.putdata(pixels)
im.save('./challenges/challenge 7/generated_content/test.png')
# im.show()
def decrypt_message(passkey):
infile_ = os.path.abspath('./Challenges/Challenge 7/solution.txt.enc')
outfile_ = os.path.abspath('./Challenges/Challenge 7/generated_content/solution.txt')
challenge_00.decrypt_openssl(infile=infile_, outfile=outfile_, passphrase=passkey)
if __name__ == "__main__":
input_01 = './challenges/challenge 7/input1.png'
output_01 = './challenges/challenge 7/output1.png'
a = './challenges/challenge 7/input2.png'
# create_white_map_template(input_01, output_01, a)
passkey = 'hackfuwearehonouredtohavewithusarevolutionaryofadifferentcalibre'
decrypt_message(passkey)