def break_repeating_key_XOR(x, k): blocks = [x[i:i+k] for i in range(0, len(x), k)] transposed_blocks = list(itertools.zip_longest(*blocks, fillvalue=0)) key = [break_single_byte_XOR(bytes(x))[0] for x in transposed_blocks] return bytes(key)
def f(filename=None): decoded_lines = [binascii.unhexlify(lines.strip()) for lines in open(filename).readlines()] best_text = [break_single_byte_XOR(i)[1] for i in decoded_lines] # index tuple return max(best_text, key=score)