import os
def load_file(filename):
try:
with open(filename, 'rb') as file:
buffer = bytearray(file.read())
return buffer
except IOError as e:
print(f"Error opening file: {filename}")
return None
def encrypt(buffer):
for i in range(len(buffer)):
buffer[i] = (buffer[i] + 8) % 256
return buffer
def decrypt(buffer):
print("Decrypting file...")
for i in range(len(buffer)):
buffer[i] = (buffer[i] - 8) % 256
return buffer
if __name__ == '__main__':
file_path = "./112211/model_seg.dlc"
model_name=os.path.basename(file_path)
dir_name=os.path.dirname(file_path)
loaded_buffer = load_file(file_path)
if loaded_buffer is not None:
encrypted_buffer = encrypt(loaded_buffer)
with open(dir_name+f"/{model_name}.enc", 'wb') as file:
file.write(encrypted_buffer)
else:
print('load failed')
python 实现加密解密
于 2023-11-22 14:15:57 首次发布