a.py 679 B

12345678910111213141516171819202122
  1. def xor_encrypt_decrypt(input_file, output_file, key):
  2. with open(input_file, 'rb') as f:
  3. data = f.read()
  4. # 对文件内容执行异或操作
  5. encrypted_data = bytes([byte ^ key for byte in data])
  6. # 将处理后的内容写回文件或者保存到新文件中
  7. with open(output_file, 'wb') as f:
  8. f.write(encrypted_data)
  9. # 要处理的文件
  10. input_file = 'index2.html'
  11. # 输出文件
  12. output_file = 'index3.html'
  13. # 异或操作的密钥
  14. key = 0x12 # 例如,使用十六进制密钥
  15. # 执行异或操作
  16. xor_encrypt_decrypt(input_file, output_file, key)
  17. print("文件已加密/解密并保存到", output_file)