import os
def decrypt(data, bytes_str):
# Initialize v4
v4 = 0xD7
# Process the bytes string
for char in bytes_str:
v4 ^= ord(char)
# Initialize v8 as a list of integers from data
v8 = list(data)
length = len(data)
# Decryption loop
for j in range(length, 0, -1):
v8[0] ^= v4
v4 = (j + v4) & 0xFF # Simulate 8-bit overflow
v10 = (2 * v4) & 0xFF
v10 = ((v4 & 0x80) >> 7) | v10
v4 = v10
v8 = v8[1:] + [v8[0]] # Rotate the first element to the end
# Print the decrypted data
for k in range(len(v8)):
print(f"0x{v8[k]:02x}, ", end="")
if k % 8 == 7:
print()
return bytes(v8)
# 从文件读取数据
def read_file(filename):
with open(filename, 'rb') as file:
data = file.read()
return data
# 将数据写入文件
def write_file(filename, data):
with open(filename, 'wb') as file:
file.write(data)
def decrypt_files_in_folder(folder_path):
for filename in os.listdir(folder_path):
input_filename = os.path.join(folder_path, filename)
if os.path.isfile(input_filename):
output_filename = os.path.splitext(input_filename)[0] + ".decrypted"
bytes_str = filename.lower()
data = read_file(input_filename)
decrypted_data = decrypt(data, bytes_str)
write_file(output_filename, decrypted_data)
decrypt_files_in_folder(".\\")
input()