Below is what I have so far. I'm posting in this thread because I borrowed code from Learning one's script.
The script basically copies selected message to clipboard and then applies Deo's Crypt.Encrypt.StrEncrypt or Crypt.Encrypt.StrDecrypt to either encrypt or decrypt the text using AES_256 encryption and SHA_512 hash by default.
The default hotkeys are Shift+F1 to encrypt and Shift+F2 to decrypt. Shift+Esc to see hotkeys or exit script (it has no tray icon by default).
Encrypted text replaces the original text. Decrypted text is shown in a message box. You can also try Shift+F3 to select all text and decrypt the bottom or top (short or long press) of the message, but I'm not sure how reliable this hotkey will be. See comments at the beginning of the script for details.
If you decide to use the script for real, then please change the password and compile it.
You also need Deo's CryptFoos.ahk, Crypt.ahk, CryptConst.ahk scripts, available here: http://www.autohotke...yption-hashing/
Suggestions to improve the script or make the clipboard functions more reliable are welcome.
/****************************************************************
SCRIPT: Cryptor.ahk by pajenn
PURPOSE:
The purpose of this script is to allow users to quickly encrypt/decrypt text, for example in an email or instant message, by press of a hotkey.
HOTKEYS (defaults):
Shift+F1: Encrypt selected text. Long pressing F1 (over 0.3 seconds) will also send Shift+Home to the active window, which in effect auto-selects one line for you. This is meant as a convenience when typing short (one line) messages into an IM application like Skype, but may be unreliable (sometimes long press doesn't work).
Shift+F2: Decrypt selected text and display it in a text box. You do not have to select the exact text to decrypt, just a block of text that includes the [begin_encrypt]...[end_encrypt] markers. If the selection includes multiple encrypted messages, only the top one is displayed.
Shift+F3 (unreliable): Select all text in an active window (sends Ctrl+A followed by Ctrl+C) and opens the bottom encrypted message (short press) or top encrypted message (long press) from it. Long press is over 0.3 seconds press of F3.
Shift+F3 can save you the step of having to select the text to decrypt manually. Short press is better suited for instant messaging applications such as Skype because they tend to display the most recent message at the bottom. Long press is intended to decrypt emails, for example, where the encrypted message is usually at the top.
Shift+Esc: Displays hotkeys and gives user option to exit Cryptor.
NOTE:
This is meant to be a convenient method to encrypt/decrypt instant messages and emails in cases when the applications used for communication do not provide good built-in options for encryption. If possible, I'd suggest the use of proper PGP encryption schemes instead such as Thurderbird with Enigmail plugin for email and Jitsi for encrypted IMs/VoIP, but this script can be more convenient to privately converse with contacts who do not want to use Thurderbird, Jitsi or other products with good encryption support.
DEFAULT ENCRYPTION ALGORITHMS:
AES_256 encryption and SHA_512 hash (but you can change these in Deo's Crypt.Encrypt.StrEncrypt and Crypt.Encrypt.StrDecrypt functions, see link to Deo's scripts or look at the code in Deo's functions).
RECOMMENDED USAGE:
Change password field below and comment out #NoTrayIcon if you want to see a tray icon for the script, then compile it (unicode 32- or 64-bit). You need AutoHotkey (unicode version) and Deo's CryptFoos.ahk, Crypt.ahk, CryptConst.ahk scripts in the same directory. You can compile the script from context menu if AutoHotkey is installed or use Ahk2Exe.exe (comes with AutoHotkey). Send the compiled exe to contacts you wish to communicate with using encryption (make sure to hand it to them in person or send it to them in a password protected file). If you plan to use this script regularly, then add a shortcut to it to Windows' Startup folder. Make sure anti-virus programs do not block Cryptor.exe.
LICENSE:
You are welcome to use my part of the work below with or without attribution, but the heavy lifting is done by Deo's scripts which are included at the bottom, but Deo has not specified a license for them.
CREDITS and REQUIREMENTS:
Requires the following scripts from Deo: CryptFoos.ahk, Crypt.ahk, CryptConst.ahk
Link to Deo's scripts (checked 22-Jun-2013): http://www.autohotkey.com/board/topic/67155-ahk-l-crypt-ahk-cryptography-class-encryption-hashing/
Borrows code from Learning one's (Boris Mudrinic's) CryptWinClass.ahk script. Larger blocks of borrowed code are specifically indicated by comments although I increased ClipWait times to improve reliability.
Link to CryptWinClass.ahk (checked 22-Jun-2013): http://www.autohotkey.com/board/topic/92576-object-cryptwin/
****************************************************************
*/
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance, force
#NoTrayIcon ; comment out this line with ; if you want to see tray icon for the script
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;Menu,Tray,Icon,Cryptor.ico ; Requires Cryptor.ico file in script folder.
;CHANGE PASSWORD BELOW TO SOMETHING LONG AND COMPLICATED (no quatation marks or semicolons, and avoid rare symbols too)
password := "password"
return
+Esc:: ; hotkey info and exit cryptor
; list hotkeys below
hotkeysInfo := "Shift+F1: Encrypt selected text`r`nShift+F2: Decrypt selected text`r`nShift+F3: Copy all text in active window and open bottom (short press), or`r`n top (long press) encrypted message`r`nShift+Esc: Show hotkeys and/or exit Cryptor.`r`n`r`nPress YES to close Cryptor.exe running in the background. NO to continue."
MsgBox,4,Exit Cryptor?,%hotkeysInfo%
IfMsgBox,Yes
ExitApp
return
;quick press Shift+F1 to encrypt selected text, long press Shift+F1 (over 0.3s) to auto-select message (one line) by sending Shift+Home to target window i.e. selects a line you've just typed (generally only works for single lines). In most windows if you've selected text already, and then long press by accident, it doesn't undo the selection.
+F1::
KeyWait,F1,T0.3
If ErrorLevel
{
KeyWait,Shift ; wait for user to (also) release Shift
Send +{Home}
Sleep, 100
}
; code from Learning one's CryptWinClass.ahk
;=== GetSelected text ===
IsClipEmpty := (Clipboard = "") ? 1 : 0
if (IsClipEmpty != 1) { ; not empty
ClipboardBackup := ClipboardAll ; backup
While (Clipboard != "") { ; empty Clipboard - looks funny but usually is more reliable...
Clipboard := ""
Sleep, 20
}
}
Send, ^c
ClipWait, 1 ; waits specifically for text or files to appear for 0.2 seconds
Text := Clipboard ; Text is SelectedText
this.PutToClipBoard(ClipboardBackup) ; restore Clipboard
if Text is space
return
;end of code from Learning one
hash := Crypt.Encrypt.StrEncrypt(Text,password,7,6) ; encrypts string using AES_256 encryption and SHA_512 hash
hashText := "[begin_encrypt]" . hash . "[end_encrypt]" ; encrypted text with beginning and end marked
Clipboard := hashText
Text := hash := hashText := ""
Sleep, 200 ; improves reliability
Send, ^v ; paste
return
+F2::
; code from Learning one's CryptWinClass.ahk
;=== GetSelected text ===
IsClipEmpty := (Clipboard = "") ? 1 : 0
if (IsClipEmpty != 1) { ; not empty
ClipboardBackup := ClipboardAll ; backup
While (Clipboard != "") { ; empty Clipboard - looks funny but usually is more reliable...
Clipboard := ""
Sleep, 20
}
}
Send, ^c
ClipWait, 1 ; waits specifically for text or files to appear for 1 second
Text := Clipboard ; Text is SelectedText
this.PutToClipBoard(ClipboardBackup) ; restore Clipboard
if Text is space
return
;end of code from Learning one
RegExMatch(Text,"msU).*\[begin_encrypt](.*)\[end_encrypt].*$",hash)
Text =
decrypted_string := Crypt.Encrypt.StrDecrypt(hash1,password,7,6) ; decrypts the string using previously generated hash, AES_256 encryption and SHA_512 hash
MsgBox,0,Decrypted message,%decrypted_string%
hash := hash1 := decrypted_string := ""
return
; I'm having reliability issues with this hotkey, YMMV. it's a work in progess.
+F3::
KeyWait,F3,T0.3 ; wait for user to release F3
longPress := ErrorLevel ? 1 : 0 ;record whether user pressed F3 for over 0.3 seconds (long press)
KeyWait, Shift ; wait for user to release Sfift key also
Send ^a
Sleep, 300
; code from Learning one's CryptWinClass.ahk
;=== GetSelected text ===
IsClipEmpty := (Clipboard = "") ? 1 : 0
if (IsClipEmpty != 1) { ; not empty
ClipboardBackup := ClipboardAll ; backup
While (Clipboard != "") { ; empty Clipboard - looks funny but usually is more reliable...
Clipboard := ""
Sleep, 20
}
}
Send, ^c
ClipWait, 1 ; waits specifically for text or files to appear for 1 seconds
Text := Clipboard ; Text is SelectedText
this.PutToClipBoard(ClipboardBackup) ; restore Clipboard
if Text is space
return
;end of code from Learning one
if longPress
RegExMatch(Text,"msU).*\[begin_encrypt](.*)\[end_encrypt].*$",hash)
else RegExMatch(Text,"ms).*\[begin_encrypt](.*)\[end_encrypt].*$",hash)
decrypted_string := Crypt.Encrypt.StrDecrypt(hash1,password,7,6) ; decrypts the string using previously generated hash, AES_256 encryption and SHA_512 hash
MsgBox,0,Decrypted message,%decrypted_string%
Text := hash := hash1 := decrypted_string := ""
return
;code from Learning One's CryptWinClass.ahk
PutToClipBoard(ToPut) { ; probably a little bit more reliable than just "Clipboard := ToPut" or not...?
if (ToPut = "")
Clipboard := ""
else {
; Clipboard := "" ; first empty, than put? More reliable or not?
Clipboard := ToPut
ClipWait, 1, 1 ; waits for data of any kind to appear on the clipboard for 1 second
}
}
;end of code from Learning One
#Include CryptFoos.ahk ; by Deo
#Include Crypt.ahk ; by Deo
#Include CryptConst.ahk ; by Deo