Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[object] CryptWin


  • Please log in to reply
9 replies to this topic
Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009

WARNING: This is old thread. It is continued here.

[object] CryptWin
CryptWin%20preview.png
- is based on idea to put sensitive text data in a few .txt files, and see/edit them quickly and easily via CryptWin
- depends on Crypt.ahk, CryptConst.ahk, CryptFoos.ahk by Deo, so you have to #Include them or put them in your Standard or User Library
- uses AES_256 crypt algorytm and SHA hash algorytm by default (can be changed)
- is portable
- is encapsulated
- allows you to set/get properties, call methods and monitor CryptWin's events
- can be used as stand-alone script or made part of another larger script without collision
- allows you to make your custom encryption tricks via BeforeDecrypt and AfterEncrypt events
- is not totally finished but most important functionalities are fully developed and working fine
- has reserved prefix: "CryptWin", uses "SafeFileOverwrite" functionality
- supports drag and drop, has resizable window
- can encrypt or decrypt selected text in any text editor
- besides encrypted plain text files, CryptWin can open encrypted MS Word documents and encrypted MS Excel workbooks
 
Watch tutorial video
 
Download - includes [CryptWinClass] and [documentation, examples, license, credits, etc. in comments]
 
Example script 1 - simplest usage



CryptWin()          ; initialise
CryptWin.GuiShow()  ; show
return

#Include CryptWinClass.ahk  ; by Learning one
#Include CryptFoos.ahk      ; by Deo
#Include Crypt.ahk          ; by Deo
#Include CryptConst.ahk     ; by Deo

Example script 2 - intermediate



CryptWin()                    ; initialises CryptWin
CryptWin.GuiSetSize(700, 350) ; sets the size of CryptWin window and centers it on the screen
CryptWin.Password := "123456" ; sets password
CryptWin.View := "Encrypted"  ; goes to Encrypted view mode
CryptWin.Text := "E4278C66A8AB35963EA6C1458E8E0E0D25178AC7869B9FB378DF1199ACCFB96A"	; sets text (note that we switched to encrypted view mode one line above)
CryptWin.View := "Decrypted"  ; goes to Decrypted view mode - decrypts text above
CryptWin.FontSize := 22       ; sets font size to 22
CryptWin.GuiShow()            ; shows window
MsgBox, % CryptWin.Password   ; gets Password and shows it in MsgBox
return

F1::CryptWin.Selection("Encrypt") ; encrypts selected text in any text editor
F2::CryptWin.Selection("Decrypt") ; decrypts selected text in any text editor

#Include CryptWinClass.ahk  ; by Learning one
#Include CryptFoos.ahk      ; by Deo
#Include Crypt.ahk          ; by Deo
#Include CryptConst.ahk     ; by Deo

Example script 3 - when you want to use just selection encrypt/decrypt functionality without showing CryptWin window



CryptWin()                        ; initialise
CryptWin.Password := "123456"     ; set password
return

F1::CryptWin.Selection("Encrypt") ; encrypts selected text in any text editor
F2::CryptWin.Selection("Decrypt") ; decrypts selected text in any text editor
F3::CryptWin.PasswordDialog() ; displays mini enter password dialog without showing main CryptWin window - if you want to change password
Esc::ExitApp

#Include CryptWinClass.ahk  ; by Learning one
#Include CryptFoos.ahk      ; by Deo
#Include Crypt.ahk          ; by Deo
#Include CryptConst.ahk     ; by Deo

My Website • Recommended: AutoHotkey Unicode 32-bit • Join DropBox, Copy


Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009
CryptWin updated to v1.01
Fixed - decrypted radio button was not pre-selected when CryptWin was initialised
Added - new examples
Added - PasswordDialog() method which displays mini enter password dialog without showing main CryptWin window
Improved - CryptWin.Selection() automatically calls PasswordDialog() if password is not specified
Improved - CryptWin.Selection() preserves whitespaces better
Improved - faster text coloring when setting large strings to text field
Changed - DropDownList is now a little bit larger for more ergonomical selecting

My Website • Recommended: AutoHotkey Unicode 32-bit • Join DropBox, Copy


Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009

CryptWin updated to v1.02
- added WantTab in text field
- added "Do you want to save changes?" dialog if you made changes and haven't saved them
- added AskToSaveChanges property (default=1)

 

CryptWin updated to v1.03
- added Clear() method


My Website • Recommended: AutoHotkey Unicode 32-bit • Join DropBox, Copy


SnowFlake_FlowSnake
  • Members
  • 845 posts
  • Last active: Jan 24 2016 05:24 PM
  • Joined: 08 Oct 2012

can you add all this

 

 #Include CryptWinClass.ahk ; by Learning one

#Include CryptFoos.ahk ; by Deo
#Include Crypt.ahk ; by Deo
#Include CryptConst.ahk

 

in  one ahk file?


  • Download link of my scripts on Autohotkey.com 2/10/2015 [DOWNLAND]
  • Contact Info:  https://github.com/floowsnaake //  FloowSnaake(A)gmail.com
  • IF you need Help send me a PM,Email or Post on Github

  • Quote by tank  Posted 29 September 2015 - 06:14 PM

  • "Eventually i will find a way to convert the DB back to PHPBB3. but i dont have the bandwidth right now. No one that has tried has had success. It is the Only way i can keep this open is if i could successfully convert it."

Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009

