Jump to content
Sign in to follow this  
eynstyne

Encrypting stuff using 231 ascii characters

Recommended Posts

eynstyne

Hello all...

I'm working on an encryption system. It sometimes works, and it sometimes doesn't. Why?

The problem is, it drops letters in really large text.

It uses a 231 array to carry out ascii characters. A typical example is:

Key - Apple

Message - Wee

Encrypted...It looks like : 靦牺簽觙錴H

When decrypting...Any key you enter can semi-decrypt it.

Here is the code for Encryption and Decryption. How can I optimise this for maximum protection? What do I need to fix?

CODE
#include <array.au3>

#include <file.au3>

#include <string.au3>

#include <GUIConstants.au3>

$Form1 = GUICreate("Status...", 225, 59, 266, 259, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE,$WS_EX_TOPMOST))

$Label1 = GUICtrlCreateLabel("Creating Character Set...", 3, 3, 225, 17)

$Progress1 = GUICtrlCreateProgress(2, 22, 222, 14)

GUICtrlSetData(-1, 25)

$Button1 = GUICtrlCreateButton("Cancel", 86, 39, 57, 18, 0)

GUISetState(@SW_SHOW)

while 1

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

$KEYWORDSET = _ArrayCreate("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u")

$CHAR = _ArrayCreate("v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P")

$CHAR2 = _ArrayCreate("Q","R","S","T","U","V","W","X","Y","Z","1","2","3","4","5","6","7","8","9","0","`")

