#!/usr/bin/env python def xor(data, key): keylen = len(key) return bytearray(( (data[i] ^ key[i % keylen]) for i in range(0,len(data)) )) if __name__ == "__main__": data = bytearray(open('topsecret.txt', 'rb').read()) key = b'key' res = xor(data, key) print(res.decode())