import sys

# Try XOR decryption with various keys
def xor_decrypt(data, key):
    key_bytes = key.encode() if isinstance(key, str) else key
    result = bytearray()
    for i, byte in enumerate(data):
        result.append(byte ^ key_bytes[i % len(key_bytes)])
    return bytes(result)

# Read encrypted file
with open('clients_information.xlsx.enc', 'rb') as f:
    encrypted = f.read()

# Try common keys
common_keys = [
    '20yk',
    'secret',
    'password',
    'key',
    'infected',
    'FLAG',
    'HTB',
]

for key in common_keys:
    decrypted = xor_decrypt(encrypted, key)
    # Check if it starts with PK (ZIP header for xlsx)
    if decrypted[:2] == b'PK':
        print(f"Key found: {key}")
        with open('clients_information.xlsx', 'wb') as f:
            f.write(decrypted)
        print("File decrypted successfully!")
        sys.exit(0)

print("No key found in common list. Searching memory dump...")
