import string keys = [] for a in string.lowercase: for b in string.lowercase: for c in string.lowercase: keys.append(a+b+c) f = open('059.txt', 'r') content = f.read().split(',') f.close() cipher = [ int(i) for i in content ] cipher_len = len(cipher) for key in keys: decoded = "" for p in range(0, cipher_len): decoded += chr(cipher[p] ^ ord(key[p%3])) if decoded.find(" the ") != -1 and decoded.find(" and ") != -1: break #print decoded #print key print sum([ ord(x) for x in decoded ])