Skip to content

Instantly share code, notes, and snippets.

@UserUnknownFactor
Created May 2, 2025 08:39
Show Gist options
  • Save UserUnknownFactor/e330bcff8b84ac6f86a822939d149ce4 to your computer and use it in GitHub Desktop.
Save UserUnknownFactor/e330bcff8b84ac6f86a822939d149ce4 to your computer and use it in GitHub Desktop.

Revisions

  1. UserUnknownFactor created this gist May 2, 2025.
    34 changes: 34 additions & 0 deletions key_xor_files_by_ext.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    import os
    import numpy as np
    import re

    def xor_files(key_string, extension=".txt", prefix="dec_", bytes_required=6):
    key_bytes = bytes([int(x, 16) for x in key_string.split()])
    #assert len(key_bytes) == bytes_required, f"Key must be exactly {bytes_required} bytes"

    # Get all files in the current directory
    all_files = [f for f in os.listdir() if f.lower().endswith(extension)]

    for filename in all_files:
    print(f"Processing {filename}...")

    with open(filename, 'rb') as f:
    data = np.frombuffer(f.read(), dtype=np.uint8)

    # Create the key array and repeat it to match the data length
    key_array = np.array(list(key_bytes), dtype=np.uint8)
    repeats = len(data) // len(key_array) + 1
    full_key = np.tile(key_array, repeats)[:len(data)]

    result = np.bitwise_xor(data, full_key)

    output_filename = f"{prefix}{filename}"
    with open(output_filename, 'wb') as f:
    f.write(result.tobytes())

    print(f"Created {output_filename}")

    # Example usage
    if __name__ == "__main__":
    key = "AA BB CC DD EE FF"
    xor_files(key)