def decrypt(prefix): res = [] for suffix in product(letters, repeat=5 - len(prefix)): passwd = np.concatenate([prefix, suffix]) text = decode(ciphertext, passwd) if isgood(text): passwd = "".join(map(chr, passwd)) res.append((passwd, text)) return res
def decrypt(prefix): res = [] for suffix in product(letters, repeat=5-len(prefix)): passwd = np.concatenate([prefix, suffix]) text = decode(ciphertext, passwd) if isgood(text): passwd = "".join(map(chr, passwd)) res.append( (passwd, text) ) return res
import itertools from crypt import decode, letters, isgood, preprocess with open('secret.msg') as f: ciphertext = f.read() ciphertext = preprocess(ciphertext) for p in itertools.product(letters, repeat=5): text = decode(ciphertext, p) if isgood(text): passwd = "".join(map(chr, p)) print('%s:%s' % (passwd, text))
import itertools from crypt import decode, letters, isgood, preprocess ciphertext = file('secret.msg').read() ciphertext = preprocess(ciphertext) for p in itertools.product(letters, repeat=5): text = decode(ciphertext, p) if isgood(text): passwd = "".join(map(chr,p)) print '%s:%s' % (passwd, text)