1
0
Fork 0
mirror of https://github.com/HACKERALERT/Picocrypt.git synced 2024-09-20 17:56:35 +00:00

Update Picocrypt.py

This commit is contained in:
Evan Su 2021-03-23 14:59:36 -04:00 committed by GitHub
parent 40e64bda9c
commit dbdf208ab8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -45,7 +45,7 @@ try:
except: except:
pass pass
# Global variables and notices # Global variables and strings
rootDir = dirname(realpath(__file__)) rootDir = dirname(realpath(__file__))
inputFile = "" inputFile = ""
outputFile = "" outputFile = ""
@ -55,7 +55,7 @@ ad = ""
kept = False kept = False
working = False working = False
gMode = None gMode = None
headerRsc = None headerRsc = False
allFiles = False allFiles = False
draggedFolderPaths = False draggedFolderPaths = False
files = False files = False
@ -73,7 +73,7 @@ keepNotice = "Keep decrypted output even if it's corrupted or modified"
eraseNotice = "Securely erase and delete original file" eraseNotice = "Securely erase and delete original file"
erasingNotice = "Securely erasing original file(s)..." erasingNotice = "Securely erasing original file(s)..."
overwriteNotice = "Output file already exists. Would you like to overwrite it?" overwriteNotice = "Output file already exists. Would you like to overwrite it?"
cancelNotice = "Picocrypt is still working. Are you sure?" cancelNotice = "Exiting now will lead to broken output. Are you sure?"
rsNotice = "Prevent corruption using Reed-Solomon" rsNotice = "Prevent corruption using Reed-Solomon"
rscNotice = "Creating Reed-Solomon tables..." rscNotice = "Creating Reed-Solomon tables..."
unknownErrorNotice = "Unknown error occured. Please try again." unknownErrorNotice = "Unknown error occured. Please try again."
@ -96,26 +96,39 @@ except:
s = tkinter.ttk.Style() s = tkinter.ttk.Style()
s.configure("TCheckbutton",background="#ffffff") s.configure("TCheckbutton",background="#ffffff")
# Event when user selects an input file # Event when user drags file(s) and folder(s) into window
def inputSelected(draggedFile): def inputSelected(draggedFile):
global inputFile,working,headerRsc,allFiles global inputFile,working,headerRsc,allFiles,draggedFolderPaths,files
global draggedFolderPaths,files
resetUI() resetUI()
dummy.focus() dummy.focus()
status.config(cursor="") status.config(cursor="")
status.bind("<Button-1>",lambda e:None) status.bind("<Button-1>",lambda e:None)
# Try to handle when select file is cancelled # Use try to handle errors
try: try:
# Create list of input files
allFiles = [] allFiles = []
files = [] files = []
draggedFolderPaths = [] draggedFolderPaths = []
# Ask for input file
suffix = "" suffix = ""
tmp = [i for i in draggedFile] tmp = [i for i in draggedFile]
res = [] res = []
within = False within = False
tmpName = "" tmpName = ""
"""
The next for loop parses data return by tkinterdnd2's file drop method.
When files and folders are dragged, the output (the 'draggedFile' parameter)
will contain the dropped files/folders and will look something like this:
A single file/folder: "C:\Foo\Bar.txt"
A single file/folder with a space in path: "{C:\Foo Bar\Lorem.txt}"
Multiple files/folders: "C:\Foo\Bar1.txt C:\Foo\Ba2.txt"
Multiple files/folders with spaces in paths:
- "C:\Foo\Bar1.txt {C:\Foo Bar\Lorem.txt}"
- "{C:\Foo Bar\Lorem.txt} C:\Foo\Bar1.txt"
- "{C:\Foo Bar\Lorem1.txt} {C:\Foo Bar\Lorem2.txt}"
"""
for i in tmp: for i in tmp:
if i=="{": if i=="{":
within = True within = True
@ -136,15 +149,20 @@ def inputSelected(draggedFile):
allFiles = [] allFiles = []
files = [] files = []
# Check each thing dragged by user
for i in res: for i in res:
# If there is a directory, recursively add all files to 'allFiles'
if isdir(i): if isdir(i):
# Record the directory for secure wipe (if necessary)
draggedFolderPaths.append(i) draggedFolderPaths.append(i)
tmp = Path(i).rglob("*") tmp = Path(i).rglob("*")
for p in tmp: for p in tmp:
allFiles.append(abspath(p)) allFiles.append(abspath(p))
# Just a file, add it to files
else: else:
files.append(i) files.append(i)
# If there's only one file, set it as input file
if len(files)==1 and len(allFiles)==0: if len(files)==1 and len(allFiles)==0:
inputFile = files[0] inputFile = files[0]
files = [] files = []
@ -210,7 +228,7 @@ def inputSelected(draggedFile):
nFiles = len(files) nFiles = len(files)
nFolders = len(draggedFolderPaths) nFolders = len(draggedFolderPaths)
# Show selected file(s) # Show selected file(s) and folder(s)
if (allFiles or files) and not draggedFolderPaths: if (allFiles or files) and not draggedFolderPaths:
inputString.set(f"{nFiles} files selected (will encrypt).") inputString.set(f"{nFiles} files selected (will encrypt).")
elif draggedFolderPaths and not files: elif draggedFolderPaths and not files:
@ -222,11 +240,6 @@ def inputSelected(draggedFile):
) )
else: else:
inputString.set(inputFile.split("/")[-1]+suffix) inputString.set(inputFile.split("/")[-1]+suffix)
'''if allFiles or files:
inputString.set(f"{len(allFiles) or len(files)}"+
" files selected (will encrypt).")
else:
inputString.set(inputFile.split("/")[-1]+suffix)'''
# Enable password box, etc. # Enable password box, etc.
passwordInput["state"] = "normal" passwordInput["state"] = "normal"
@ -242,7 +255,7 @@ def inputSelected(draggedFile):
statusString.set(corruptedNotice) statusString.set(corruptedNotice)
progress["value"] = 100 progress["value"] = 100
# No file selected, do nothing # No file(s) selected, do nothing
except: except:
inputString.set("Drag and drop file(s) and folder(s) into this window.") inputString.set("Drag and drop file(s) and folder(s) into this window.")
resetUI() resetUI()
@ -252,6 +265,7 @@ def inputSelected(draggedFile):
dummy.focus() dummy.focus()
working = False working = False
# Clears the selected files
def clearInputs(): def clearInputs():
dummy.focus() dummy.focus()
resetUI() resetUI()
@ -534,7 +548,7 @@ def start():
password, password,
salt, salt,
time_cost=8, # 8 iterations time_cost=8, # 8 iterations
memory_cost=2**10, # 2^20 Kibibytes (1GiB) memory_cost=2**20, # 2^20 Kibibytes (1GiB)
parallelism=8, # 8 parallel threads parallelism=8, # 8 parallel threads
hash_len=32, hash_len=32,
type=Type.ID type=Type.ID
@ -1072,7 +1086,7 @@ def createRsc():
sys.exit(0) sys.exit(0)
def prepare(): def prepare():
system("sdelete64.exe /accepteula -nobanner") system("sdelete64.exe /accepteula")
# Close window only if not encrypting or decrypting # Close window only if not encrypting or decrypting
def onClose(): def onClose():