#Blowfish算法窗口def Blowfish_encrypt_decryptkey data mode #获取块大小并生成随机的初始向量 bs = Blowfishblock_size iv = osurandombs #创建Blowfish密码器并进行加密解密操作 cipher = Blowfishnewkey mode iv data = paddat
def create_new_window3(): def on_encrypt(): #获取输入文件路径、输出文件路径和密钥 input_file_path = e_input.get() output_file_path = e_output.get() key = e_key.get() #检查是否填写完整 if not input_file_path or not output_file_path or not key: messagebox.showwarning("Warning", "请填写完整的输入、输出路径和密钥!") return #调用文件加密函数进行处理 if encrypt_file(input_file_path, output_file_path, key): messagebox.showinfo("Success", "文件加密成功!")
def on_decrypt():
#获取输入文件路径、输出文件路径和密钥
input_file_path = e_input.get()
output_file_path = e_output.get()
key = e_key.get()
#检查是否填写完整
if not input_file_path or not output_file_path or not key:
messagebox.showwarning("Warning", "请填写完整的输入、输出路径和密钥!")
return
#调用文件解密函数进行处理
if decrypt_file(input_file_path, output_file_path, key):
messagebox.showinfo("Success", "文件解密成功!")
def generate_random_key():
#生成随机密钥,包括字母和数字,长度为8
key = ''.join(random.choices(string.ascii_letters + string.digits, k=8))
return key
#用于生成密钥按钮的事件处理函数
def on_generate_key():
#调用生成随机密钥函数生成密钥
key = generate_random_key()
#清空密钥输入框并将生成的密钥赋值给输入框
e_key.delete(0, tk.END)
e_key.insert(0, key)
#复制按钮函数
def on_copy_key():
#获取密钥
key = e_key.get()
if key:
#将密钥复制到剪贴板
pyperclip.copy(key)
messagebox.showinfo("Copied", "密钥已复制到剪贴板!")
def on_select_input():
#打开文件选择对话框,获取选择的文件路径
file_path = filedialog.askopenfilename()
if file_path:
e_input.delete(0, tk.END)
e_input.insert(0, file_path)
def on_select_output():
#打开文件保存对话框,并设置默认文件扩展名为.docx
file_path = filedialog.asksaveasfilename(defaultextension='.docx')
if file_path:
e_output.delete(0, tk.END)
e_output.insert(0, file_path)
new_window = tk.Toplevel(root_new)
new_window.title('Blowfish算法加密/解密窗口')
new_window.geometry('2000x1000')
lbl_input = tk.Label(new_window, text="输入文件路径:")
lbl_input.pack()
e_input = tk.Entry(new_window, width=50)
e_input.pack()
btn_select_input = tk.Button(new_window, text="选择文件", command=on_select_input)
btn_select_input.pack()
lbl_output = tk.Label(new_window, text="输出文件路径:")
lbl_output.pack()
e_output = tk.Entry(new_window, width=50)
e_output.pack()
btn_select_output = tk.Button(new_window, text="选择路径", command=on_select_output)
btn_select_output.pack()
lbl_key = tk.Label(new_window, text="密钥:")
lbl_key.pack()
e_key = tk.Entry(new_window)
e_key.pack()
#创建生成密钥按钮
generate_key_btn = tk.Button(new_window, text="生成密钥", command=on_generate_key)
generate_key_btn.pack()
#复制
copy_key_btn = tk.Button(new_window, text="复制密钥", command=on_copy_key)
copy_key_btn.pack()
#创建加密和解密按钮
btn_encrypt = tk.Button(new_window, text="加密", command=on_encrypt)
btn_encrypt.pack()
btn_decrypt = tk.Button(new_window, text="解密", command=on_decrypt)
btn_decrypt.pack(
原文地址: https://www.cveoy.top/t/topic/hh32 著作权归作者所有。请勿转载和采集!