用户:
酒_笙查看:0 回复:1 评论:0 创建时间:2021-10-30T08:03:40
【作品展示】

【作品介绍】
mium 1.8.2
【作品源代码】
import tkinter as tk
from tkinter import filedialog, messagebox
import tkinter
from tkinter import *
import os
import random
from tkinter import font
# 自动引入运行库
# 设置强密码
def get_strong_password():
strongpassword = ''
for inint in range(256):
strongpassword += random.choice(
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+++___-!^%$#*')
return strongpassword
# 加密
def encrypt(path, password):
kfc = filedialog.asksaveasfilename(title='选择解密后文件位置')
fileFullName = path.split(os.path.sep)
fileName = fileFullName[len(fileFullName)-1].split(".")[0]
fileSuffix = fileFullName[len(fileFullName)-1].split(".")[1]
# 文件全名称:fileFullName[len(fileFullName)-1]
# 文件名称:fileName
# 文件后缀:fileSuffix
fileParent = 0 # path[0:len(path)-len(fileFullName[len(fileFullName)-1])]
newFileName = 0 # fileFullName[len(fileFullName)-1]
newFilePath = kfc
# print("文件父路径:",fileParent)
# print("新的文件名称:",newFileName)
# print("新的文件全路径:", newFilePath)
f_read = open(path, "rb")
f_write = open(newFilePath, "wb")
count = 0 # 当前密码加密索引
# 异或循环加密
for now in f_read:
for nowByte in now:
newByte = nowByte ^ ord(password[count % len(password)])
count += 1
f_write.write(bytes([newByte]))
f_read.close()
f_write.close()
messagebox.askokcancel('提示', '加密成功!')
# 解密
def decrypt(path, password, awa):
fileFullName = path.split(os.path.sep) # os.path.sep为操作系统的文件分隔符
fileName = fileFullName[len(fileFullName) - 1].split(".")[0]
fileSuffix = fileFullName[len(fileFullName) - 1].split(".")[1]
# print("文件全名称:", fileFullName[len(fileFullName)-1])
# print("文件名称:", fileName)
# print("文件后缀:", fileSuffix)
fileParent = path[0:len(path) - len(fileFullName[len(fileFullName)-1])]
newFileName = fileFullName[len(fileFullName) - 1]
newFilePath = awa
# print("文件父路径:", fileParent)
# print("新的文件名称:", newFileName)
# print("新的文件全路径:", newFilePath)
f_read = open(path, "rb")
f_write = open(newFilePath, "wb")
count = 0 # 当前密码加密索引
# 异或循环加密
for now in f_read:
for nowByte in now:
newByte = nowByte ^ ord(password[count % len(password)])
count += 1
f_write.write(bytes([newByte]))
f_read.close()
f_write.close()
messagebox.askokcancel('提示', '解密成功!')
def choosefile():
filepath = filedialog.askopenfilename(title='选择需要加密的文件')
Entry1.select_clear()
Entry1.insert(0, filepath)
return filepath
def choosefile0O():
filepath = filedialog.askopenfilename(title='选择需要解密的文件')
Entry1.select_clear()
Entry1.insert(0, filepath)
return filepath
def choosekey():
keypath = filedialog.askopenfilename(
title='选择密钥文件', filetypes=(('受支持的密钥文件', '*.key'),))
Entry2.select_clear()
Entry2.insert(0, keypath)
return keypath
def about():
about = Tk()
about.title('关于')
about.geometry("450x550")
about.resizable(0, 0)
about.iconbitmap(default='images\icon.ico')
Label1 = tk.Label(about, text='关于', font=('楷体', 36))
Label1.place(height=喵, width=97, x=20, y=23)
Label2 = tk.Label(about, text='version 1.8.2', font=('微软雅黑', 12))
Label2.place(height=30, width=150, x=4, y=80)
Label3 = tk.Label(about, text='注册信息:', font=('黑体', 12))
Label3.place(height=27, width=90, x=20, y=117)
Entry1 = tk.Entry(about, justify=LEFT)
Entry1.insert('0', 'HQF7-QFFQ-123R-12DA')
Entry1.config(state=DISABLED)
Entry1.place(height=23, width=200, x=105, y=120)
Entry2 = tk.Entry(about)
Entry2.insert('0', '永久有效')
Entry2.config(state=DISABLED)
Entry2.place(height=23, width=72, x=320, y=120)
Label4 = tk.Label(about, text='更新内容')
Label4.place(height=24, width=140, x=145, y=170)
Label5 = tk.Text(about, font='黑体')
Label5.insert(INSERT, '1.8.2')
Label5.insert(INSERT, '\n')
Label5.insert(INSERT, '1.正式加入了密钥文本路径显示')
Label5.insert(INSERT, '\n')
Label5.insert(INSERT, '2.修复21w07a密钥文本路径无效特性')
Label5.insert(INSERT, '\n')
Label5.insert(INSERT, '3.修复选择保存密钥文件名特性')
Label5.insert(INSERT, '\n')
Label5.insert(INSERT, '4.修复加密特性')
Label5.insert(INSERT, '\n')
Label5.insert(INSERT, '5.修复输入框无效问题')
Label5.place(height=300, width=395, x=28, y=190)
Label6 = tk.Label(about, text='联系方式:chengwenhao_183@163.com')
Label6.place(height=22, width=320, x=75, y=520)
messagebox.askokcancel('关于', '©酒笙 1.8.2 chengwenhao_183@163.com')
about.mainloop()
def savefile():
savefilepath = filedialog.asksaveasfilename(title='选择加密后文件储存位置')
return savefilepath
def savekey():
savekeypath = filedialog.asksaveasfilename(
title='选择密钥存储位置', filetypes=(('受支持的密钥文件', '*.key'),))
return savekeypath
# 定义点击
def codeing():
getpath = 0
getpath = Entry1.get()
password = get_strong_password()
password = str(password)
savekeypath = savekey()
with open(savekeypath, 'wt', encoding="utf-8") as create_password:
create_password.write(password)
encrypt(getpath, password)
def encodeing():
getpath = 0
getpath = Entry1.get()
keypath = choosekey()
keypath = Entry2.get()
getpath = choosefile0O()
password_key = open(keypath, "r") # 设置文件对象
password = password_key.read() # 将txt文件的所有内容读入到字符串str中
password_key.close() # 将文件关闭
savefileparh = savefile()
decrypt(getpath, password, savefileparh)
# 函数定义
window = Tk()
window.title('mium')
window.geometry("450x175")
window.resizable(0, 0)
window.configure(background='black')
window.iconbitmap(default='images\icon.ico')
Label1 = tkinter.Label(window, text='文件:', background='black',
bd=5, highlightcolor='white', fg='white')
Label1.place(height=24, width=68, x=22, y=36)
Entry1 = tkinter.Entry(window, background='black',
fg='white', highlightcolor='white')
Entry1.place(height=24, width=200, x=100, y=36)
Label2 = tkinter.Label(window, text='密钥:', background='black',
bd=5, highlightcolor='white', fg='white')
Label2.place(height=24, width=68, x=22, y=76)
Entry2 = tkinter.Entry(window, background='black', fg='white')
Entry2.place(height=24, width=200, x=100, y=76)
Button0 = tkinter.Button(window, text='选择文件', font='楷体',
bg='black', fg='white', command=choosefile)
Button0.place(height=24, width=96, x=320, y=36)
Button0 = tkinter.Button(window, text='选择密钥', font='楷体',
bg='black', fg='white', command=choosekey)
Button0.place(height=24, width=96, x=320, y=76)
Button1 = tkinter.Button(window, text='加密', bg='#afdd22',
font='KaiTi', command=codeing)
Button1.place(height=36, width=69, x=100, y=120)
Button2 = tkinter.Button(window, text='解密', bg='#c83c23',
font='KaiTi', command=encodeing)
Button2.place(height=36, width=69, x=200, y=120)
Button3 = tkinter.Button(window, text='关于', bg='#fff143',
font='KaiTi', command=about)
Button3.place(height=36, width=69, x=300, y=120)
# 运行
window.mainloop()
# 开启交互
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn