Jump to content

Code Optimization


Recommended Posts

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

Link to comment
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.

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
Link to comment
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.

Edited by Richard Robertson
Link to comment
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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...