$CHAR3 = _ArrayCreate("~","!","@","#","$","%","^","&","*","(",")","_","+","-","=","[","]","{","}","|","\")

$CHAR4 = _ArrayCreate(":",";","""","'",",",".","<",">","?","/","","","?,"?,"?,"?,"?,"?,"?,"?,"?)

$CHAR5 = _ArrayCreate("?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?)

$CHAR6 = _ArrayCreate("?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?)

$CHAR7 = _ArrayCreate("?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?)

$CHAR8 = _ArrayCreate("?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?)

$CHAR9 = _ArrayCreate("?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?)

$CHAR10 = _ArrayCreate("?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"","","","","","","",""," ")

guictrlsetdata($Label1,"Assembling Character Set...")

for $j = 0 to 20

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

guictrlsetdata($Label1,"Assembling Character Set..." & $j & " Characters")

_ArrayAdd($KEYWORDSET,$CHAR[$j])

next

guictrlsetdata($Progress1,10)

for $k = 0 to 20

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

guictrlsetdata($Label1,"Assembling Character Set..." & $k + $j & " Characters")

_ArrayAdd($KEYWORDSET,$CHAR2[$k])

next

guictrlsetdata($Progress1,20)

for $i = 0 to 20

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

guictrlsetdata($Label1,"Assembling Character Set..." & $j + $k + $i & " Characters")

_ArrayAdd($KEYWORDSET,$CHAR3[$i])

Next

guictrlsetdata($Progress1,30)

for $m = 0 to 20

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

guictrlsetdata($Label1,"Assembling Character Set..." & $j + $k + $i + $m & " Characters")

_ArrayAdd($KEYWORDSET,$CHAR4[$m])

Next

guictrlsetdata($Progress1,40)

for $n = 0 to 20

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

guictrlsetdata($Label1,"Assembling Character Set..." & $j + $k + $i + $m + $n & " Characters")

_ArrayAdd($KEYWORDSET,$CHAR5[$n])

Next

guictrlsetdata($Progress1,50)

for $l = 0 to 20

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

guictrlsetdata($Label1,"Assembling Character Set..." & $j + $k + $i + $m + $n + $l & " Characters")

_ArrayAdd($KEYWORDSET,$CHAR6[$l])

Next

guictrlsetdata($Progress1,60)

for $p = 0 to 20

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

guictrlsetdata($Label1,"Assembling Character Set..." & $j + $k + $i + $m + $n + $l + $p & " Characters")

_ArrayAdd($KEYWORDSET,$CHAR7[$p])

Next

guictrlsetdata($Progress1,70)

for $o = 0 to 20

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

guictrlsetdata($Label1,"Assembling Character Set..." & $j + $k + $i + $m + $n + $l + $p + $o & " Characters")

_ArrayAdd($KEYWORDSET,$CHAR8[$o])

Next

guictrlsetdata($Progress1,80)

for $q = 0 to 20

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

guictrlsetdata($Label1,"Assembling Character Set..." & $j + $k + $i + $m + $n + $l + $p + $o + $q & " Characters")

_ArrayAdd($KEYWORDSET,$CHAR9[$q])

Next

guictrlsetdata($Progress1,90)

for $t = 0 to 19

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

guictrlsetdata($Label1,"Assembling Character Set..." & $j + $k + $i + $m + $n + $l + $p + $o + $q + $t & " Characters")

_ArrayAdd($KEYWORDSET,$CHAR10[$t])

next

guictrlsetdata($Progress1,100)

GUISetState(@SW_HIDE)

$KEY = Inputbox("Enter a key...","Enter a key to encrypt message. A lengthy and random key is best:","","*",200,150,-1,-1)

if $key = "" Then

msgbox(16,"Error...","You did not enter a key!")

Exit

EndIf

$MESSAGE = Inputbox("Enter your message","Your message. Do not include spaces.","","",200,150,-1,-1)

if $message = "" Then

msgbox(16,"Error...","You did not type a message")

Exit

EndIf

_FileCreate("E:\ENCRYPT.txt")

;Generates the Alphabet text and mixes it around

GUISetState(@SW_SHOW)

TraySetToolTip("Sorting Alphabet set...")

controlhide("Status...","",$progress1)

guictrlsetdata($Label1,"Sorting Character Set...")

For $i = 0 to 231

$msg = Guigetmsg()

if $msg = $button1 Then

guictrlsetdata($Label1,"Cancelling...")

Exit

EndIf

$MID = StringMid($KEY,$i,1)

if $MID <> "" Then

$Search = _ArraySearch($KEYWORDSET,$MID,0,0,1)

_ArraySwap($KEYWORDSET[$search],$KEYWORDSET[$i])

_ArraySort($KEYWORDSET)

endif

Next

guictrlsetdata($Label1,"Encrypting Message...")

for $i = 1 to Stringlen($MESSAGE)

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

$MID = StringMid($MESSAGE,$i,1)

$Search = _ArraySearch($KEYWORDSET,$MID,0,0,1)

$s = mod($search + $i,231)

if $search > -1 then

if $s > 0 Then

FileWrite("E:\ENCRYPT.TXT",$KEYWORDSET[$s])

ElseIf $s > 231 Then

$s = 231 - $search + $i

FileWrite("E:\ENCRYPT.TXT",$KEYWORDSET[$s])

EndIf

EndIf

TraySetToolTip("Encrypting...")

Next

exitloop

WEnd

DECRYPTION...

CODE

#include <array.au3>

#include <file.au3>

#include <string.au3>

#include <GUIConstants.au3>

$Form1 = GUICreate("Status...", 225, 59, 266, 259, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE,$WS_EX_TOPMOST))

$Label1 = GUICtrlCreateLabel("Creating Character Set...", 3, 3, 225, 17)

$Progress1 = GUICtrlCreateProgress(2, 22, 222, 14)

GUICtrlSetData(-1, 25)

$Button1 = GUICtrlCreateButton("Cancel", 86, 39, 57, 18, 0)

GUISetState(@SW_SHOW)

while 1

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

$KEYWORDSET = _ArrayCreate("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u")

$CHAR = _ArrayCreate("v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P")

$CHAR2 = _ArrayCreate("Q","R","S","T","U","V","W","X","Y","Z","1","2","3","4","5","6","7","8","9","0","`")

$CHAR3 = _ArrayCreate("~","!","@","#","$","%","^","&","*","(",")","_","+","-","=","[","]","{","}","|","\")

$CHAR4 = _ArrayCreate(":",";","""","'",",",".","<",">","?","/","","","?,"?,"?,"?,"?,"?,"?,"?,"?)

$CHAR5 = _ArrayCreate("?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?)

$CHAR6 = _ArrayCreate("?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?)

$CHAR7 = _ArrayCreate("?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?)

$CHAR8 = _ArrayCreate("?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?)

$CHAR9 = _ArrayCreate("?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?)

$CHAR10 = _ArrayCreate("?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"?,"","","","","","","",""," ")

guictrlsetdata($Label1,"Assembling Character Set...")

for $j = 0 to 20

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

guictrlsetdata($Label1,"Assembling Character Set..." & $j & " Characters")

_ArrayAdd($KEYWORDSET,$CHAR[$j])

next

guictrlsetdata($Progress1,10)

for $k = 0 to 20

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

guictrlsetdata($Label1,"Assembling Character Set..." & $k + $j & " Characters")

_ArrayAdd($KEYWORDSET,$CHAR2[$k])

next

guictrlsetdata($Progress1,20)

for $i = 0 to 20

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

guictrlsetdata($Label1,"Assembling Character Set..." & $j + $k + $i & " Characters")

_ArrayAdd($KEYWORDSET,$CHAR3[$i])

Next

guictrlsetdata($Progress1,30)

for $m = 0 to 20

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

guictrlsetdata($Label1,"Assembling Character Set..." & $j + $k + $i + $m & " Characters")

_ArrayAdd($KEYWORDSET,$CHAR4[$m])

Next

guictrlsetdata($Progress1,40)

for $n = 0 to 20

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

guictrlsetdata($Label1,"Assembling Character Set..." & $j + $k + $i + $m + $n & " Characters")

_ArrayAdd($KEYWORDSET,$CHAR5[$n])

Next

guictrlsetdata($Progress1,50)

for $l = 0 to 20

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

guictrlsetdata($Label1,"Assembling Character Set..." & $j + $k + $i + $m + $n + $l & " Characters")

_ArrayAdd($KEYWORDSET,$CHAR6[$l])

Next

guictrlsetdata($Progress1,60)

for $p = 0 to 20

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

guictrlsetdata($Label1,"Assembling Character Set..." & $j + $k + $i + $m + $n + $l + $p & " Characters")

_ArrayAdd($KEYWORDSET,$CHAR7[$p])

Next

guictrlsetdata($Progress1,70)

for $o = 0 to 20

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

guictrlsetdata($Label1,"Assembling Character Set..." & $j + $k + $i + $m + $n + $l + $p + $o & " Characters")

_ArrayAdd($KEYWORDSET,$CHAR8[$o])

Next

guictrlsetdata($Progress1,80)

for $q = 0 to 20

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

guictrlsetdata($Label1,"Assembling Character Set..." & $j + $k + $i + $m + $n + $l + $p + $o + $q & " Characters")

_ArrayAdd($KEYWORDSET,$CHAR9[$q])

Next

guictrlsetdata($Progress1,90)

for $t = 0 to 19

$msg = Guigetmsg()

if $msg = $button1 Then

Exit

EndIf

guictrlsetdata($Label1,"Assembling Character Set..." & $j + $k + $i + $m + $n + $l + $p + $o + $q + $t & " Characters")

_ArrayAdd($KEYWORDSET,$CHAR10[$t])

next

guictrlsetdata($Progress1,100)

GUISetState(@SW_HIDE)

$KEY = InputBox("Enter Key","Enter your keyword to decrypt the message:","","*",200,150,-1,-1)

$open = FileOpenDialog("Open file with encrypted message...","","All Files (*.*)",1+2+4)

$MESSAGE = Filereadline($open,1)

if $KEY = "" then

msgbox(16,"Error","You did not type a key!")

exit

EndIf

if $open = "" Then

msgbox(48,"Error","The file chosen is blank or does not contain any text on line 1")

Exit

EndIf

_FileCreate("E:\DECRYPT.txt")

;Generates the Key Alphabet text and mixes it around

GUISetState(@SW_SHOW)

TraySetToolTip("Sorting Alphabet set...")

controlhide("Status...","",$progress1)

guictrlsetdata($Label1,"Sorting Character Set...")

For $i = 0 to 231

$msg = Guigetmsg()

if $msg = $button1 Then

guictrlsetdata($Label1,"Cancelling...")

Exit

EndIf

$MID = StringMid($KEY,$i,1)

if $MID <> "" Then

$Search = _ArraySearch($KEYWORDSET,$MID,0,0,1)

_ArraySwap($KEYWORDSET[$i],$KEYWORDSET[$search])

_ArraySort($KEYWORDSET)

endif

Next

;Matches Encryption Alphabet

guictrlsetdata($Label1,"Decrypting Message...")

for $i = 1 to Stringlen($MESSAGE)

$MID = StringMid($MESSAGE,$i,1)

$Search = _ArraySearch($KEYWORDSET,$MID,0,0,1)

if $i > $search Then

msgbox(0,"",$search)

$SEARCHy = _ArraySearch($KEYWORDSET,"y",0,0,1)

msgbox(0,"y",$SEARCHy)

FileWrite("E:\DECRYPT.TXT",$KEYWORDSET[$s])

Else

$s = mod($search - $i,231)

EndIf

if $search <> @error Then

FileWrite("E:\DECRYPT.TXT",$KEYWORDSET[$s])

ElseIf $s > 231 Then

FileWrite("E:\DECRYPT.TXT",$KEYWORDSET[231 - $s])

Elseif $i > $search Then

msgbox(0,"",$search)

msgbox(0,"",$s)

$s = $search + $i

FileWrite("E:\DECRYPT.TXT",$KEYWORDSET[$s])

EndIf

TraySetToolTip("Decrypting...")

Next

ExitLoop

wend

Edited by eynstyne

F@m!ly Guy Fr33k! - Avatar speaks for itself__________________________________________________________________________________________ite quotes... - Is your refrigerator running? If it is, It probably runs like you...very homosexually - Christians don't believe in gravity - Geeze Brian where do you think you are, Payless?- Show me potato Salad!__________________________________________________________________________________________Programs available - Shutdown timer[indent][/indent]

Share this post


Link to post
Share on other sites
lod3n

No offence, but what's wrong with the included _StringEncrypt function?

Regardless, I wouldn't use character sets outside of A-Z, 0-9 for encryption. If you REALLY want to do something fancy like that, why not use a 5 character string ranging from "[000]" through "[231]"? Or something like that...


[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
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
Sign in to follow this  

×