def xor_cipher(input_file, output_file, key): """ファイルを簡易的に暗号化・復号化する関数 Args: input_file (str): 読み込むファイル名 output_file (str): 書き出すファイル名 key (int): 暗号化キー(0〜255の整数) """ # 鍵を1バイトのデータに変換 key_byte = bytes([key]) with open(input_file, "rb") as f_in: data = f_in.read() # 各バイトに対してXOR(排他的論理和)を適用 processed_data = bytearray(b ^ key_byte[0] for b in data) with open(output_file, "wb") as f_out: f_out.write(processed_data)