#!/usr/bin/env python3

import sys

def decrypt(fp):
    try:
        with open(fp, "rb") as f:
            key = bytes([(x & 0x7f) ^ 0x42 for x in f.read(0x20)])
            contents = f.read()

        out = b""

        for i in range(len(contents)):
            out += bytes([contents[i] ^ key[i % 0x20]])

        #print(out)
        with open('out', "wb") as f:
            f.write(out)
    except FileNotFoundError as e:
        print(f"failed to find file {fp}")

def main(argv):
    if len(argv) == 1:
        print(f"usage: {argv[0]} [enc file [enc file [enc file [...]]]]")
        return 1

    for fp in argv[1:]:
        decrypt(fp)

    return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv))
