import hashlib import json def hash_filename(filename): hash_object = hashlib.sha256(filename.encode()) hex_dig = hash_object.hexdigest() return hex_dig if __name__ == "__main__": hashed_files = {} while True: string_input = input("请输入字符串(输入'退出'退出循环):") if string_input == "退出": break hashed_name = hash_filename(string_input) hashed_files[string_input] = hashed_name json_filename = input("请输入要保存的 JSON 文件名:") with open(json_filename, 'w') as json_file: json.dump(hashed_files, json_file) print(f"JSON 文件已保存为 {json_filename}")