Solution to problem 59
This commit is contained in:
parent
fb090995d6
commit
dff609f634
@ -9,6 +9,8 @@ Solution for problem 59 of Project Euler
|
||||
https://projecteuler.net/problem=59
|
||||
"""
|
||||
|
||||
from itertools import permutations
|
||||
from string import ascii_lowercase
|
||||
from utils import timeit
|
||||
|
||||
|
||||
@ -43,7 +45,21 @@ def compute():
|
||||
values in the original text.
|
||||
"""
|
||||
|
||||
# Your code goes here
|
||||
with open('../files/Problem59.txt', 'r') as f:
|
||||
# encrypted = list(map(int, f.read().split(',')))
|
||||
encrypted = [int(char) for char in f.read().split(',')]
|
||||
# print(encrypted)
|
||||
# print(test)
|
||||
plain_text = len(encrypted) // 3
|
||||
for key in permutations(ascii_lowercase, 3):
|
||||
decrypted = ""
|
||||
for k, i in zip(list(key) * plain_text, encrypted):
|
||||
decrypted += chr(ord(k) ^ i)
|
||||
|
||||
# assuming Euler will be in the text
|
||||
if 'Euler' in decrypted:
|
||||
return sum([ord(c) for c in decrypted])
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
x
Reference in New Issue
Block a user