-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP059.py
More file actions
82 lines (60 loc) · 2.11 KB
/
P059.py
File metadata and controls
82 lines (60 loc) · 2.11 KB
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
80
81
82
import eulertools as et
from eulertools import timeit
"""
0 = 1,1 - 1
1 = 2,3 - 3 5 7 9
2 = 4,5 - 13 17 21 25
3 = 6,7 - 31 37 43 49
"""
def encrypt(array, key):
e = []
for i in range(0, len(array)):
e.append(chr(array[i] ^ int(key[i % len(key)])))
return e
def cipher():
with open(r'C:\Code\Euler\p059_cipher.txt') as f:
y = f.read()
cipher_list = [int(i) for i in y.split(',')]
return cipher_list
def trial_code():
cipher_list = cipher()
cipher_list_1 = [b for a, b in enumerate(cipher_list) if a % 3 == 0]
cipher_list_2 = [b for a, b in enumerate(cipher_list) if a % 3 - 1 == 0]
cipher_list_3 = [b for a, b in enumerate(cipher_list) if a % 3 - 2 == 0]
lower_case_letters = list(range(97,123))
length_l = len(cipher_list_1)
print(length_l)
for lower_case_letter in lower_case_letters:
t = sum((32 <= lower_case_letter ^ c <= 90) or (97 <= lower_case_letter ^ c <= 122) for c in cipher_list_1)
length_l = len(cipher_list_1)
if t == length_l:
print(t,chr(lower_case_letter))
length_l = len(cipher_list_2)
print(length_l)
for lower_case_letter in lower_case_letters:
t = sum((32 <= lower_case_letter ^ c <= 90) or (97 <= lower_case_letter ^ c <= 122) for c in cipher_list_2)
length_l = len(cipher_list_2)
if t > 470:
print(t,chr(lower_case_letter))
length_l = len(cipher_list_3)
print(length_l)
for lower_case_letter in lower_case_letters:
t = sum((32 <= lower_case_letter ^ c <= 90) or (97 <= lower_case_letter ^ c <= 122) for c in cipher_list_3)
length_l = len(cipher_list_3)
if t > 470:
print(t,chr(lower_case_letter))
@timeit
def problem():
cipher_list = cipher()
key = [ord('e'), ord('x'), ord('p')]
message = encrypt(cipher_list, key)
print(''.join(message))
print(sum(ord(x) for x in message))
if __name__ == "__main__":
print(problem())
# trial_code()
# print(corner_values(0))
# print(corner_values(1))
# print(corner_values(2))
# print(corner_values(3))
# print(corner_values(4))