Sign in to follow this  
Followers 0
Eradicator

Code Optimization

7 posts in this topic

Greetings,

I wrote a basic CD-key system, and I want to know whether it can be optimized. I don't see anything that could make it any faster, but i'd like a second opinion. It works by downloading a list of encrypted CD-keys and decrypting them while comparing them to what the user has entered. Here is the code.

$location = "http://fakewebsite.com/cdkeys.txt"
$password = "encryptionkey"

$key = IniRead(@ScriptDir & "\cd-key.ini", "CD-KEY", "KEY", "")

If $key = "" Then
    $key = InputBox("Hotkeys - CD-Key", "Please enter your CD-Key here to activate your installation.")
    If $key = "" Then
        Exit
    EndIf
    IniWriteSection(@ScriptDir & "\cd-key.ini","CD-KEY", "KEY=" & $key)
EndIf

$text = _INetGetSource($location)

TrayTip("Verifying", "Checking status of your installation.", 10, 1)

$array = StringSplit($text, @CrLf)

$i = 1

For $i = 1 To _ArraySize($array) Step 2
    If $key <> _StringEncrypt(0, $array[$i], $password, "1") Then
        If $i = _ArraySize($array) - 1 Then
            TrayTip("Error", "You have entered an invalid CD-Key or your installation has been disabled by [CE]Eradicator.", 10, 3)
            MsgBox(16, "Hotkeys - Error", "You have entered an invalid CD-Key or your installation has been disabled by [CE]Eradicator. Please restart the application and enter a valid CD-Key.")
            If FileExists(@ScriptDir & "\cd-key.ini") Then
                FileDelete(@ScriptDir & "\cd-key.ini")
            EndIf
            Exit
        EndIf
    Else
        $i = _ArraySize($array)
        TrayTip("Completed", "Your installation has been verified.", 10, 2)
        ExitLoop
    EndIf
Next

And heres that UDF. (I can't remimber who wrote it, i'd appreciate if anyone can point out who made it.)

Func _ArraySize( $aArray )
    SetError( 0 )
    
    $index = 0
    
    Do
        $pop = _ArrayPop( $aArray )
        $index = $index + 1
    Until @error = 1
    
    Return $index - 1
EndFunc

Thanks in advance.

Regards,

Eradicator

Share this post


Link to post
Share on other sites



For safety's sake, it'd be better to send the key to the server and have the server verify it. That way, someone can't just monitor network traffic and get the entire list of keys.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

For safety's sake, it'd be better to send the key to the server and have the server verify it. That way, someone can't just monitor network traffic and get the entire list of keys.

Actually, the reason I didn't do that is because the server is an older web server and I didn't figure AutoIt can write a stable basic small scale data exchange server. (Which would mean running at least three days without needing a restart.)

Regards,

Eradicator

Edited by Eradicator

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I was thinking PHP or ASP or any of the other server side languages.

Oh and, I'm pretty sure AutoIt will run alright for extended periods of time. I haven't seen anything that would give me reason to think otherwise.

One more edit... I noticed your _ArraySize call..? You could just use UBound instead.

Edited by Richard Robertson

Share this post


Link to post
Share on other sites

I was thinking PHP or ASP or any of the other server side languages.

Oh and, I'm pretty sure AutoIt will run alright for extended periods of time. I haven't seen anything that would give me reason to think otherwise.

One more edit... I noticed your _ArraySize call..? You could just use UBound instead.

Can you give me an example of how to pass an argument (in this case, the cd-key) to a .PHP or .ASP page?

Regards,

Eradicator

Share this post


Link to post
Share on other sites

Oh and, I'm pretty sure AutoIt will run alright for extended periods of time. I haven't seen anything that would give me reason to think otherwise.

I have an autoitscript running on server2k3 for over a month now. Works fine.

Share this post


Link to post
Share on other sites

Just send it tacked on the end like "http://fakesite.com/check.php?key=0478962" and then in the PHP (I don't know how to use ASP) you call $_GET["key"] and that gives you the value of the parameter (in the example 0478962).

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  
Followers 0