Long ago i watched a tutorial on how to encrypt files(of any kind) with a key/password The original code just makes the process in the terminal, but i wanted to make it into an application using tkinter as my GUI, i've come to a problem my small brain can't solve
The original video: https://www.youtube.com/watch?v=HHlInKhVz3s
This is the error i get: TypeError: Encrypt() missing 2 required positional arguments: 'WhichFile' and 'KeyInput'
This is my code:
from tkinter.filedialog import askopenfilename
import time
root = Tk()
root.title=("Tkinter Calculator")
root.geometry("500x500")
#title
WindowTitle = Label(root, text="Choose Action", font=("Arial", 15))
WindowTitle.place(x=250, y=10,anchor="center")
### The functions
#Encrypt
def Encrypt(WhichFile, KeyInput):
file = open(WhichFile, "rb")
data = file.read()
file.close()
data = bytearray(data)
for index, value in enumerate(data):
data[index] = value ^ KeyInput
file = open("CC-" + WhichFile, "wb")
file.write(data)
file.close()
#Decrypt
def Decrypt(WhichFile, KeyInput):
file = open(WhichFile, "rb")
data = file.read()
file.close()
data = bytearray(data)
for index, value in enumerate(data):
data[index] = value ^ KeyInput
file = open(WhichFile, "wb")
file.write(data)
file.close()
#Step1 - Write the name of the file(Needs to be in the same folder(Also include ext.))
WhichFile = Entry(root, width = 20)
WhichFile.place(x=100, y=150)
WhichFile.insert(0, "Enter File name with extension")
#Step2 - Ask for a key/password
KeyInput = Entry(root, width = 20)
KeyInput.place(x=100, y=250)
KeyInput.insert(0, "Enter a key: ")
#Button for encrypt
Encryptbtn = Button(root, text="Encrypt", highlightbackground='#3E4149', command=Encrypt)
Encryptbtn.place(x=100, y=350)
#Button for decrypt
Decryptbtn = Button(root, text="Decrypt", highlightbackground='#3E4149', command=Decrypt)
Decryptbtn.place(x=200, y=350)
root.mainloop()