Jump to content

Encrypt_It


susserj
 Share

Recommended Posts

Hi

I've created this script and thought it might be useful to others. Basically, it encrypts selected text with the hot key <ctr><alt>e and then one can un-encrypts the text using the hot key <ctrl><alt>v.

This script might be useful when sending an email to someone while needing a minimum level of privacy.The other person would need the executable, of course, and the compiled passwords would need to be the same.

I've tested it with Windows7 64 bit.

It works most of the time. It was a little flaky but I think it's OK now.

Just be sure that you are on a windows screen that allows editing before envoking the hot keys or you might get a nasty surprise.

Cheers

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.12.0
 Script Name:               Encrypt_IT
 Version:                1.3
 Author:                    Joel Susser

 Last Modifed:              06/04/2015
 Description:               This script Encrypts selected text.
                            This program is ideal for sending encrypted text through normal emails.


                            - To activate program run the Executable Encrypt_it.exe
                            - To Encrypt Text, Select the Text and type <ctr><alt><e>
                            - To Un-Encrypt Text, Select Text wrapped with <<encrypt_on>><encrypt_off> Tags and then type <ctr><Alt><u>
                            - To Exit application, close it in the system tray.

Update functionalty:        -Fixed a logic bug 
                            -Added error checking for empty selection or missing tags
                            -Added a function to just view encrypted text (It doeesn't replace the text)
                            -Added scrowlable msgbox using Form and Edit Field


Example Encrypted Message:
<encrypt_on>0xAC974253127B228E1E5C87259AE31C22FF44723C24CB817D89E2206D7AE75BAC0A5B<encrypt_off>


#ce ----------------------------------------------------------------------------

$hWnd = WinGetHandle("[ACTIVE]", "") ;get handle of current window
WinActivate ( $hWnd )               ;active current window by handle

#include <MsgBoxConstants.au3>
#include <Crypt.au3>
#include <String.au3>
#include <Clipboard.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>


const $sPassword = "password" ;should be changed.
Global $g_bPaused = False     ;probably not needed.
Global $sData = ""          ;initalize data storage variable to ""
Global $Encrypted = ""      ;initalize encrypted variable to ""

;setup hotkeys
HotKeySet("^!e", "Encrypt"); <ctrl><alt>e
HotKeySet("^!u", "UnEncrypt_replace"); <ctrl><alt>u
HotKeySet("^!v", "UnEncrypt_view"); <ctrl><alt>v
;HotKeySet("{ESC}", "Terminate") ; Press Esc to terminate script

;create main loop to check for hotkeys
While 1
    Sleep(100)
WEnd

Func Terminate()
    Exit
EndFunc   ;==>Terminate

Func Encrypt()
    $hWnd = WinGetHandle("[ACTIVE]", "") ;active handle of windows that selection was made on when hot key pressed
    WinActivate ( $hWnd )
    WinActive ($hWnd)
 send("^c")                         ;copy selected text to clipboard
 ;send("{CTRLDOWN}c{CTRLUP}")
 sleep(1000);wait for selection to complete
 ;consolewrite($sData & @CRLF)
 ;wait for selection to complete
 ;$sData = ClipGet()
 $sData =_ClipBoard_GetData ( $CF_TEXT ) ;convert clipboard data to pure text and move it to $sData variable
 If Check_Unencrypted_Data_Good($sData) Then
     ;MsgBox($MB_SYSTEMMODAL, "", $sData)
     $Encrypted = _Crypt_EncryptData($sData, $sPassword, $CALG_RC4) ; encrypt $sData data and move it to $Encrypted
     ;MsgBox($MB_SYSTEMMODAL, '', $Encrypted)
     $sData = "<encrypt_on>" & $Encrypted & "<encrypt_off>"
     ClipPut($sData)                ;put $encrypted data back into cliboaard
      WinActivate ( $hWnd )             ;active windows by handle
      WinActive ($hWnd)                 ;wait for window to be active
      send("^v")                        ;send clipboard data to screen via <ctr>v command
      sleep(1000)                       ;wait for clipboard push to completd
      ClipPut("");clear clipboard       ;clear the clipboard
 EndIf
EndFunc



Func UnEncrypt_replace()
$hWnd = WinGetHandle("[ACTIVE]", "") ;active handle of windows that selection was made on when hot key pressed
WinActivate ( $hWnd )   ;active window by handle
WinActive ($hWnd)
 send("^c") ;send clipboard data to screen
  ;send("{CTRLDOWN}c{CTRLUP}")
 sleep(1000)
 $sData = ClipGet()
  ;consolewrite($sData & @CRLF)
    if Check_if_Properly_Tagged($sData) then
        ;$sData =_ClipBoard_GetData ( $CF_TEXT ) ;convert clipboard data to pure text and put it in $sData variable
         $aArray=_StringBetween($sData,'<encrypt_on>','<encrypt_off>');remove tags
         $Encrypted = $aArray[0]
         ;MsgBox($MB_SYSTEMMODAL, "", $Encrypted)
         sleep(500)
         $sData = BinaryToString( _Crypt_DecryptData($Encrypted, $sPassword, $CALG_RC4)) ; de-crypt data
        ; MsgBox($MB_SYSTEMMODAL, "", $sData)
          ClipPut($sData) ;put data collected in clipboard
          send("^v") ;send clipboard to screen
          ; send("{CTRLDOWN}v{CTRLUP}")
          sleep(1000) ;wait for completion
          ClipPut("") ;clear clipboard
          ;MsgBox($MB_SYSTEMMODAL, "", "UnEncrypting")
    EndIf
EndFunc




Func UnEncrypt_view()
$hWnd = WinGetHandle("[ACTIVE]", "") ;active handle of windows that selection was made on when hot key pressed
WinActivate ( $hWnd )   ;active window by handle
WinActive ($hWnd)
 send("^c")             ;send clipboard data to screen
 ; send("{CTRLDOWN}c{CTRLUP}")
 sleep(1000)
 $sData = ClipGet()
  ;consolewrite($sData & @CRLF)
;$sData =_ClipBoard_GetData ( $CF_TEXT ) ;convert clipboard data to pure text and put it in $sData variable

    if Check_if_Properly_Tagged($sData) then
         $aArray=_StringBetween($sData,'<encrypt_on>','<encrypt_off>');remove tags
         $Encrypted = $aArray[0]
         ;MsgBox($MB_SYSTEMMODAL, "", $Encrypted)
         sleep(500)
         $sData = BinaryToString( _Crypt_DecryptData($Encrypted, $sPassword, $CALG_RC4)) ; de-crypt data

        ; MsgBox($MB_SYSTEMMODAL, "", $sData)
          MsgBox_Scroll("Un-Encrypt Text", $sData)
    endif
  ClipPut("") ;clear clipboard
  ;MsgBox($MB_SYSTEMMODAL, "", "UnEncrypting")
EndFunc


;custom scrollable message box
func MsgBox_scroll($title, $text)
    $Form1 = GUICreate($title, 623, 436, 192, 132)
    $Edit1 = GUICtrlCreateEdit("", 8, 0, 593, 433)
    GUICtrlSetData(-1, $text)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                ;Exit
                GUIDelete ( $Form1 )
                ExitLoop
        EndSwitch
    WEnd
EndFunc

;check if cliboard is blank. If yes, there is a problem.
func Check_Unencrypted_Data_Good($sData)
    if $sData = "" Then
        MsgBox($MB_SYSTEMMODAL,"Error", "No Text Selected for Encryption")
        return False
    Else
        Return True
    EndIf
EndFunc

;check if clipboard data has the closing and starting tags. If not, there is a problem.
func Check_if_Properly_Tagged($sData)
    if ( StringInStr($sData, "<encrypt_on>") And StringInStr($sData, "<encrypt_off>") ) Then
        return  True
    Else
        MsgBox($MB_SYSTEMMODAL,"Error", "Missing Encyption Tag")
        return false
    EndIf
EndFunc
Edited by susserj
Link to comment
Share on other sites

Hi

I've updated this script to view the unencrypted text using the hot keys <ctr><alt>v. (I may need to remove the function <ctr><alt>u functionality, because if the field the curser is on does not accept text inputting, the results might be unexpected).

If anyone knows how to check if the curser is in an editable field, without throwing an error message, please let me know.

I have added some error checking for empty text selections and missing tag selections.

Thanks

joel

Edited by susserj
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...