An encryption/decryption method, that appears secure when 2 unique keys are chosen and a unique order for the characters to be used. It is only meant for short strings to be encoded, as each character takes progressively longer to encrypt. I created this for communication with php on a server, so php version will follow shortly.
May be used as:
Code:
Prime_Crypt(EncDec, String, 1Key, 2Key, Chars)
EncDec must be the literal word Encrypt or Decrypt
String is the string you wish to enc/decrypt
1Key is a unique key you must specify (may be any length)
2Key is a unique key you must specify (may be any length)
Chars is an optional parameter, but if you want it to be secure then you should change it. It is a list of all the characters you plan on using. ie:
0123456789abcdefghijklmnopqrstuvwxyzABCDE$&*)...........
and so on, although the strength in the encryption is that this should be in a random order. I have made this to give you a random order if you want one:
Code:
StringCaseSense, On
Chars := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!£$^&*()_-+={[}]:;@'~#<>.| "
StringSplit, Chars, Chars
Loop
{
Random, Rand, 1, % StrLen(Chars)
NewString .= SubStr(Chars, Rand, 1)
StringReplace, Chars, Chars, % SubStr(Chars, Rand, 1),, All
If !Chars
Break
}
MsgBox, Finished:`n`n%NewString%
And the actual encryption. Just copy and paste and it will run an example:When decrypting and ecrypting, the 2 keys and the character order used must be the same or you will not be able to decryptCode:
#SingleInstance, Force
String = This Is A String That Will Be Tested For Encryption!
1Key = 12345678
2Key = 87654321
NewString := Prime_Crypt("Encrypt", String, 1Key, 2Key)
MsgBox, The string:`n`n%String%`n`nHas been encrypted to:`n`n%NewString%
String := Prime_Crypt("Decrypt", NewString, 1Key, 2Key)
MsgBox, The encrypted string:`n`n%NewString%`n`nHas been decrypted back to:`n`n%String%
ExitApp
Return
Prime_Crypt(EncDec, String, 1Key, 2Key, Chars="")
{
If !Chars
Chars := "U[5.vy:m~]s3lXAjVKhFP0^6ofbQk7e""`%?udY><qE{=GrSN_B+}nO$M()9cZtg-H£ 8R!az'i1wx#D4|p;W@&ILC2*JT"
StringSplit, 1Key, 1Key
StringSplit, 2Key, 2Key
StringSplit, String, String
StringSplit, Chars, Chars
LoopNum := 0, Prime := 3
Loop, % StrLen(String) ;%
{
LoopNum := (LoopNum >= StrLen(1Key)) ? 1 : LoopNum+1
Num := 2
Loop
{
Mod(Prime, Num) = 0 ? Prime++ : Num++
If (Prime = Num)
Break
}
ChosenPrime := 0
Loop, %Prime%
ChosenPrime := (ChosenPrime = StrLen(2Key)) ? 1 : ChosenPrime+1
Char := String%A_Index%
Loop, % StrLen(Chars) ;%
{
If (Char == Chars%A_Index%)
CryptAscNum := A_Index, Break
}
Loop, % 1Key%LoopNum%+2Key%ChosenPrime%
{
If (EncDec = "Encrypt")
CryptAscNum := (CryptAscNum >= StrLen(Chars)) ? 0 : CryptAscNum+1
Else If (EncDec = "Decrypt")
CryptAscNum := (CryptAscNum <= 0) ? StrLen(Chars) : CryptAscNum-1
Else
Return, "Only Encrypt or Decrypt may be used as parameters for EncDec with literal quotes"
}
NewString .= Chars%CryptAscNum%
Prime++
}
Return, NewString
}
Esc::ExitApp