2021-02-19 16:30:39 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2021-03-15 20:08:47 +01:00
|
|
|
"""
|
|
|
|
Dependencies: argon2-cffi, pycryptodome, reedsolo
|
|
|
|
Copyright (c) Evan Su (https://evansu.cc)
|
2021-03-16 17:10:54 +01:00
|
|
|
Released under a GNU GPL v3 License
|
2021-03-15 20:08:47 +01:00
|
|
|
https://github.com/HACKERALERT/Picocrypt
|
|
|
|
"""
|
2021-02-19 16:30:39 +01:00
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Test if libraries are installed
|
2021-02-19 16:30:39 +01:00
|
|
|
try:
|
2021-03-13 18:11:06 +01:00
|
|
|
from argon2.low_level import hash_secret_raw
|
|
|
|
from Crypto.Cipher import ChaCha20_Poly1305
|
2021-03-15 19:41:15 +01:00
|
|
|
try:
|
|
|
|
from creedsolo import ReedSolomonError
|
|
|
|
except:
|
|
|
|
from reedsolo import ReedSolomonError
|
2021-02-19 16:30:39 +01:00
|
|
|
except:
|
2021-03-13 18:11:06 +01:00
|
|
|
# Libraries missing, install them
|
|
|
|
from os import system
|
2021-03-15 19:41:15 +01:00
|
|
|
try:
|
|
|
|
# Debian/Ubuntu based
|
|
|
|
system("sudo apt-get install python3-tk")
|
|
|
|
except:
|
|
|
|
# Fedora
|
|
|
|
system("sudo dnf install python3-tkinter")
|
2021-03-16 17:10:54 +01:00
|
|
|
|
2021-03-15 19:41:15 +01:00
|
|
|
system("python3 -m pip install argon2-cffi --no-cache-dir")
|
|
|
|
system("python3 -m pip install pycryptodome --no-cache-dir")
|
|
|
|
system("python3 -m pip install reedsolo --no-cache-dir")
|
2021-02-19 16:30:39 +01:00
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Imports
|
2021-02-21 17:48:15 +01:00
|
|
|
from tkinter import filedialog,messagebox
|
2021-02-19 01:43:18 +01:00
|
|
|
from threading import Thread
|
|
|
|
from datetime import datetime
|
|
|
|
from argon2.low_level import hash_secret_raw,Type
|
|
|
|
from Crypto.Cipher import ChaCha20_Poly1305
|
2021-03-19 03:03:21 +01:00
|
|
|
from Crypto.Hash import SHA3_512 as sha3_512
|
2021-02-19 01:43:18 +01:00
|
|
|
from secrets import compare_digest
|
|
|
|
from os import urandom,fsync,remove
|
|
|
|
from os.path import getsize,expanduser
|
|
|
|
import sys
|
|
|
|
import tkinter
|
|
|
|
import tkinter.ttk
|
2021-02-24 17:54:34 +01:00
|
|
|
import tkinter.scrolledtext
|
2021-02-19 01:43:18 +01:00
|
|
|
import webbrowser
|
2021-03-15 19:41:15 +01:00
|
|
|
try:
|
|
|
|
from creedsolo import RSCodec,ReedSolomonError
|
|
|
|
except:
|
|
|
|
from reedsolo import RSCodec,ReedSolomonError
|
2021-02-19 01:43:18 +01:00
|
|
|
|
2021-03-16 17:10:54 +01:00
|
|
|
# Tk/Tcl is a little barbaric, so I'm disabling
|
|
|
|
# high DPI so it doesn't scale bad and look horrible
|
2021-03-13 18:20:29 +01:00
|
|
|
try:
|
|
|
|
from ctypes import windll
|
2021-03-13 18:56:27 +01:00
|
|
|
windll.shcore.SetProcessDpiAwareness(0)
|
2021-03-13 18:20:29 +01:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Global variables and notices
|
2021-02-19 01:43:18 +01:00
|
|
|
inputFile = ""
|
|
|
|
outputFile = ""
|
|
|
|
password = ""
|
|
|
|
ad = ""
|
2021-03-13 18:11:06 +01:00
|
|
|
kept = False
|
|
|
|
working = False
|
2021-03-18 15:46:21 +01:00
|
|
|
gMode = None
|
2021-03-18 20:15:32 +01:00
|
|
|
headerRsc = None
|
2021-02-19 01:43:18 +01:00
|
|
|
adString = "File metadata (used to store some text along with the file):"
|
|
|
|
passwordNotice = "Error. The provided password is incorrect."
|
|
|
|
corruptedNotice = "Error. The input file is corrupted."
|
2021-03-17 18:20:18 +01:00
|
|
|
veryCorruptedNotice = "Error. The input file and header keys are badly corrupted."
|
2021-02-19 01:43:18 +01:00
|
|
|
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."
|
2021-03-17 18:20:18 +01:00
|
|
|
kVeryCorruptedNotice = "The input file is badly corrupted, but the output has been kept."
|
2021-02-25 17:35:54 +01:00
|
|
|
derivingNotice = "Deriving key (takes a few seconds)..."
|
2021-02-19 01:43:18 +01:00
|
|
|
keepNotice = "Keep decrypted output even if it's corrupted or modified"
|
|
|
|
eraseNotice = "Securely erase and delete original file"
|
2021-02-21 17:48:15 +01:00
|
|
|
overwriteNotice = "Output file already exists. Would you like to overwrite it?"
|
2021-03-15 19:41:15 +01:00
|
|
|
rsNotice = "Prevent corruption using Reed-Solomon"
|
|
|
|
rscNotice = "Creating Reed-Solomon tables..."
|
2021-02-25 17:35:54 +01:00
|
|
|
unknownErrorNotice = "Unknown error occured. Please try again."
|
2021-02-19 01:43:18 +01:00
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Create root Tk
|
2021-02-19 01:43:18 +01:00
|
|
|
tk = tkinter.Tk()
|
2021-03-18 15:46:21 +01:00
|
|
|
tk.geometry("480x480")
|
2021-02-19 01:43:18 +01:00
|
|
|
tk.title("Picocrypt")
|
|
|
|
tk.configure(background="#f5f6f7")
|
|
|
|
tk.resizable(0,0)
|
|
|
|
|
2021-03-16 17:10:54 +01:00
|
|
|
# Try setting window icon if included with Picocrypt
|
2021-03-13 18:11:06 +01:00
|
|
|
try:
|
|
|
|
favicon = tkinter.PhotoImage(file="./key.png")
|
|
|
|
tk.iconphoto(False,favicon)
|
|
|
|
except:
|
|
|
|
pass
|
2021-02-19 01:43:18 +01:00
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Some styling
|
2021-02-19 01:43:18 +01:00
|
|
|
s = tkinter.ttk.Style()
|
|
|
|
s.configure("TCheckbutton",background="#f5f6f7")
|
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Event when user selects an input file
|
2021-02-19 01:43:18 +01:00
|
|
|
def inputSelected():
|
2021-03-18 20:15:32 +01:00
|
|
|
global inputFile,working,headerRsc
|
2021-03-13 18:11:06 +01:00
|
|
|
dummy.focus()
|
|
|
|
|
|
|
|
# Try to handle when select file is cancelled
|
|
|
|
try:
|
|
|
|
# Ask for input file
|
|
|
|
suffix = ""
|
|
|
|
tmp = filedialog.askopenfilename(
|
|
|
|
initialdir=expanduser("~")
|
|
|
|
)
|
|
|
|
if len(tmp)==0:
|
|
|
|
# Exception will be caught by except below
|
|
|
|
raise Exception("No file selected.")
|
|
|
|
inputFile = tmp
|
2021-03-18 20:15:32 +01:00
|
|
|
|
|
|
|
# Decide if encrypting or decrypting
|
|
|
|
if ".pcv" in inputFile.split("/")[-1]:
|
2021-03-15 19:41:15 +01:00
|
|
|
suffix = " (will decrypt)"
|
2021-03-18 20:15:32 +01:00
|
|
|
fin = open(inputFile,"r+b")
|
|
|
|
|
|
|
|
# Read file metadata (a little complex)
|
|
|
|
tmp = fin.read(139)
|
|
|
|
reedsolo = False
|
|
|
|
if tmp[0]==43:
|
|
|
|
reedsolo = True
|
|
|
|
tmp = tmp[1:]
|
|
|
|
else:
|
|
|
|
tmp = tmp[:-1]
|
|
|
|
tmp = bytes(headerRsc.decode(tmp)[0])
|
|
|
|
tmp = tmp.replace(b"+",b"")
|
|
|
|
tmp = int(tmp.decode("utf-8"))
|
|
|
|
if not reedsolo:
|
|
|
|
fin.seek(138)
|
|
|
|
ad = fin.read(tmp)
|
|
|
|
try:
|
|
|
|
ad = bytes(headerRsc.decode(ad)[0])
|
|
|
|
except ReedSolomonError:
|
|
|
|
ad = b"Error decoding file metadata."
|
|
|
|
ad = ad.decode("utf-8")
|
2021-03-13 18:11:06 +01:00
|
|
|
fin.close()
|
2021-03-18 20:15:32 +01:00
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Insert the metadata into its text box
|
|
|
|
adArea["state"] = "normal"
|
|
|
|
adArea.delete("1.0",tkinter.END)
|
2021-03-18 20:15:32 +01:00
|
|
|
adArea.insert("1.0",ad)
|
2021-03-13 18:11:06 +01:00
|
|
|
adArea["state"] = "disabled"
|
|
|
|
adLabelString.set("File metadata (read only):")
|
|
|
|
keepBtn["state"] = "normal"
|
|
|
|
eraseBtn["state"] = "disabled"
|
2021-03-15 19:41:15 +01:00
|
|
|
rsBtn["state"] = "disabled"
|
2021-03-18 15:46:21 +01:00
|
|
|
cpasswordInput["state"] = "normal"
|
|
|
|
cpasswordInput.delete(0,"end")
|
|
|
|
cpasswordInput["state"] = "disabled"
|
2021-03-13 18:11:06 +01:00
|
|
|
else:
|
|
|
|
# Update the UI
|
|
|
|
eraseBtn["state"] = "normal"
|
|
|
|
keepBtn["state"] = "disabled"
|
2021-03-15 19:41:15 +01:00
|
|
|
rsBtn["state"] = "normal"
|
2021-03-13 18:11:06 +01:00
|
|
|
adArea["state"] = "normal"
|
|
|
|
adArea.delete("1.0",tkinter.END)
|
2021-03-15 19:41:15 +01:00
|
|
|
suffix = " (will encrypt)"
|
2021-03-13 18:11:06 +01:00
|
|
|
adLabelString.set(adString)
|
2021-03-18 15:46:21 +01:00
|
|
|
cpasswordInput["state"] = "normal"
|
|
|
|
cpasswordInput.delete(0,"end")
|
2021-03-18 20:15:32 +01:00
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Enable password box, etc.
|
|
|
|
inputString.set(inputFile.split("/")[-1]+suffix)
|
|
|
|
passwordInput["state"] = "normal"
|
|
|
|
passwordInput.delete(0,"end")
|
|
|
|
startBtn["state"] = "normal"
|
|
|
|
statusString.set("Ready.")
|
|
|
|
progress["value"] = 0
|
2021-03-18 20:15:32 +01:00
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# File decode error
|
|
|
|
except UnicodeDecodeError:
|
|
|
|
statusString.set(corruptedNotice)
|
2021-03-18 20:15:32 +01:00
|
|
|
progress["value"] = 100
|
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# No file selected, do nothing
|
|
|
|
except:
|
|
|
|
pass
|
2021-03-18 20:15:32 +01:00
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Focus the dummy button to remove ugly borders
|
|
|
|
finally:
|
|
|
|
dummy.focus()
|
|
|
|
working = False
|
|
|
|
|
|
|
|
# Button to select input file
|
2021-02-19 01:43:18 +01:00
|
|
|
selectFileInput = tkinter.ttk.Button(
|
2021-03-13 18:11:06 +01:00
|
|
|
tk,
|
|
|
|
text="Select file",
|
|
|
|
command=inputSelected,
|
2021-02-19 01:43:18 +01:00
|
|
|
)
|
|
|
|
selectFileInput.place(x=19,y=20)
|
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Label that displays selected input file
|
2021-02-19 01:43:18 +01:00
|
|
|
inputString = tkinter.StringVar(tk)
|
|
|
|
inputString.set("Please select a file.")
|
|
|
|
selectedInput = tkinter.ttk.Label(
|
2021-03-13 18:11:06 +01:00
|
|
|
tk,
|
|
|
|
textvariable=inputString
|
2021-02-19 01:43:18 +01:00
|
|
|
)
|
|
|
|
selectedInput.config(background="#f5f6f7")
|
|
|
|
selectedInput.place(x=104,y=23)
|
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Label that prompts user to enter a password
|
2021-02-19 01:43:18 +01:00
|
|
|
passwordString = tkinter.StringVar(tk)
|
|
|
|
passwordString.set("Password:")
|
|
|
|
passwordLabel = tkinter.ttk.Label(
|
2021-03-13 18:11:06 +01:00
|
|
|
tk,
|
|
|
|
textvariable=passwordString
|
2021-02-19 01:43:18 +01:00
|
|
|
)
|
|
|
|
passwordLabel.place(x=17,y=56)
|
|
|
|
passwordLabel.config(background="#f5f6f7")
|
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# A frame to make password input fill width
|
2021-02-19 01:43:18 +01:00
|
|
|
passwordFrame = tkinter.Frame(
|
2021-03-13 18:11:06 +01:00
|
|
|
tk,
|
|
|
|
width=440,
|
|
|
|
height=22
|
2021-02-19 01:43:18 +01:00
|
|
|
)
|
|
|
|
passwordFrame.place(x=20,y=76)
|
|
|
|
passwordFrame.columnconfigure(0,weight=10)
|
|
|
|
passwordFrame.grid_propagate(False)
|
2021-03-13 18:11:06 +01:00
|
|
|
# Password input box
|
2021-02-19 01:43:18 +01:00
|
|
|
passwordInput = tkinter.ttk.Entry(
|
2021-03-18 15:46:21 +01:00
|
|
|
passwordFrame,
|
|
|
|
show="\u2022"
|
2021-02-19 01:43:18 +01:00
|
|
|
)
|
|
|
|
passwordInput.grid(sticky="nesw")
|
|
|
|
passwordInput["state"] = "disabled"
|
|
|
|
|
2021-03-18 15:46:21 +01:00
|
|
|
cpasswordString = tkinter.StringVar(tk)
|
|
|
|
cpasswordString.set("Confirm password:")
|
|
|
|
cpasswordLabel = tkinter.ttk.Label(
|
|
|
|
tk,
|
|
|
|
textvariable=cpasswordString
|
|
|
|
)
|
|
|
|
cpasswordLabel.place(x=17,y=106)
|
|
|
|
cpasswordLabel.config(background="#f5f6f7")
|
|
|
|
|
|
|
|
# A frame to make confirm password input fill width
|
|
|
|
cpasswordFrame = tkinter.Frame(
|
|
|
|
tk,
|
|
|
|
width=440,
|
|
|
|
height=22
|
|
|
|
)
|
|
|
|
cpasswordFrame.place(x=20,y=126)
|
|
|
|
cpasswordFrame.columnconfigure(0,weight=10)
|
|
|
|
cpasswordFrame.grid_propagate(False)
|
|
|
|
# Confirm password input box
|
|
|
|
cpasswordInput = tkinter.ttk.Entry(
|
|
|
|
cpasswordFrame,
|
|
|
|
show="\u2022"
|
|
|
|
)
|
|
|
|
cpasswordInput.grid(sticky="nesw")
|
|
|
|
cpasswordInput["state"] = "disabled"
|
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Start the encryption/decryption process
|
2021-02-19 01:43:18 +01:00
|
|
|
def start():
|
2021-03-18 20:15:32 +01:00
|
|
|
global inputFile,outputFile,password,ad,kept,working,gMode,headerRsc
|
2021-03-15 19:41:15 +01:00
|
|
|
dummy.focus()
|
|
|
|
reedsolo = False
|
|
|
|
chunkSize = 2**20
|
2021-03-13 18:11:06 +01:00
|
|
|
|
|
|
|
# Decide if encrypting or decrypting
|
2021-03-18 20:15:32 +01:00
|
|
|
if ".pcv" not in inputFile:
|
2021-03-13 18:11:06 +01:00
|
|
|
mode = "encrypt"
|
2021-03-18 15:46:21 +01:00
|
|
|
gMode = "encrypt"
|
2021-03-16 20:07:25 +01:00
|
|
|
outputFile = inputFile+".pcv"
|
2021-03-15 19:41:15 +01:00
|
|
|
reedsolo = rs.get()==1
|
2021-03-13 18:11:06 +01:00
|
|
|
else:
|
|
|
|
mode = "decrypt"
|
2021-03-18 15:46:21 +01:00
|
|
|
gMode = "decrypt"
|
2021-03-16 17:10:54 +01:00
|
|
|
# Check if Reed-Solomon was enabled by checking for "+"
|
2021-03-15 19:41:15 +01:00
|
|
|
test = open(inputFile,"rb+")
|
|
|
|
decider = test.read(1).decode("utf-8")
|
|
|
|
test.close()
|
|
|
|
if decider=="+":
|
|
|
|
reedsolo = True
|
2021-03-16 17:10:54 +01:00
|
|
|
# Decrypted output is just input file without the extension
|
2021-03-13 18:11:06 +01:00
|
|
|
outputFile = inputFile[:-4]
|
|
|
|
|
2021-03-18 20:15:32 +01:00
|
|
|
# Check if file already exists (getsize() throws error if file not found)
|
|
|
|
try:
|
|
|
|
getsize(outputFile)
|
|
|
|
force = messagebox.askyesno("Warning",overwriteNotice)
|
|
|
|
dummy.focus()
|
|
|
|
if force!=1:
|
|
|
|
return
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
# Disable inputs and buttons while encrypting/decrypting
|
|
|
|
selectFileInput["state"] = "disabled"
|
|
|
|
passwordInput["state"] = "disabled"
|
|
|
|
cpasswordInput["state"] = "disabled"
|
|
|
|
adArea["state"] = "disabled"
|
|
|
|
startBtn["state"] = "disabled"
|
|
|
|
eraseBtn["state"] = "disabled"
|
|
|
|
keepBtn["state"] = "disabled"
|
|
|
|
rsBtn["state"] = "disabled"
|
|
|
|
|
2021-03-18 15:46:21 +01:00
|
|
|
# Make sure passwords match
|
|
|
|
if passwordInput.get()!=cpasswordInput.get() and mode=="encrypt":
|
|
|
|
selectFileInput["state"] = "normal"
|
|
|
|
passwordInput["state"] = "normal"
|
|
|
|
cpasswordInput["state"] = "normal"
|
|
|
|
adArea["state"] = "normal"
|
|
|
|
startBtn["state"] = "normal"
|
|
|
|
eraseBtn["state"] = "normal"
|
|
|
|
rsBtn["state"] = "normal"
|
|
|
|
working = False
|
|
|
|
progress["value"] = 100
|
|
|
|
statusString.set("Passwords don't match.")
|
|
|
|
return
|
|
|
|
|
2021-03-15 19:41:15 +01:00
|
|
|
# Set progress bar indeterminate
|
|
|
|
progress.config(mode="indeterminate")
|
|
|
|
progress.start(15)
|
2021-03-18 20:15:32 +01:00
|
|
|
statusString.set(rscNotice)
|
2021-03-15 19:41:15 +01:00
|
|
|
|
|
|
|
# Create Reed-Solomon object
|
|
|
|
if reedsolo:
|
2021-03-17 18:20:18 +01:00
|
|
|
# 13 bytes per 128 bytes, ~10% larger output file
|
|
|
|
rsc = RSCodec(13)
|
2021-03-15 19:41:15 +01:00
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Set and get some variables
|
|
|
|
working = True
|
2021-03-17 18:20:18 +01:00
|
|
|
headerBroken = False
|
|
|
|
reedsoloFixedCount = 0
|
|
|
|
reedsoloErrorCount = 0
|
2021-03-13 18:11:06 +01:00
|
|
|
dummy.focus()
|
|
|
|
password = passwordInput.get().encode("utf-8")
|
|
|
|
ad = adArea.get("1.0",tkinter.END).encode("utf-8")
|
|
|
|
wipe = erase.get()==1
|
|
|
|
|
2021-03-16 17:10:54 +01:00
|
|
|
# Open files
|
2021-03-13 18:11:06 +01:00
|
|
|
fin = open(inputFile,"rb+")
|
2021-03-15 19:41:15 +01:00
|
|
|
if reedsolo and mode=="decrypt":
|
2021-03-16 17:10:54 +01:00
|
|
|
# Move pointer one forward
|
2021-03-15 19:41:15 +01:00
|
|
|
fin.read(1)
|
2021-03-13 18:11:06 +01:00
|
|
|
fout = open(outputFile,"wb+")
|
2021-03-15 19:41:15 +01:00
|
|
|
if reedsolo and mode=="encrypt":
|
2021-03-18 20:15:32 +01:00
|
|
|
# Signal that Reed-Solomon was enabled with a "+"
|
2021-03-15 19:41:15 +01:00
|
|
|
fout.write(b"+")
|
2021-03-13 18:11:06 +01:00
|
|
|
|
|
|
|
# Generate values for encryption if encrypting
|
|
|
|
if mode=="encrypt":
|
|
|
|
salt = urandom(16)
|
|
|
|
nonce = urandom(24)
|
2021-03-18 20:15:32 +01:00
|
|
|
|
|
|
|
# Reed-Solomon-encode metadata
|
|
|
|
ad = bytes(headerRsc.encode(ad))
|
|
|
|
# Write the metadata to output
|
|
|
|
tmp = str(len(ad)).encode("utf-8")
|
|
|
|
# Right-pad with "+"
|
|
|
|
while len(tmp)!=10:
|
|
|
|
tmp += b"+"
|
|
|
|
tmp = bytes(headerRsc.encode(tmp))
|
|
|
|
fout.write(tmp) # Length of metadata
|
2021-03-16 17:34:59 +01:00
|
|
|
fout.write(ad) # Metadata (associated data)
|
2021-03-16 20:07:25 +01:00
|
|
|
|
2021-03-18 20:15:32 +01:00
|
|
|
# Write zeros as placeholders, come back to write over it later.
|
|
|
|
# Note that 128 extra Reed-Solomon bytes are added
|
|
|
|
fout.write(b"0"*192) # SHA3-512 of encryption key
|
|
|
|
fout.write(b"0"*192) # CRC of file
|
|
|
|
fout.write(b"0"*144) # Poly1305 tag
|
|
|
|
# Reed-Solomon-encode salt and nonce
|
|
|
|
fout.write(bytes(headerRsc.encode(salt))) # Argon2 salt
|
|
|
|
fout.write(bytes(headerRsc.encode(nonce))) # ChaCha20 nonce
|
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# If decrypting, read values from file
|
|
|
|
else:
|
2021-03-18 20:15:32 +01:00
|
|
|
# Move past metadata into actual data
|
|
|
|
tmp = fin.read(138)
|
|
|
|
if tmp[0]==43:
|
|
|
|
tmp = tmp[1:]+fin.read(1)
|
|
|
|
tmp = bytes(headerRsc.decode(tmp)[0])
|
|
|
|
tmp = tmp.replace(b"+",b"")
|
|
|
|
adlen = int(tmp.decode("utf-8"))
|
|
|
|
fin.read(int(adlen))
|
|
|
|
|
2021-03-16 17:10:54 +01:00
|
|
|
# Read the salt, nonce, etc.
|
2021-03-18 20:15:32 +01:00
|
|
|
cs = fin.read(192)
|
|
|
|
crccs = fin.read(192)
|
|
|
|
digest = fin.read(144)
|
|
|
|
salt = fin.read(144)
|
|
|
|
nonce = fin.read(152)
|
|
|
|
# Reed-Solomon-decode each value
|
|
|
|
try:
|
|
|
|
cs = bytes(headerRsc.decode(cs)[0])
|
|
|
|
except:
|
|
|
|
headerBroken = True
|
|
|
|
cs = cs[:64]
|
|
|
|
try:
|
|
|
|
crccs = bytes(headerRsc.decode(crccs)[0])
|
|
|
|
except:
|
|
|
|
headerBroken = True
|
|
|
|
crccs = crccs[:64]
|
|
|
|
try:
|
|
|
|
digest = bytes(headerRsc.decode(digest)[0])
|
|
|
|
except:
|
|
|
|
headerBroken = True
|
|
|
|
digest = digest[:16]
|
|
|
|
try:
|
|
|
|
salt = bytes(headerRsc.decode(salt)[0])
|
|
|
|
except:
|
|
|
|
headerBroken = True
|
|
|
|
salt = salt[:16]
|
|
|
|
try:
|
|
|
|
nonce = bytes(headerRsc.decode(nonce)[0])
|
|
|
|
except:
|
|
|
|
headerBroken = True
|
|
|
|
nonce = nonce[:24]
|
|
|
|
|
|
|
|
if headerBroken:
|
|
|
|
if keep.get()!=1:
|
|
|
|
statusString.set(veryCorruptedNotice)
|
|
|
|
fin.close()
|
|
|
|
fout.close()
|
|
|
|
remove(outputFile)
|
|
|
|
# Reset UI
|
|
|
|
selectFileInput["state"] = "normal"
|
|
|
|
passwordInput["state"] = "normal"
|
|
|
|
adArea["state"] = "normal"
|
|
|
|
startBtn["state"] = "normal"
|
|
|
|
keepBtn["state"] = "normal"
|
|
|
|
working = False
|
|
|
|
progress.stop()
|
|
|
|
progress.config(mode="determinate")
|
|
|
|
progress["value"] = 100
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
kept = "badlyCorrupted"
|
2021-03-13 18:11:06 +01:00
|
|
|
|
2021-03-15 19:41:15 +01:00
|
|
|
# Show notice about key derivation
|
2021-03-13 18:11:06 +01:00
|
|
|
statusString.set(derivingNotice)
|
|
|
|
|
|
|
|
# Derive argon2id key
|
|
|
|
key = hash_secret_raw(
|
|
|
|
password,
|
|
|
|
salt,
|
|
|
|
time_cost=8, # 8 iterations
|
2021-03-17 18:44:57 +01:00
|
|
|
memory_cost=2**20, # 2^20 Kibibytes (1GiB)
|
2021-03-13 18:11:06 +01:00
|
|
|
parallelism=8, # 8 parallel threads
|
|
|
|
hash_len=32,
|
|
|
|
type=Type.ID
|
|
|
|
)
|
|
|
|
|
|
|
|
# Key deriving done, set progress bar determinate
|
|
|
|
progress.stop()
|
|
|
|
progress.config(mode="determinate")
|
|
|
|
progress["value"] = 0
|
|
|
|
|
|
|
|
# Compute hash of derived key
|
2021-03-19 03:26:52 +01:00
|
|
|
check = sha3_512.new()
|
2021-03-19 03:03:21 +01:00
|
|
|
check.update(key)
|
|
|
|
check = check.digest()
|
2021-03-13 18:11:06 +01:00
|
|
|
|
|
|
|
# If decrypting, check if key is correct
|
|
|
|
if mode=="decrypt":
|
|
|
|
# If key is incorrect...
|
|
|
|
if not compare_digest(check,cs):
|
2021-03-17 18:20:18 +01:00
|
|
|
if not headerBroken:
|
|
|
|
statusString.set(passwordNotice)
|
|
|
|
fin.close()
|
|
|
|
fout.close()
|
|
|
|
remove(outputFile)
|
|
|
|
# Reset UI
|
|
|
|
selectFileInput["state"] = "normal"
|
|
|
|
passwordInput["state"] = "normal"
|
|
|
|
adArea["state"] = "normal"
|
|
|
|
startBtn["state"] = "normal"
|
|
|
|
keepBtn["state"] = "normal"
|
|
|
|
working = False
|
|
|
|
progress["value"] = 100
|
|
|
|
del key
|
|
|
|
return
|
2021-03-13 18:11:06 +01:00
|
|
|
|
|
|
|
# Create XChaCha20-Poly1305 object
|
|
|
|
cipher = ChaCha20_Poly1305.new(key=key,nonce=nonce)
|
|
|
|
# Cyclic redundancy check for file corruption
|
2021-03-19 03:26:52 +01:00
|
|
|
crc = sha3_512.new()
|
2021-03-13 18:11:06 +01:00
|
|
|
|
2021-03-16 17:10:54 +01:00
|
|
|
# Amount of data encrypted/decrypted, total file size, starting time
|
2021-03-13 18:11:06 +01:00
|
|
|
done = 0
|
|
|
|
total = getsize(inputFile)
|
|
|
|
|
|
|
|
# If secure wipe enabled, create a wiper object
|
|
|
|
if wipe:
|
|
|
|
wiper = open(inputFile,"r+b")
|
|
|
|
wiper.seek(0)
|
|
|
|
|
2021-03-17 22:01:37 +01:00
|
|
|
# Keep track of time because it flies...
|
|
|
|
startTime = datetime.now()
|
|
|
|
previousTime = datetime.now()
|
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Continously read file in chunks of 1MB
|
|
|
|
while True:
|
2021-03-15 19:41:15 +01:00
|
|
|
if mode=="decrypt" and reedsolo:
|
2021-03-16 17:10:54 +01:00
|
|
|
# Read a chunk plus Reed-Solomon recovery bytes
|
2021-03-17 18:20:18 +01:00
|
|
|
piece = fin.read(1104905)
|
2021-03-15 19:41:15 +01:00
|
|
|
else:
|
|
|
|
piece = fin.read(chunkSize)
|
2021-03-13 18:11:06 +01:00
|
|
|
if wipe:
|
|
|
|
# If securely wipe, write random trash
|
|
|
|
# to original file after reading it
|
|
|
|
trash = urandom(len(piece))
|
|
|
|
wiper.write(trash)
|
|
|
|
# If EOF
|
|
|
|
if not piece:
|
|
|
|
if mode=="encrypt":
|
2021-03-16 17:10:54 +01:00
|
|
|
# Get the cipher MAC tag (Poly1305)
|
2021-03-13 18:11:06 +01:00
|
|
|
digest = cipher.digest()
|
|
|
|
fout.flush()
|
|
|
|
fout.close()
|
|
|
|
fout = open(outputFile,"r+b")
|
2021-03-18 20:15:32 +01:00
|
|
|
# Compute the offset and seek to it (unshift "+")
|
2021-03-15 19:41:15 +01:00
|
|
|
rsOffset = 1 if reedsolo else 0
|
2021-03-18 20:15:32 +01:00
|
|
|
fout.seek(138+len(ad)+rsOffset)
|
2021-03-16 17:10:54 +01:00
|
|
|
# Write hash of key, CRC, and Poly1305 MAC tag
|
2021-03-18 20:15:32 +01:00
|
|
|
fout.write(bytes(headerRsc.encode(check)))
|
|
|
|
fout.write(bytes(headerRsc.encode(crc.digest())))
|
|
|
|
fout.write(bytes(headerRsc.encode(digest)))
|
2021-03-13 18:11:06 +01:00
|
|
|
else:
|
2021-03-17 18:20:18 +01:00
|
|
|
# If decrypting, verify CRC
|
2021-03-13 18:11:06 +01:00
|
|
|
crcdg = crc.digest()
|
|
|
|
if not compare_digest(crccs,crcdg):
|
|
|
|
# File is corrupted
|
|
|
|
statusString.set(corruptedNotice)
|
|
|
|
progress["value"] = 100
|
|
|
|
fin.close()
|
|
|
|
fout.close()
|
2021-03-15 19:41:15 +01:00
|
|
|
# If keep file not checked...
|
2021-03-13 18:11:06 +01:00
|
|
|
if keep.get()!=1:
|
|
|
|
remove(outputFile)
|
2021-03-16 17:10:54 +01:00
|
|
|
# Reset UI
|
2021-03-13 18:11:06 +01:00
|
|
|
selectFileInput["state"] = "normal"
|
|
|
|
passwordInput["state"] = "normal"
|
|
|
|
adArea["state"] = "normal"
|
|
|
|
startBtn["state"] = "normal"
|
|
|
|
keepBtn["state"] = "normal"
|
|
|
|
working = False
|
|
|
|
del fin,fout,cipher,key
|
|
|
|
return
|
|
|
|
else:
|
2021-03-17 18:20:18 +01:00
|
|
|
if not kept:
|
|
|
|
kept = "corrupted"
|
|
|
|
# Next, verify MAC tag (Poly1305)
|
2021-03-13 18:11:06 +01:00
|
|
|
try:
|
2021-03-16 17:10:54 +01:00
|
|
|
# Throws ValueError if incorrect Poly1305
|
2021-03-13 18:11:06 +01:00
|
|
|
cipher.verify(digest)
|
|
|
|
except:
|
2021-03-17 18:20:18 +01:00
|
|
|
if not reedsoloErrorCount and not headerBroken:
|
2021-03-15 19:41:15 +01:00
|
|
|
# File is modified
|
|
|
|
statusString.set(modifiedNotice)
|
|
|
|
progress["value"] = 100
|
|
|
|
fin.close()
|
|
|
|
fout.close()
|
|
|
|
# If keep file not checked...
|
|
|
|
if keep.get()!=1:
|
|
|
|
remove(outputFile)
|
2021-03-16 17:10:54 +01:00
|
|
|
# Reset UI
|
2021-03-15 19:41:15 +01:00
|
|
|
selectFileInput["state"] = "normal"
|
|
|
|
passwordInput["state"] = "normal"
|
|
|
|
adArea["state"] = "normal"
|
|
|
|
startBtn["state"] = "normal"
|
|
|
|
keepBtn["state"] = "normal"
|
|
|
|
working = False
|
|
|
|
del fin,fout,cipher,key
|
|
|
|
return
|
|
|
|
else:
|
2021-03-17 18:20:18 +01:00
|
|
|
if not kept:
|
|
|
|
kept = "modified"
|
2021-03-15 19:41:15 +01:00
|
|
|
break
|
|
|
|
|
|
|
|
# Encrypt/decrypt chunk and update CRC
|
|
|
|
if mode=="encrypt":
|
2021-03-16 17:10:54 +01:00
|
|
|
# Encrypt piece
|
2021-03-15 19:41:15 +01:00
|
|
|
data = cipher.encrypt(piece)
|
2021-03-16 17:10:54 +01:00
|
|
|
# Update checksum
|
2021-03-15 19:41:15 +01:00
|
|
|
crc.update(data)
|
|
|
|
if reedsolo:
|
2021-03-16 17:10:54 +01:00
|
|
|
# Encode using Reed-Solomon if user chooses
|
2021-03-15 19:41:15 +01:00
|
|
|
data = bytes(rsc.encode(data))
|
|
|
|
else:
|
2021-03-16 17:10:54 +01:00
|
|
|
# Basically encrypting but in reverse
|
2021-03-15 19:41:15 +01:00
|
|
|
if reedsolo:
|
|
|
|
try:
|
|
|
|
data,_,fixed = rsc.decode(piece)
|
|
|
|
except ReedSolomonError:
|
|
|
|
# File is really corrupted
|
|
|
|
if not reedsoloErrorCount:
|
2021-03-17 18:20:18 +01:00
|
|
|
if keep.get()!=1:
|
|
|
|
statusString.set(veryCorruptedNotice)
|
|
|
|
progress["value"] = 100
|
2021-03-15 19:41:15 +01:00
|
|
|
# If keep file not checked...
|
2021-03-13 18:11:06 +01:00
|
|
|
if keep.get()!=1:
|
2021-03-15 19:41:15 +01:00
|
|
|
fin.close()
|
|
|
|
fout.close()
|
2021-03-13 18:11:06 +01:00
|
|
|
remove(outputFile)
|
2021-03-16 17:10:54 +01:00
|
|
|
# Reset UI
|
2021-03-13 18:11:06 +01:00
|
|
|
selectFileInput["state"] = "normal"
|
|
|
|
passwordInput["state"] = "normal"
|
|
|
|
adArea["state"] = "normal"
|
|
|
|
startBtn["state"] = "normal"
|
|
|
|
keepBtn["state"] = "normal"
|
|
|
|
working = False
|
2021-03-17 18:20:18 +01:00
|
|
|
progress["value"] = 100
|
2021-03-13 18:11:06 +01:00
|
|
|
del fin,fout,cipher,key
|
|
|
|
return
|
|
|
|
else:
|
2021-03-17 18:20:18 +01:00
|
|
|
kept = "badlyCorrupted"
|
|
|
|
# Attempt to recover badly corrupted data
|
|
|
|
data = b""
|
|
|
|
piece = piece[:-13]
|
|
|
|
counter = 0
|
|
|
|
while True:
|
|
|
|
# Basically just strip the Reed-Solomon bytes
|
|
|
|
# and return the original non-encoded data
|
|
|
|
if counter<1104905:
|
|
|
|
data += piece[counter:counter+242]
|
|
|
|
counter += 255 # 255 bytes, 242 original
|
|
|
|
else:
|
|
|
|
break
|
2021-03-15 19:41:15 +01:00
|
|
|
fixed = bytearray()
|
|
|
|
reedsoloErrorCount += 1
|
|
|
|
data = bytes(data)
|
|
|
|
reedsoloFixedCount += len(fixed)
|
|
|
|
crc.update(data)
|
|
|
|
data = cipher.decrypt(data)
|
|
|
|
else:
|
|
|
|
crc.update(piece)
|
|
|
|
data = cipher.decrypt(piece)
|
2021-03-13 18:11:06 +01:00
|
|
|
|
|
|
|
# Calculate speed, ETA, etc.
|
|
|
|
first = False
|
2021-03-19 03:09:04 +01:00
|
|
|
elapsed = (datetime.now()-previousTime).total_seconds() or 0.0001
|
|
|
|
sinceStart = (datetime.now()-startTime).total_seconds() or 0.0001
|
2021-03-17 22:01:37 +01:00
|
|
|
previousTime = datetime.now()
|
2021-03-16 17:10:54 +01:00
|
|
|
# Prevent divison by zero
|
|
|
|
if not elapsed:
|
2021-03-13 18:11:06 +01:00
|
|
|
elapsed = 0.1**6
|
|
|
|
percent = done*100/total
|
|
|
|
progress["value"] = percent
|
|
|
|
rPercent = round(percent)
|
2021-03-17 22:01:37 +01:00
|
|
|
speed = (done/sinceStart)/10**6
|
2021-03-16 17:10:54 +01:00
|
|
|
# Prevent divison by zero
|
|
|
|
if not speed:
|
2021-03-13 18:11:06 +01:00
|
|
|
first = True
|
|
|
|
speed = 0.1**6
|
2021-03-17 22:01:37 +01:00
|
|
|
rSpeed = str(round(speed,2))
|
2021-03-18 20:15:32 +01:00
|
|
|
# Right-pad with zeros to large prevent layout shifts
|
2021-03-17 22:01:37 +01:00
|
|
|
while len(rSpeed.split(".")[1])!=2:
|
|
|
|
rSpeed += "0"
|
2021-03-13 18:11:06 +01:00
|
|
|
eta = round((total-done)/(speed*10**6))
|
2021-03-16 17:10:54 +01:00
|
|
|
# Seconds to minutes if seconds more than 59
|
2021-03-15 19:41:15 +01:00
|
|
|
if eta>=60:
|
|
|
|
eta = f"{eta//60}m {eta%60}"
|
2021-03-17 22:01:37 +01:00
|
|
|
if isinstance(eta,int) or isinstance(eta,float):
|
|
|
|
if eta<0:
|
|
|
|
eta = 0
|
2021-03-16 17:10:54 +01:00
|
|
|
# If it's the first round and no data/predictions yet...
|
2021-03-13 18:11:06 +01:00
|
|
|
if first:
|
|
|
|
statusString.set("...% at ... MB/s (ETA: ...s)")
|
|
|
|
else:
|
2021-03-16 17:10:54 +01:00
|
|
|
# Update status
|
2021-03-13 18:11:06 +01:00
|
|
|
info = f"{rPercent}% at {rSpeed} MB/s (ETA: {eta}s)"
|
2021-03-15 19:41:15 +01:00
|
|
|
if reedsolo and mode=="decrypt" and reedsoloFixedCount:
|
2021-03-17 18:20:18 +01:00
|
|
|
eng = "s" if reedsoloFixedCount!=1 else ""
|
|
|
|
info += f", fixed {reedsoloFixedCount} corrupted byte{eng}"
|
2021-03-15 19:41:15 +01:00
|
|
|
if reedsolo and mode=="decrypt" and reedsoloErrorCount:
|
|
|
|
info += f", {reedsoloErrorCount} MB unrecoverable"
|
2021-03-13 18:11:06 +01:00
|
|
|
statusString.set(info)
|
|
|
|
|
2021-03-16 17:10:54 +01:00
|
|
|
# Increase done and write to output
|
2021-03-17 23:47:33 +01:00
|
|
|
done += 1104905 if (reedsolo and mode=="decrypt") else chunkSize
|
2021-03-13 18:11:06 +01:00
|
|
|
fout.write(data)
|
|
|
|
|
|
|
|
# Show appropriate notice if file corrupted or modified
|
|
|
|
if not kept:
|
|
|
|
if mode=="encrypt":
|
2021-03-16 20:07:25 +01:00
|
|
|
output = inputFile.split("/")[-1]+".pcv"
|
2021-03-13 18:11:06 +01:00
|
|
|
else:
|
2021-03-18 20:15:32 +01:00
|
|
|
output = inputFile.split("/")[-1].replace(".pcv","")
|
2021-03-13 18:11:06 +01:00
|
|
|
statusString.set(f"Completed. (Output: {output})")
|
2021-03-16 17:10:54 +01:00
|
|
|
# Show Reed-Solomon stats if it fixed corrupted bytes
|
2021-03-15 19:41:15 +01:00
|
|
|
if mode=="decrypt" and reedsolo and reedsoloFixedCount:
|
|
|
|
statusString.set(f"Completed with {reedsoloFixedCount} bytes fixed."+
|
|
|
|
f" (Output: {output})")
|
2021-03-13 18:11:06 +01:00
|
|
|
else:
|
|
|
|
if kept=="modified":
|
|
|
|
statusString.set(kModifiedNotice)
|
2021-03-17 18:20:18 +01:00
|
|
|
elif kept=="corrupted":
|
2021-03-13 18:11:06 +01:00
|
|
|
statusString.set(kCorruptedNotice)
|
2021-03-17 18:20:18 +01:00
|
|
|
else:
|
|
|
|
statusString.set(kVeryCorruptedNotice)
|
2021-03-13 18:11:06 +01:00
|
|
|
|
|
|
|
# Reset variables and UI states
|
|
|
|
selectFileInput["state"] = "normal"
|
|
|
|
adArea["state"] = "normal"
|
|
|
|
adArea.delete("1.0",tkinter.END)
|
|
|
|
adArea["state"] = "disabled"
|
|
|
|
startBtn["state"] = "disabled"
|
|
|
|
passwordInput["state"] = "normal"
|
|
|
|
passwordInput.delete(0,"end")
|
|
|
|
passwordInput["state"] = "disabled"
|
2021-03-18 15:46:21 +01:00
|
|
|
cpasswordInput["state"] = "normal"
|
|
|
|
cpasswordInput.delete(0,"end")
|
|
|
|
cpasswordInput["state"] = "disabled"
|
2021-03-13 18:11:06 +01:00
|
|
|
progress["value"] = 0
|
|
|
|
inputString.set("Please select a file.")
|
|
|
|
keepBtn["state"] = "normal"
|
|
|
|
keep.set(0)
|
|
|
|
keepBtn["state"] = "disabled"
|
|
|
|
eraseBtn["state"] = "normal"
|
|
|
|
erase.set(0)
|
|
|
|
eraseBtn["state"] = "disabled"
|
2021-03-15 19:41:15 +01:00
|
|
|
rs.set(0)
|
|
|
|
rsBtn["state"] = "disabled"
|
2021-03-13 18:11:06 +01:00
|
|
|
if not kept:
|
|
|
|
fout.flush()
|
|
|
|
fsync(fout.fileno())
|
|
|
|
fout.close()
|
|
|
|
fin.close()
|
|
|
|
if wipe:
|
|
|
|
# Make sure to flush file
|
|
|
|
wiper.flush()
|
|
|
|
fsync(wiper.fileno())
|
|
|
|
wiper.close()
|
|
|
|
remove(inputFile)
|
|
|
|
inputFile = ""
|
|
|
|
outputFile = ""
|
|
|
|
password = ""
|
|
|
|
ad = ""
|
|
|
|
kept = False
|
|
|
|
working = False
|
|
|
|
# Wipe keys for safety
|
|
|
|
del fin,fout,cipher,key
|
|
|
|
|
|
|
|
# Wraps the start() function with error handling
|
2021-02-24 17:54:34 +01:00
|
|
|
def wrapper():
|
2021-03-18 15:46:21 +01:00
|
|
|
global working,gMode
|
2021-03-13 18:11:06 +01:00
|
|
|
# Try start() and handle errors
|
|
|
|
try:
|
|
|
|
start()
|
2021-03-17 22:01:37 +01:00
|
|
|
except:
|
2021-03-18 15:46:21 +01:00
|
|
|
# Reset UI accordingly
|
|
|
|
progress.stop()
|
|
|
|
progress.config(mode="determinate")
|
2021-03-15 19:41:15 +01:00
|
|
|
progress["value"] = 100
|
2021-03-13 18:11:06 +01:00
|
|
|
selectFileInput["state"] = "normal"
|
|
|
|
passwordInput["state"] = "normal"
|
|
|
|
startBtn["state"] = "normal"
|
2021-03-18 15:46:21 +01:00
|
|
|
|
|
|
|
if gMode=="decrypt":
|
|
|
|
keepBtn["state"] = "normal"
|
|
|
|
else:
|
|
|
|
adArea["state"] = "normal"
|
|
|
|
cpasswordInput["state"] = "normal"
|
|
|
|
rsBtn["state"] = "normal"
|
|
|
|
eraseBtn["state"] = "normal"
|
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
statusString.set(unknownErrorNotice)
|
|
|
|
dummy.focus()
|
|
|
|
working = False
|
|
|
|
finally:
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
# Encryption/decrypt is done is a separate thread
|
|
|
|
# so the UI isn't blocked. This is a wrapper
|
|
|
|
# to spawn a thread and start it.
|
2021-02-19 01:43:18 +01:00
|
|
|
def startWorker():
|
2021-03-13 18:11:06 +01:00
|
|
|
thread = Thread(target=wrapper,daemon=True)
|
|
|
|
thread.start()
|
2021-02-19 01:43:18 +01:00
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# ad stands for "associated data"/metadata
|
2021-02-19 01:43:18 +01:00
|
|
|
adLabelString = tkinter.StringVar(tk)
|
|
|
|
adLabelString.set(adString)
|
|
|
|
adLabel = tkinter.ttk.Label(
|
2021-03-13 18:11:06 +01:00
|
|
|
tk,
|
|
|
|
textvariable=adLabelString
|
2021-02-19 01:43:18 +01:00
|
|
|
)
|
2021-03-18 15:46:21 +01:00
|
|
|
adLabel.place(x=17,y=158)
|
2021-02-19 01:43:18 +01:00
|
|
|
adLabel.config(background="#f5f6f7")
|
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Frame so metadata text box can fill width
|
2021-02-19 01:43:18 +01:00
|
|
|
adFrame = tkinter.Frame(
|
2021-03-13 18:11:06 +01:00
|
|
|
tk,
|
|
|
|
width=440,
|
|
|
|
height=100
|
2021-02-19 01:43:18 +01:00
|
|
|
)
|
2021-03-18 15:46:21 +01:00
|
|
|
adFrame.place(x=20,y=178)
|
2021-02-19 01:43:18 +01:00
|
|
|
adFrame.columnconfigure(0,weight=10)
|
|
|
|
adFrame.grid_propagate(False)
|
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Metadata text box
|
2021-02-19 16:30:39 +01:00
|
|
|
adArea = tkinter.Text(
|
2021-03-13 18:11:06 +01:00
|
|
|
adFrame,
|
|
|
|
exportselection=0
|
2021-02-19 01:43:18 +01:00
|
|
|
)
|
|
|
|
adArea.config(font=("Consolas",12))
|
|
|
|
adArea.grid(sticky="we")
|
|
|
|
adArea["state"] = "disabled"
|
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Check box for keeping corrupted/modified output
|
2021-02-19 01:43:18 +01:00
|
|
|
keep = tkinter.IntVar()
|
|
|
|
keepBtn = tkinter.ttk.Checkbutton(
|
2021-03-13 18:11:06 +01:00
|
|
|
tk,
|
|
|
|
text=keepNotice,
|
|
|
|
variable=keep,
|
|
|
|
onvalue=1,
|
|
|
|
offvalue=0,
|
|
|
|
command=lambda:dummy.focus()
|
2021-02-19 01:43:18 +01:00
|
|
|
)
|
2021-03-18 15:46:21 +01:00
|
|
|
keepBtn.place(x=18,y=290)
|
2021-02-19 01:43:18 +01:00
|
|
|
keepBtn["state"] = "disabled"
|
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Check box for securely erasing original file
|
2021-02-19 01:43:18 +01:00
|
|
|
erase = tkinter.IntVar()
|
|
|
|
eraseBtn = tkinter.ttk.Checkbutton(
|
2021-03-13 18:11:06 +01:00
|
|
|
tk,
|
|
|
|
text=eraseNotice,
|
|
|
|
variable=erase,
|
|
|
|
onvalue=1,
|
|
|
|
offvalue=0,
|
|
|
|
command=lambda:dummy.focus()
|
2021-02-19 01:43:18 +01:00
|
|
|
)
|
2021-03-18 15:46:21 +01:00
|
|
|
eraseBtn.place(x=18,y=310)
|
2021-02-19 01:43:18 +01:00
|
|
|
eraseBtn["state"] = "disabled"
|
|
|
|
|
2021-03-15 19:41:15 +01:00
|
|
|
# Check box for Reed Solomon
|
|
|
|
rs = tkinter.IntVar()
|
|
|
|
rsBtn = tkinter.ttk.Checkbutton(
|
|
|
|
tk,
|
|
|
|
text=rsNotice,
|
|
|
|
variable=rs,
|
|
|
|
onvalue=1,
|
|
|
|
offvalue=0,
|
|
|
|
command=lambda:dummy.focus()
|
|
|
|
)
|
2021-03-18 15:46:21 +01:00
|
|
|
rsBtn.place(x=18,y=330)
|
2021-03-15 19:41:15 +01:00
|
|
|
rsBtn["state"] = "disabled"
|
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Frame so start button can fill width
|
2021-02-19 01:43:18 +01:00
|
|
|
startFrame = tkinter.Frame(
|
2021-03-13 18:11:06 +01:00
|
|
|
tk,
|
|
|
|
width=442,
|
|
|
|
height=25
|
2021-02-19 01:43:18 +01:00
|
|
|
)
|
2021-03-18 15:46:21 +01:00
|
|
|
startFrame.place(x=19,y=360)
|
2021-02-19 01:43:18 +01:00
|
|
|
startFrame.columnconfigure(0,weight=10)
|
|
|
|
startFrame.grid_propagate(False)
|
2021-03-13 18:11:06 +01:00
|
|
|
# Start button
|
2021-02-19 01:43:18 +01:00
|
|
|
startBtn = tkinter.ttk.Button(
|
2021-03-13 18:11:06 +01:00
|
|
|
startFrame,
|
|
|
|
text="Start",
|
|
|
|
command=startWorker
|
2021-02-19 01:43:18 +01:00
|
|
|
)
|
|
|
|
startBtn.grid(sticky="nesw")
|
|
|
|
startBtn["state"] = "disabled"
|
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Progress bar
|
2021-02-19 01:43:18 +01:00
|
|
|
progress = tkinter.ttk.Progressbar(
|
2021-03-13 18:11:06 +01:00
|
|
|
tk,
|
|
|
|
orient=tkinter.HORIZONTAL,
|
|
|
|
length=440,
|
|
|
|
mode="determinate"
|
2021-02-19 01:43:18 +01:00
|
|
|
)
|
2021-03-18 15:46:21 +01:00
|
|
|
progress.place(x=20,y=388)
|
2021-02-19 01:43:18 +01:00
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Status label
|
2021-02-19 01:43:18 +01:00
|
|
|
statusString = tkinter.StringVar(tk)
|
|
|
|
statusString.set("Ready.")
|
|
|
|
status = tkinter.ttk.Label(
|
2021-03-13 18:11:06 +01:00
|
|
|
tk,
|
|
|
|
textvariable=statusString
|
2021-02-19 01:43:18 +01:00
|
|
|
)
|
2021-03-18 15:46:21 +01:00
|
|
|
status.place(x=17,y=416)
|
2021-02-19 01:43:18 +01:00
|
|
|
status.config(background="#f5f6f7")
|
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Credits :)
|
2021-02-25 17:35:54 +01:00
|
|
|
hint = "Created by Evan Su. Click for details and source."
|
2021-02-19 16:30:39 +01:00
|
|
|
creditsString = tkinter.StringVar(tk)
|
|
|
|
creditsString.set(hint)
|
|
|
|
credits = tkinter.ttk.Label(
|
2021-03-13 18:11:06 +01:00
|
|
|
tk,
|
|
|
|
textvariable=creditsString,
|
|
|
|
cursor="hand2"
|
2021-02-19 16:30:39 +01:00
|
|
|
)
|
|
|
|
credits["state"] = "disabled"
|
|
|
|
credits.config(background="#f5f6f7")
|
2021-03-18 15:46:21 +01:00
|
|
|
credits.place(x=17,y=446)
|
2021-02-19 16:30:39 +01:00
|
|
|
source = "https://github.com/HACKERALERT/Picocrypt"
|
|
|
|
credits.bind("<Button-1>",lambda e:webbrowser.open(source))
|
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Version
|
2021-02-24 17:54:34 +01:00
|
|
|
versionString = tkinter.StringVar(tk)
|
2021-03-18 16:16:30 +01:00
|
|
|
versionString.set("v1.10")
|
2021-02-24 17:54:34 +01:00
|
|
|
version = tkinter.ttk.Label(
|
2021-03-13 18:11:06 +01:00
|
|
|
tk,
|
|
|
|
textvariable=versionString
|
2021-02-24 17:54:34 +01:00
|
|
|
)
|
|
|
|
version["state"] = "disabled"
|
|
|
|
version.config(background="#f5f6f7")
|
2021-03-18 16:16:30 +01:00
|
|
|
version.place(x=430,y=446)
|
2021-02-19 16:30:39 +01:00
|
|
|
|
2021-03-13 18:11:06 +01:00
|
|
|
# Dummy button to remove focus from other buttons
|
|
|
|
# and prevent ugly border highlighting
|
2021-02-19 01:43:18 +01:00
|
|
|
dummy = tkinter.ttk.Button(
|
2021-03-13 18:11:06 +01:00
|
|
|
tk
|
2021-02-19 01:43:18 +01:00
|
|
|
)
|
|
|
|
dummy.place(x=480,y=0)
|
|
|
|
|
2021-03-18 20:15:32 +01:00
|
|
|
# Function to create Reed-Solomon header codec
|
|
|
|
def createRsc():
|
|
|
|
global headerRsc
|
|
|
|
headerRsc = RSCodec(128)
|
|
|
|
sys.exit(0)
|
|
|
|
|
2021-03-17 18:21:24 +01:00
|
|
|
# Close window only if not encrypting or decrypting
|
2021-02-19 01:43:18 +01:00
|
|
|
def onClose():
|
2021-03-13 18:11:06 +01:00
|
|
|
if not working:
|
|
|
|
tk.destroy()
|
2021-02-19 01:43:18 +01:00
|
|
|
|
2021-03-18 20:15:32 +01:00
|
|
|
# Main application loop
|
2021-02-19 01:43:18 +01:00
|
|
|
if __name__=="__main__":
|
2021-03-18 20:15:32 +01:00
|
|
|
# Create Reed-Solomon header codec
|
|
|
|
tmp = Thread(target=createRsc,daemon=True)
|
|
|
|
tmp.start()
|
|
|
|
# Start tkinter
|
2021-03-13 18:11:06 +01:00
|
|
|
tk.protocol("WM_DELETE_WINDOW",onClose)
|
|
|
|
tk.mainloop()
|
|
|
|
sys.exit(0)
|