 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
tic
Joined: 22 Apr 2007 Posts: 1786
|
Posted: Tue Jan 29, 2008 10:07 am Post subject: Prime crypt - Some custom enc/decryption |
|
|
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 decrypt
| Code: | #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 |
|
|
| Back to top |
|
 |
trik
Joined: 15 Jul 2007 Posts: 1320
|
Posted: Wed Jan 30, 2008 12:41 pm Post subject: |
|
|
Now, just to wait for Laszlo... _________________ Religion is false. >_> |
|
| Back to top |
|
 |
polyethene
Joined: 11 Aug 2004 Posts: 5248 Location: UK
|
Posted: Wed Jan 30, 2008 12:54 pm Post subject: |
|
|
Substitution ciphers like this are far from secure but they have practical uses. I currently have a client (ahk) server (php) scripts that obfuscate strings with hex conversion and simple rotation. It's fast and can be done in minimal amount of code. Statistically no encryption is absolute, so what you employ should depend on the nature of your working environment. tic's method looks interesting, I'd like to see his finished php version  _________________ GitHub • Scripts • IronAHK • Contact by email not private message. |
|
| Back to top |
|
 |
tic
Joined: 22 Apr 2007 Posts: 1786
|
Posted: Wed Jan 30, 2008 1:54 pm Post subject: |
|
|
strictly speaking it isnt neccesary to use prime numbers, and this is greatly slowing the code down for longer strings.
i just need a way to generate a constantly changing number. it doesnt matter that a "hacker" will know this routine, so in the case above 3,5,7,11,13.....
as the hacker does not know the length of the keys or what they contain, but this number must still be variable. unfortuantely it takes time to work out large prime numbers. i need a formula that will generate a constantly changing result, and will not be reciprocal, for example using sine or cosine. so for example prime numbers will never be the same as the last one and the result has a varying degree of increment, however it is purely divergent, so will continue to increase. it would be ideal to have an oscilating function that does not give the same results every cycle (if that makes sense )
any ideas?
Edit:
This is close but no cigar. it repeats after nearly 10000:
| Code: | pi := 4*ATan(1)
Loop, 10000
y := Round(Sqrt(Mod(100*(Cos(A_Index*(pi/180)+A_Index)), 100*(Sin(A_Index*(pi/180)+A_Index)))**2)) |
anyone can do better?
Edit2:
This does not repeat until about 994000:
| Code: | | y := Round(Sqrt(Mod(100*(Cos(A_Index*(pi/180)+A_Index)), 100*(Sin(A_Index*(pi/180)+Cos(A_Index))))**2)) |
but is quite slow. anyone got a quicker one? |
|
| Back to top |
|
 |
tic
Joined: 22 Apr 2007 Posts: 1786
|
Posted: Wed Jan 30, 2008 5:01 pm Post subject: |
|
|
I will write a php version of this Titan, but am first just trying to perfect the ahk version (i had already started on the php version).
Once finished I will fully show how to copy protect an exe using this method and still allow your app to be portable!
I can see a weakness, but it relates to what I am currently working on now. As said earlier I need a non repeating array of numbers, of infinite length that can be recreated (ie not random), and the first number in the array must be greater than the length of the key.
I would be interested in what Laszlo has to say and whether he can suggest a way to generate these numbers.
If anyone needs an explanation of how it works, I will explain (dont read that as me not thinking youre smart enough lol just that you may not want to bumble through my code as I know I often dont want to with other peoples scripts) |
|
| Back to top |
|
 |
arsan
Joined: 02 Jan 2010 Posts: 105
|
Posted: Wed Mar 17, 2010 11:10 pm Post subject: |
|
|
| tic wrote: | 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$&*)...........
|
I liked the fact that we could choose the characters we plan on using. But suppose if I chose to use only alpha-numeric characters, ie, [a-zA-Z0-9] in the "Chars" variable, then the characters in the original string which are not present in the "Chars" variable won't be decrypted. They will stay as they were in the encrypted text even after decryption. |
|
| Back to top |
|
 |
tic
Joined: 22 Apr 2007 Posts: 1786
|
Posted: Thu Mar 18, 2010 10:00 am Post subject: |
|
|
| Heh....I was just mucking around....I dont think it would be a good idea to use this rereading this. Phew that was a long time ago... |
|
| Back to top |
|
 |
arsan
Joined: 02 Jan 2010 Posts: 105
|
Posted: Thu Mar 18, 2010 11:46 am Post subject: |
|
|
| Well, I was just studying whatever I could find about encryption in this forum, even if they are old. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|