#!/usr/bin/env python3

from __future__ import print_function
import sys, struct

KEYLEN=2

def xor_strings(s,t):
    # https://en.wikipedia.org/wiki/XOR_cipher#Example_implementation
    """xor two strings together"""
    return b"".join(bytes([a^b]) for a,b in zip(s,t))

def read_file(fname):
    file=open(fname, mode='rb')
    content=file.read()
    file.close()
    return content

def chunks(l, n):
    """divide input buffer by n-len chunks"""
    n = max(1, n)
    return [l[i:i + n] for i in range(0, len(l), n)]

#cipher_file=read_file(sys.argv[1])
cipher_file=b"!|xan`oA|bx/ivmj -n{ofsh?/pneCxa -,>?1!.FLYNINFR@1! njs|r}Snpj#"

def is_printable(t):
    for c in t:
        if c<0x20:
            return False
        if c>=0x80:
            return False
    return True

for i in range(256):
    for j in range(256):
        possible_key=struct.pack("BB", i, j)

        tmp=chunks(cipher_file, KEYLEN)
        plain=b"".join(map(lambda x: xor_strings(x, possible_key), tmp))
        if is_printable(plain):
            print (i,j,plain)

