Jump to content

One-way XOR En/Decryption ( GUI )


 Share

Recommended Posts

Just to start off, this isn't a project or collaboration of any kind, I was unable to start a topic in the 'Example Scripts' section.

This is just a small utility program I made for something I needed years ago, but only recently coded it in AutoIt. Basically it is a one way Encrypter / Decrypter for XOR.
Nothing much to it; enter a HEX string and hit the button, it will return a result using the key that you input into the box. Not sure if anyone has done it this way before, but it works great, and I got all the kinks worked out finally. Let me know what you all think, and if there are any improvements that can be made, whether it be with the GUI or the efficiency of my code. :)

Additionally, if possible, move this thread to the correct section.

fG4U4kr.jpg

 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\..\Desktop\ENDEC.ico
#AutoIt3Wrapper_Outfile=ENDEC.Exe
#AutoIt3Wrapper_Res_Description=One way XOR Encrypt / Decrypt
#AutoIt3Wrapper_Res_Fileversion=1.0.0.1
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Include <Array.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ColorConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$XOR_GUI = GUICreate("XOR En/Decrypt", 615, 290, 192, 124)
$CRYPT_BTN = GUICtrlCreateButton("En/Decrypt", 505, 32, 100, 25)
$CLIP_BTN = GUICtrlCreateButton("Copy", 505, 163, 100, 25)
$CLEAR_BTN = GUICtrlCreateButton("Clear", 505, 215, 100, 25)
$XOR_KEY = GUICtrlCreateInput("61", 535, 100, 50, 15, BitOR($ES_UPPERCASE, $ES_CENTER), 0)
$STR_INPUT = GUICtrlCreateEdit("", 24, 32, 469, 105, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_VSCROLL, $ES_UPPERCASE, $ES_MULTILINE), 0)
$STR_RESULT = GUICtrlCreateEdit("", 24, 163, 469, 105, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_VSCROLL, $ES_UPPERCASE, $ES_READONLY), 0)
GUICtrlSetColor($STR_RESULT, $COLOR_RED)
$XOR_KEY_LABEL = GUICtrlCreateLabel("En/Decrypt Key", 517, 80, 100, 17)
$STR_INPUT_LABEL = GUICtrlCreateLabel("String [ HEX ]  0", 24, 8, 200, 17)
$STR_RESULT_LABEL = GUICtrlCreateLabel("Result [ HEX ]  0", 24, 144, 200, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


Global $STR_DATA = ['']

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $CRYPT_BTN
            Convert()

        Case $CLIP_BTN
            ClipPut(GUICtrlRead($STR_RESULT))

        Case $CLEAR_BTN
            Clear()

    EndSwitch
WEnd

Func Convert()

    GUICtrlSetData($STR_INPUT_LABEL, 'String [ HEX ]  ' & StringLen(GUICtrlRead($STR_INPUT)))

    $STR_READ = '0x' & StringStripWS(GUICtrlRead($STR_INPUT), 8)

    Dim $STR_DATA = ['']

    For $i = 1 To StringLen($STR_READ) Step 2

        If StringLen(GUICtrlRead($STR_INPUT)) > 0 Then

            $STR_TRIM = '0x' & StringMid($STR_READ, $i, 2)

            $XOR_STR = BitXOR($STR_TRIM, '0x' & GUICtrlRead($XOR_KEY))

            _ArrayAdd($STR_DATA, StringMid(Hex($XOR_STR), 7, 2))

        Else

            ContinueLoop
            Dim $STR_DATA = ['']

        EndIf

    Next

    If StringLen(GUICtrlRead($STR_INPUT)) > 0 Then

        $STR_PARSE = _ArrayToString($STR_DATA, ' ', 2, UBound($STR_DATA) -1)
        GUICtrlSetData($STR_RESULT, $STR_PARSE)
        GUICtrlSetData($STR_RESULT_LABEL, 'Result [ HEX ]  ' & StringLen(GUICtrlRead($STR_RESULT)))

    Else

        MsgBox(48, 'ERROR', @error & ' There is no data to parse.')
        Clear()

    EndIf

EndFunc

Func Clear()

    GUICtrlSetData($STR_INPUT, '')
    GUICtrlSetData($STR_INPUT_LABEL, 'String [ HEX ]  0')
    GUICtrlSetData($STR_RESULT, '')
    GUICtrlSetData($STR_RESULT_LABEL, 'Result [ HEX ]  0')
    Dim $STR_DATA = ['']

EndFunc

TO-DO: 

  • Restrict the input box to only accept HEX and Numeric values.

 

Download:

ENCDEC.Src.au3

ENDEC.ico

Link to comment
Share on other sites

If your OTP (One Time Pad) is shorter than the plaintext (the unencrypted input) then it's terribly unsafe.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Yes, It is terribly unsafe and weak. I'm not too familiar with encryption though.

This was just a small application I was working on as a tool for something I used to do years ago. It was for packet analysis back around ... 2006 or so.

It's rather useless to me now, since I don't work with that anymore, but it was still fun to get it working. :)

Link to comment
Share on other sites

My remark was merely a warning to unsuspecting future readers of this post. Decrypting text XORed with a 1-byte key is sister kid level homework :D

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Ah. Understood  For most intents and purposes (in the traditional encryption sense), "one way" means one direction...meaning encrypt only.  Hashing algorithms for example (MD5, SHA, etc.) do one way encryption. to produce the hash value. The method used to generate the hash value should be very difficult to reverse.   

If you are interested in encryption I'd highly recommend looking at the _Crypt* functions in the help file.  Either way, keep on scriptin'

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...