I can't. I estimated that Deo's work has such qualities that it is capable to be protected by copyright (his, of course). Deo didn't specify license for his work, and in most jurisdictions that means maximum protection by default. So, in most jurisdictions, no license (for work which is under somebody's copyright) is equal to most restrictive license by default.

In such situation, nobody is allowed to distribute his work. Therefore, I'm not allowed to put all his work in one  #Include file or in a .zip archive and distribute it with my work - CryptWin. Actualy, nobody is allowed to even use his work! The fact he released his work on AHK forum is not relevant - maximum protection remains.

All those restrictive legal consiquences probably aren't what Deo wants, but in this situation, the law regulates the situation because author (Deo) did not.

But all of above are just presumptions. To be 100% sure about legal situation in this case, we need to know where's Deo from, because that law applies.
 
P.S. I understand that all of this is little bit funny, boring, not practical, and said...
 


My Website • Recommended: AutoHotkey Unicode 32-bit • Join DropBox, Copy


pajenn
  • Members
  • 391 posts
  • Last active: Feb 06 2015 07:57 AM
  • Joined: 07 Feb 2009

This is an amazing script and very much needed. Thank you.

I'd like to modify it a little bit so that a hotkey, like F2 for example, would automatically select the encrypted text under the mouse, and then display the decrypted version of it in a text box. The idea being that I could quickly and conveniently decrypt emails and skype messages (when pasting is not allowed).

I tried doing this by replacing line "Send, ^v" with "MsgBox % Clipboard" (around line 1021 in CryptWinClass.ahk), which worked okay until I compiled the script. Of course a proper (scrollable) GUI would be better than the default message box, and I haven't tried implementing the auto-selection of encrypted text yet, but I wanted to know if you had ideas about this?



General privacy problem: Something like this is needed for skype, outlook, webmail and other popular messaging/email applications that don't have good support for PGP or other encryption (and hand everything over to the NSA anyway). I use Mozilla Thunderbird myself with Enigmail plugin for email (OpenPGP encryption) and Jitsi for encrypted IMs and VoIP, but the problem is that many of my contacts stick to skype and outlook. I've looked for applications that could implement something similar to what your script does and what I want to make it do, but the alternatives I've found generally require you to write or paste a message into a window and then press a button to encrypt or decrypt it (similar to your Example script 1, although yours is excellent). Then if encrypting, you need to copy and paste the result into an email or chat application. This is just too many steps and too inconvenient for frequent daily use.


Hardware: fast laptop with SSD
Software: Win 7 Home Premium 64-bit, android for phone and tablet


pajenn
  • Members
  • 391 posts
  • Last active: Feb 06 2015 07:57 AM
  • Joined: 07 Feb 2009

This is probably something really basic, but I'm having trouble with this script when I compile it. I'm using the following slightly modified version of example script 3:

#SingleInstance, force
;#NoTrayIcon
CryptWin()                        ; initialise
CryptWin.Password := "password"     ; set password
return
+F1::CryptWin.Selection("Encrypt") ; encrypts selected text in any text editor
+F2::MsgBox % CryptWin.Selection("Decrypt",0) ; decrypts selected text to msgbox
+Esc::ExitApp

#Include CryptWinClass.ahk  ; by Learning one
#Include CryptFoos.ahk      ; by Deo
#Include Crypt.ahk          ; by Deo
#Include CryptConst.ahk     ; by Deo

it works fine in script form, but after I compile it, the msgbox of decrypted text shows up empty. encrypting still works in compiled form. I'd like a compiled version so that it would be easy for others to use who are not familiar with ahk nor have it installed (plus the password would be hidden inside the exe).

edit: in fact, even the original example script 3 doesn't work for me if I compile it, or the decrypt function doesn't work. (I'm using 64-bit unicode version of AHK).

edit2: okay, the script compiles fine now, I just had to use the 32-bit unicode version -- I'm a little behind on my autohotkey since I used it mostly before it separated into many different versions and then I wasn't really able to keep up anymore and stopped following the forum closely and stopped writing new scripts for myself except when I really needed something... but I think I can write something that does what I want based on Deo's and Learning One's work.


Hardware: fast laptop with SSD
Software: Win 7 Home Premium 64-bit, android for phone and tablet


pajenn
  • Members
  • 391 posts
  • Last active: Feb 06 2015 07:57 AM
  • Joined: 07 Feb 2009

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

Hardware: fast laptop with SSD
Software: Win 7 Home Premium 64-bit, android for phone and tablet


Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009

Hi pajenn, sorry for late reply - I was offline for a while... Nice work cool.png .

In the meanwhile I made some improvements;


CryptWin updated to 1.04
- now it can open encrypted MS Word documents and encrypted MS Excel workbooks
- added ClearClipboardOnGuiClose property (turned on by default)


My Website • Recommended: AutoHotkey Unicode 32-bit • Join DropBox, Copy


Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009

CryptWin updated to 1.05

- fixed problem when user is saving a .txt file with a new password


My Website • Recommended: AutoHotkey Unicode 32-bit • Join DropBox, Copy