diff --git a/src/Python/Problem059.py b/src/Python/Problem059.py index 928e59a..8df65f6 100644 --- a/src/Python/Problem059.py +++ b/src/Python/Problem059.py @@ -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__":