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)