From 12b78407f3ce4d6ee5f67fb0c6ce5c754cf78a58 Mon Sep 17 00:00:00 2001 From: Iru Cai Date: Sun, 27 May 2018 13:25:10 +0800 Subject: 57, 59, 67, 206 --- euler59.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 euler59.py (limited to 'euler59.py') diff --git a/euler59.py b/euler59.py new file mode 100644 index 0000000..fe297c0 --- /dev/null +++ b/euler59.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +cipher_bytes = list(map(int, (input().split(',')))) +cipher_with_index = list(zip(range(0, len(cipher_bytes)), cipher_bytes)) + +def decrypt(key, cwi): + def dec(tup): + i, c = tup + return c^key[i%3] + + return list(map(dec, cwi)) + +def toText(t): + s = '' + for c in t: + s = s + chr(c) + return s + +def asciisum(t): + s = 0 + for c in t: + s = s + c + return s + + +def allprint(a): + for c in a: + if c >= 0x7f or c < 0x20: + return False + return True + + +key = [ord('a')] * 3 + +for key[0] in range(ord('a'), ord('z')+1): + for key[1] in range(ord('a'), ord('z')+1): + for key[2] in range(ord('a'), ord('z')+1): + decrypted = decrypt(key, cipher_with_index) + if allprint(decrypted): + print(toText(decrypted)) + print(asciisum(decrypted)) -- cgit v1.2.3