机缘
我是在2022年8月31日注册到CSDN上,因为我学的是计算机相关的专业,在与同学和老师的交谈中我才第一次接触到CSDN,在这个平台上我看到了很多大佬在发布学习的日常,以及工作的心得。每次老师布置的作业,我都或多或少的可以从CSDN上得到一些灵感。在机缘巧合下,我受到了激励,从2024年1月20日,开始以创作者的身份在CSDN上活跃。
收获
到目前为止,我在CSDN上以创作者的身份已经128天了,累计发布97篇博客,上传了2篇资源,很荣幸收获了1753位粉丝,访问量已经突破11w。我收到过来自志同道合好友的鼓励,以及来自官方的建议,也认识到很多厉害的朋友。
日常
我的博客分享大多来自我阅读资料过后的总结心得,在完成学习任务时的难题解决方法,以及同学问我的问题,我整理的解题思路。现在我已经习惯了在学习的日常中总结归纳学习心得,发布到博客上去帮助其他的可能需要的人,写博客也是为了帮助我总结归纳我目前所学的知识,能够让我更好的进步与成长。
成就
大大小小的成就也有一些,这里我就为大家简单展示一个我自己用Python写的以DES算法为核心的文件加解密程序(注:这里仅展示了部分代码,如有需要请留言+关注)
class FileEncryptWindow:
def __init__(self):
self.window = Tk()
self.window.title("DES文件加密解密器")
self.welcome_frame = Frame(self.window)
self.welcome_frame.pack(fill=BOTH, expand=True)
self.welcome_label = Label(self.welcome_frame, text="欢迎使用DES文件加密解密器", font=("Arial", 15))
self.welcome_label.pack(pady=20)
self.file_path = None
self.descipher = None
self.menubar = Menu(self.window)
self.filemenu = Menu(self.menubar, tearoff=0)
self.filemenu.add_command(label="打开文件", command=self.openFile)
self.filemenu.add_command(label="加密文件", command=self.encryptFile)
self.filemenu.add_command(label="解密文件", command=self.decryptFile)
self.filemenu.add_separator()
self.filemenu.add_command(label="退出", command=self.window.quit)
self.helpmenu = Menu(self.menubar, tearoff=0)
self.helpmenu.add_command(label="关于", command=self.showAbout)
self.helpmore = Menu(self.menubar, tearoff=0)
self.helpmore.add_command(label="存储", command=self.showMore)
self.menubar.add_cascade(label="文件", menu=self.filemenu)
self.menubar.add_cascade(label="帮助", menu=self.helpmenu)
self.menubar.add_cascade(label="更多", menu=self.helpmore)
self.window.config(menu=self.menubar)
self.main_frame = Frame(self.window)
self.main_frame.pack(fill=BOTH, expand=True)
frame1 = Frame(self.window)
frame1.pack()
labelFileName = Label(frame1,text="文件名:")
labelFileName.grid(row=0, column=0)
self.fileName = StringVar()
entryFileName = Entry(frame1,width=100,textvariable=self.fileName)
entryFileName.grid(row=0,column=1)
btnOpen = Button(frame1,text="打开",command=self.openFile)
btnOpen.grid(row=0, column=2)
frame2 = Frame(self.window)
frame2.pack()
labelKey = Label(frame2,text="密钥:")
labelKey.grid(row=1, column=0)
self.key = StringVar()
entryKey = Entry(frame2,textvariable=self.key)
self.key.set("")
entryKey.grid(row=1, column=1)
btnEncrypt = Button(frame2, text="加密", command=self.encryptFile)
btnEncrypt.grid(row=1, column=2)
btnDecrypt = Button(frame2, text="解密", command=self.decryptFile)
btnDecrypt.grid(row=1, column=3)
self.text = Text(self.window)
self.text.pack(fill=BOTH, expand=True)
tkinter.messagebox.showinfo("注意", "请记住加密和解密的密钥,本程序没有存储功能!")
self.window.mainloop()
def showMore(self):
tkinter.messagebox.showinfo("关于", "本功能暂时并未开放,您的需求是我最大的动力!")
def showAbout(self):
tkinter.messagebox.showinfo("关于", "这是一个简单的凯撒密码文件加密解密器!")
def openFile(self):
try:
inFileName = askopenfilename()
inFile = open(inFileName,"rb")
self.fileName.set(inFileName)
self.fileCont = inFile.read()
self.text.delete(1.0,END)
self.text.insert(END,self.fileCont)
inFile.close()
except FileNotFoundError:
tkinter.messagebox.showerror("报错","先打开文件再加密!")
def encryptFile(self):
try:
key = eval(self.key.get())
self.descipher = DESCipher(key)
encryptStr = self.descipher.encrypt(self.fileCont)
outfileName = asksaveasfilename()
outFile = open(outfileName,"wb")
outFile.write(encryptStr)
outFile.close()
except SyntaxError:
tkinter.messagebox.showerror("报错","先输入秘钥再加密!")
except AttributeError:
tkinter.messagebox.showerror("报错","先打开文件再加密!")
except PermissionError:
tkinter.messagebox.showerror("报错","该文件已经被锁定,请关闭该文件!")
except:
tkinter.messagebox.showerror("报错","请输入数字秘钥进行加密!")
def decryptFile(self):
try:
key = eval(self.key.get())
self.descipher = DESCipher(key)
decryptStr = self.descipher.decrypt(self.fileCont)
outfileName = asksaveasfilename()
outFile = open(outfileName,"wb")
outFile.write(decryptStr)
outFile.close()
except SyntaxError:
tkinter.messagebox.showerror("报错","先输入秘钥再解密!")
except AttributeError:
tkinter.messagebox.showerror("报错","先打开文件再解密!")
except PermissionError:
tkinter.messagebox.showerror("报错","该文件已经被锁定,请关闭该文件!")
except:
tkinter.messagebox.showerror("报错","请输入数字秘钥进行解密!")
FileEncryptWindow()
下面是代码运行后的效果图:
憧憬
在未来的日子里我会更加刻苦的学习,认真的总结所需知识,并持续发布优质文章,让更多的人从我这里得到收获满满!!!
我希望看到这篇文章的各位友友事业有成,学业进步,身体健康,天天开心!!!
感谢各位友友的支持,看到这里的点个小小的赞吧(๑><๑)!!!