-
Notifications
You must be signed in to change notification settings - Fork 0
/
_059.py
40 lines (31 loc) · 944 Bytes
/
_059.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
import re
common_english = re.compile("[a-zA-Z0-9\.,\"/+()\[\];':]|\s")
f = open("./inputs/_059", "r")
codes = list(map(int, f.read().split(",")))
len_codes = len(codes)
bucket1 = list(map(lambda x: codes[x], range(0, len_codes, 3)))
bucket2 = list(map(lambda x: codes[x], range(1, len_codes, 3)))
bucket3 = list(map(lambda x: codes[x], range(2, len_codes, 3)))
def find_key(bucket):
key_start = 97
key_end = 122
for k in range(key_start, key_end + 1):
found = True
for c in bucket:
if common_english.match(chr(c ^ k)) == None:
found = False
break
if found:
return chr(k)
key1 = find_key(bucket1)
key2 = find_key(bucket2)
key3 = find_key(bucket3)
key_final = key1 + key2 + key3
pwd = key_final * 485
msg = ""
ans = 0
for i in range(len(codes)):
msg += chr(ord(pwd[i]) ^ codes[i])
ans += ord(pwd[i]) ^ codes[i]
print(msg)
print(ans)