diff --git a/src/Picocrypt.py b/src/Picocrypt.py index 53c9fa6..12fe4fa 100644 --- a/src/Picocrypt.py +++ b/src/Picocrypt.py @@ -10,8 +10,8 @@ try: from Crypto.Cipher import ChaCha20_Poly1305 except: from os import system - system("python3 -m pip install argon2-cffi") - system("python3 -m pip install pycryptodome") + system("python3 -m pip install argon2-cffi --user") + system("python3 -m pip install pycryptodome --user") from tkinter import filedialog,messagebox from threading import Thread @@ -38,14 +38,13 @@ corruptedNotice = "Error. The input file is corrupted." modifiedNotice = "Error. The input file has been intentionally modified." kCorruptedNotice = "The input file is corrupted, but the output has been kept." kModifiedNotice = "The input file has been intentionally modified, but the output has been kept." -derivingNotice = "Deriving key... (takes a few seconds)" +derivingNotice = "Deriving key (takes a few seconds)..." keepNotice = "Keep decrypted output even if it's corrupted or modified" kept = False eraseNotice = "Securely erase and delete original file" working = False overwriteNotice = "Output file already exists. Would you like to overwrite it?" -unknownErrorNotice = "Unknown error occured. Please try again or view the logs." -log = "" +unknownErrorNotice = "Unknown error occured. Please try again." tk = tkinter.Tk() tk.geometry("480x420") @@ -60,9 +59,9 @@ s = tkinter.ttk.Style() s.configure("TCheckbutton",background="#f5f6f7") def inputSelected(): - global inputFile,working,log + global inputFile,working dummy.focus() - log += "File selection dialog opened\n" + try: suffix = "" tmp = filedialog.askopenfilename( @@ -90,7 +89,6 @@ def inputSelected(): adLabelString.set("File metadata (read only):") keepBtn["state"] = "normal" eraseBtn["state"] = "disabled" - log += "File selected, will decrypt\n" else: eraseBtn["state"] = "normal" keepBtn["state"] = "disabled" @@ -98,17 +96,18 @@ def inputSelected(): adArea.delete("1.0",tkinter.END) suffix = " (will be encrypted)" adLabelString.set(adString) - log += "File selected, will encrypt\n" inputString.set(inputFile.split("/")[-1]+suffix) passwordInput["state"] = "normal" + passwordInput.delete(0,"end") startBtn["state"] = "normal" statusString.set("Ready.") progress["value"] = 0 - except UnicodeDecodeError as e: - log += str(e)+"\n" + except UnicodeDecodeError: + passwordInput["state"] = "normal" + passwordInput.delete(0,"end") statusString.set(corruptedNotice) - except Exception as e: - log += str(e)+"\n" + except: + pass finally: dummy.focus() working = False @@ -155,9 +154,7 @@ passwordInput.grid(sticky="nesw") passwordInput["state"] = "disabled" def start(): - global inputFile,outputFile,password,ad,kept,working,log - - log += "Starting the encryption/decryption process\n" + global inputFile,outputFile,password,ad,kept,working if ".pcf" not in inputFile: mode = "encrypt" @@ -168,10 +165,8 @@ def start(): try: getsize(outputFile) force = messagebox.askyesno("Warning",overwriteNotice) - log += "Overwrite set to true\n" dummy.focus() if force!=1: - log += "Cancelled because overwrite set to false\n" return except: pass @@ -181,12 +176,9 @@ def start(): password = passwordInput.get().encode("utf-8") ad = adArea.get("1.0",tkinter.END).encode("utf-8") wipe = erase.get()==1 - if wipe and mode=="encrypt": - log += "Secure wipe enabled\n" - elif not wipe and mode=="encrypt": - log += "Secure wipe disabled\n" selectFileInput["state"] = "disabled" + eraseBtn["state"] = "disabled" passwordInput["state"] = "disabled" adArea["state"] = "disabled" startBtn["state"] = "disabled" @@ -226,8 +218,6 @@ def start(): progress.config(mode="indeterminate") progress.start(15) - log += "Generating key through Argon2\n" - key = hash_secret_raw( password, salt, @@ -245,9 +235,7 @@ def start(): check = sha3_512(key).digest() if mode=="decrypt": - log += "Checking if key is correct" if not compare_digest(check,cs): - log += "\nIncorrect password\n" statusString.set(passwordNotice) fin.close() fout.close() @@ -260,7 +248,6 @@ def start(): working = False del key return - log += " (yes)\n" cipher = ChaCha20_Poly1305.new(key=key,nonce=nonce) crc = sha3_512() @@ -274,7 +261,6 @@ def start(): wiper = open(inputFile,"r+b") wiper.seek(0) - log += "Encryption/decryption starting\n" while True: piece = fin.read(chunkSize) if wipe: @@ -293,13 +279,11 @@ def start(): else: crcdg = crc.digest() if not compare_digest(crccs,crcdg): - log += "Data is corrupted\n" statusString.set(corruptedNotice) progress["value"] = 100 fin.close() fout.close() if keep.get()!=1: - log += "Corrupted output has been kept\n" remove(outputFile) selectFileInput["state"] = "normal" passwordInput["state"] = "normal" @@ -314,13 +298,11 @@ def start(): try: cipher.verify(digest) except: - log += "Data has been modified\n" statusString.set(modifiedNotice) progress["value"] = 100 fin.close() fout.close() if keep.get()!=1: - log += "Modified output has been kept\n" remove(outputFile) selectFileInput["state"] = "normal" passwordInput["state"] = "normal" @@ -407,13 +389,12 @@ def start(): kept = False working = False del fin,fout,cipher,key - log += "Process completed\n" def wrapper(): - global working,log + global working try: start() - except Exception as e: + except: selectFileInput["state"] = "normal" passwordInput["state"] = "normal" adArea["state"] = "normal" @@ -422,7 +403,6 @@ def wrapper(): statusString.set(unknownErrorNotice) dummy.focus() working = False - log += str(e)+"\n" finally: sys.exit(0) @@ -515,7 +495,7 @@ status = tkinter.ttk.Label( status.place(x=17,y=356) status.config(background="#f5f6f7") -hint = "(v1.4) Created by Evan Su. Click for details and source." +hint = "Created by Evan Su. Click for details and source." creditsString = tkinter.StringVar(tk) creditsString.set(hint) credits = tkinter.ttk.Label( @@ -530,43 +510,14 @@ source = "https://github.com/HACKERALERT/Picocrypt" credits.bind("",lambda e:webbrowser.open(source)) versionString = tkinter.StringVar(tk) -versionString.set("Logs") +versionString.set("v1.5") version = tkinter.ttk.Label( tk, - textvariable=versionString, - cursor="hand2" + textvariable=versionString ) version["state"] = "disabled" version.config(background="#f5f6f7") -version.place(x=430,y=386) -version.bind("",lambda e:showLog()) - -def showLogWrapper(): - logger = tkinter.Tk() - logger.geometry("480x420") - logger.title("Logs") - logger.resizable(0,0) - loggerFrame = tkinter.Frame( - logger, - width=480, - height=420 - ) - loggerFrame.place(x=0,y=0) - loggerFrame.columnconfigure(0,weight=10) - loggerFrame.grid_propagate(False) - box = tkinter.scrolledtext.ScrolledText( - loggerFrame, - ) - box.config(font=("Consolas",11)) - box.grid(sticky="nesw") - box.insert("1.0",log) - box["state"] = "disabled" - logger.mainloop() - sys.exit(0) - -def showLog(): - t = Thread(target=showLogWrapper,daemon=True) - t.start() +version.place(x=436,y=386) dummy = tkinter.ttk.Button( tk