beardboy
Joined: 02 Mar 2004 Posts: 444 Location: SLC, Utah
|
Posted: Fri Apr 16, 2004 10:38 pm Post subject: Encryption |
|
|
Here are two small programs I wrote to be able to quickly encrypt and decrypt any file on my hard drive with a password. Good for keeping non technical people out of your files, plus it compresses the file size.
In order to use these though you need to have Winzip 7.0 or greater installed as well as WinZip Command line support. And you need to add the winzip folder to your path.
| Code: | ; Program: Encrypter
; Version: 01
; Last Modified: 2004.03.25
; Last Changes: Rewritten using AutoHotkey
linenum = 0
file = %1%
if file = ; If not file sent to program Terminate Program.
{
MsgBox, 0, No File Selected, No File Selected, program terminating.
Exit
}
StringLen, filelength, file
Loop
{
filelength -= 1
StringMid, filetemp, file, %filelength%, 1
if filetemp = \
{
break
}
}
StringLeft, filepath, file, %filelength% ; Path
StringTrimLeft, filename, file, %filelength% ; Filename with extension
StringRight, fileext, filename, 3 ; File Extension
StringTrimRight, filenoext, filename, 4 ; Filename with no extension
Loop
{
InputBox, password, Encrypter, Enter Password for file:, hide ; Get Password
InputBox, password1, Encrypter, Re-Enter Password to verify:, hide ; Verify Password
if password = %password1% ; If passwords match break loop
{
break
}
MsgBox, 4, Passwords don't match, Passwords don't match`, would you like to re-enter?
IfMsgBox, No, Exit
}
MsgBox, 4, Delete Original File?, Would you like to delete the Original File?`n`nIf no it will be renamed to %filenoext%.org.%fileext%
IfMsgBox, Yes, SetEnv, delfile, 1
RunWait, %comspec% /c wzzip -ex -s%password% "%filepath%temp.zip" "%file%",,hide ; Zip file with password into temp.zip
RunWait, %comspec% /c ren "%file%" "%filenoext%.org.%fileext%",,hide ; Rename original file to .org
RunWait, %comspec% /c ren "%filepath%temp.zip" 15.950,,hide ; Rename temp.zip to 15.950
RunWait, %comspec% /c wzzip -ex -s%password% "%filepath%temp.zip" "%filepath%15.950",,hide ; Zip up 15.950 to temp.zip
RunWait, %comspec% /c del "%filepath%15.950",,hide ; Delete 15.950
RunWait, %comspec% /c ren "%filepath%temp.zip" "%filename%",,hide ; Rename temp.zip to orignal filename
IfNotExist, %file% ; If new encrypted file doesn't exist...
{
MsgBox, 0, Encryption Problem, There was a problem Encrypting your file`, your original file has been left alone.
RunWait, %comspec% /c ren "%filepath%%filenoext%.org.%fileext%" "%filename%",,hide ; Rename .org file back to original file.
Exit
}
if delfile = 1 ; If user wanted original file deleted delete the .org
{
RunWait, %comspec% /c del "%filepath%%filenoext%.org.%fileext%",, hide
}
Exit |
| Code: | ; Program: Decrypter
; Version: 01
; Last Modified: 2004.03.25
; Last Changes: Rewritten using AutoHotkey
linenum = 0
file = %1%
if file = ; If not file sent to program Terminate Program.
{
MsgBox, 0, No File Selected, No File Selected, program terminating.
Exit
}
StringLen, filelength, file
Loop
{
filelength -= 1
StringMid, filetemp, file, %filelength%, 1
if filetemp = \
{
break
}
}
StringLeft, filepath, file, %filelength% ; Path
StringTrimLeft, filename, file, %filelength% ; Filename with extension
StringRight, fileext, filename, 3 ; File Extension
StringTrimRight, filenoext, filename, 4 ; Filename with no extension
fileorg = %filenoext%.org.%fileext% ; .org File
InputBox, password, Decrypter, Enter Password for file:, hide ; Get Password
RunWait, %comspec% /c ren "%file%" "%filenoext%.org.%fileext%",,hide ; Rename original file to .org
RunWait, %comspec% /c wzunzip -o- -s%password% "%filepath%%filenoext%.org.%fileext%" "%filepath%",,hide ; Unzip file with password into temp.zip
IfNotExist, %filepath%Logs.log ; If logs.log does not exist
{
IfNotExist, %filepath%15.950 ; If 15.950 does not exit
{
RunWait, %comspec% /c ren "%filepath%%filenoext%.org.%fileext%" "%filename%",,hide ; Rename .org file back to original filename
MsgBox, 0, Wrong Password?, Password you entered appears to be incorrect.`nProgram closing.
Exit
}
}
RunWait, %comspec% /c wzunzip -o- -s%password% "%filepath%Logs.log" "%filepath%",,hide ; If Logs.log file exists unzip
RunWait, %comspec% /c wzunzip -o- -s%password% "%filepath%15.950" "%filepath%",,hide ; If 15.950 file exists unzip
IfExist, %filepath%15.950
{
RunWait, %comspec% /c wzunzip -vb "%filepath%15.950">"%filepath%test.txt",,hide ; Find name of file being extracted
FileReadLine, line, %filepath%test.txt, 8
StringMid, zipfile, line, 43, 20
}
IfExist, %filepath%Logs.log
{
RunWait, %comspec% /c wzunzip -vb "%filepath%Logs.log">"%filepath%test.txt",,hide ; Find name of file being extracted
FileReadLine, line, %filepath%test.txt, 8
StringMid, zipfile, line, 43, 20
}
if filename = %zipfile% ; If file being extracted is the same name as Encrypted file
{
RunWait, %comspec% /c ren "%file%" "%filenoext%.new.%fileext%",,hide ; Rename extracted file to .new
RunWait, %comspec% /c ren "%filepath%%filenoext%.org.%fileext%" "%filename%",,hide ; Rename .org to original file
}
else
{
RunWait, %comspec% /c ren "%filepath%%filenoext%.org.%fileext%" "%filename%",,hide ; Rename .org to original file
}
RunWait, %comspec% /c del "%filepath%test.txt",,hide
RunWait, %comspec% /c del "%filepath%Logs.log",,hide
RunWait, %comspec% /c del "%filepath%15.950",,hide
Exit |
thanks,
beardboy |
|