-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolve.py
54 lines (44 loc) · 1.47 KB
/
solve.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
import png, hashlib, linecache
def loadImage(path):
reader = png.Reader(filename=path)
w, h, pixels, metadata = reader.read_flat()
byte_width = 4 if metadata['alpha'] else 3
return w, h, pixels, metadata, byte_width
def saveImage(path, pixels, w, h, metadata):
output = open(path, 'wb')
if metadata == None:
writer = png.Writer(w, h)
else:
writer = png.Writer(w, h, **metadata)
writer.write_array(output, pixels)
output.close()
def sha256(text):
return hashlib.sha256(text.encode("ascii")).hexdigest()
def processImage(pixels, byte_width, w, h, func):
for i in range(0, len(pixels), byte_width):
x = int((i/byte_width) % w)
y = int((i/byte_width) / w)
pixel = [pixels[i+j] for j in range(0,byte_width)]
func(i,x,y,pixel)
def setPixel(pixels, i, pixel):
for p in range(0, len(pixel)):
pixels[i+p] = pixel[p]
def mask(pixel, mask):
if len(pixel) == len(mask):
return [(255-pixel[i]) & int(mask[i],2) for i in range(0,len(pixel))]
else:
return None
def shiftKey(message, key):
result = []
shift = 0
for c in message:
if c == ' ':
result.append(' ')
continue
shift_amount = int(key[shift])
shift = (shift + 1) % len(key)
res = (int(c,16) - shift_amount) % 16
result.append(hex(res)[2:])
return ''.join(result)
def lookupBip36(index):
return linecache.getline('english.txt', index)[:-1]