AES is pretty slow, when I need to encrypt or decrypt strings I use a combination of several weak methods, but if they are combined they are very difficult to crack. for example this is how I do an encrypt:
1 determine the stringLength.
2 apply a mask ( the mask is provided to the encrypt algo as a parameter, the longer the mask the better because if the string is longer than the mask the mask will be repeated over and over )
char = char[i] + mask[i]
3 apply positional ROTK ( the rotation direction switches for even and uneven positions, the initial offset is stringLength and increases by 1 for every next char )
4 apply random ROTK ( the random character is inserted at a fixed position and will later be used for decryption, the effect is that no string is the same, you could for example encode the string "hello" which will produce for example "Xjuksy" the first time but the next time you encode it it will give a different string for example "ytglMp" yet both decode to the same string "hello", there are as many encoded variations for the word "hello" as there are valid random chars, If I remember well I use around 60 printable chars that means somewhere around 60 possible variations for every word ).
something like this:
Code: Select all
:: get $array[]
:: (
%forQ_% (
!$inputArray!
) do set /A $array[0] = !%%~?[0]! &%forI_% (
1, 1, !$array[0]!
) do set "$array[%%i]=!%%~?[%%i]!"
:: )
:: put mask on $array[]
:: (
%forI_% (
1, 1, !$array[0]!
) do (
rem get stingLength
rem (
( %stringLen_% $len, $array[%%i] )
rem )
rem apply mask
rem (
( %mask_% $array[%%i], $mask, "+", "4" )
rem )
rem apply positional rotK
rem (
set /A $arrayLen = $len - 1
set "$oldString=!$array[%%i]!" &set "$newString=!$oldString:~,1!" &%forI_% (
1, 1, !$arrayLen!
) do (
set "$char=!$oldString:~%%i,1!"
set /A $pos = %%i + $arrayLen
( %isEven_% "%%i" ) &&(
( %rotK_% $char, $char, "+!$pos!", "4" )
) || ( %rotK_% $char, $char, "-!$pos!", "4" )
set "$newString=!$newString!!$char!"
)
set "$array[%%i]=!$newString!"
rem )
rem apply random rotK
rem (
call :§parser_ randomFileNameableDec $randomDec ^!
set /A $n = $len + $randomDec
( %rotK_% $array[%%i], $array[%%i], "+!$n!", "4" )
rem )
rem insert random char
rem (
( %decToChar_% $randomChar, $randomDec )
set "$array[%%i]=!$randomChar!!$array[%%i]!"
rem )
)
:: )
When a user wants to decrypt the string he will have to know which mask was used. If many strings are encrypted the chances of the algo being cracked increases due to the way pattern search algos compare strings, but it will be difficult because a random char is inserted in the string but is not part of the string itself, it only tells the decrypter how to undo the random ROTK.
Let's do the decryption:
Code: Select all
:: get $array[]
:: (
%forQ_% (
!$inputArray!
) do set /A $array[0] = !%%~?[0]! &%forI_% (
1, 1, !$array[0]!
) do set "$array[%%i]=!%%~?[%%i]!"
:: )
:: put mask on $array[]
:: (
%forI_% (
1, 1, !$array[0]!
) do (
rem remove random char
rem (
set "$firstChar=!$array[%%i]:~0,1!"
set "$array[%%i]=!$array[%%i]:~1!"
rem )
rem get stingLength
rem (
( %stringLen_% $len, $array[%%i] )
rem )
rem remove random rotK
rem (
( %CharToDec_% $firstDec, $firstChar )
set /A $n = $len + $firstDec
( %rotK_% $array[%%i], $array[%%i], "-!$n!", "4" )
rem )
rem remove positional rotK
rem (
set /A $arrayLen = $len - 1
set "$oldString=!$array[%%i]!" &set "$newString=!$oldString:~,1!" &%forI_% (
1, 1, !$arrayLen!
) do (
set "$char=!$oldString:~%%i,1!"
set /A $pos = %%i + $arrayLen
( %isEven_% "%%i" ) &&(
( %rotK_% $char, $char, "-!$pos!", "4" )
) || ( %rotK_% $char, $char, "+!$pos!", "4" )
set "$newString=!$newString!!$char!"
)
set "$array[%%i]=!$newString!"
rem )
rem remove mask
rem (
( %mask_% $array[%%i], $mask, "-", "4" )
rem )
)
:: )
I did this to find something relatively fast, then I thought about porting the code to vbScript so I would be able to speed up things. Later I discovered AutoIT has a built in function for encryption.
Just don't encrypt hundreds of strings with the same mask, every time you apply the same mask the pattern compare algorithm has another hint to work on and the random ROTK only has a finite number of valid chars ( one could always increase this by using more random chars if one uses two random chars the number of encoded variation goes up to 60 * 60 = 3600 and so on, a good rule of thumb is to make sure the number of encoded variations is equal or higher than the number of repetitive words ).