Jump to content

En/Decrypt strings


Recommended Posts

Maybe i dont see the forest for the trees.

Maybe you could take a look at this code.

The StringTrimLeft(....,16) comes from the fact, that the numbers 1-5 which are my random encrypting levels are always 16 digits long, on lvl 3.

#include <String.au3>
save(500,"Test","Money")
MsgBox("","",load("Test","Money"))

Func save($Value,$Player,$Section)
    $Level = Random(1,5)
    $temp = _StringEncrypt(1,$Level,"123456",3)
    IniWrite("tempdata.ini",$Section,$Player,$temp & _StringEncrypt(1,$Value,"123456",$Level))
    Return 1
EndFunc

Func load($Player,$Section)
    $String = IniRead("tempdata.ini",$Section,$Player,0)
    $TrimLen = StringLen($String) - 16
    
    $Level = _StringEncrypt(0,StringTrimRight($String,$TrimLen),"123456",3)
    
    $Value = _StringEncrypt(0,StringTrimLeft($String,16),"123456",$Level)
    ;$Value = Number($Value)
    Return $Value
EndFunc
Edited by Arterie
Link to comment
Share on other sites

  • Moderators

Ok, thanks. But i still want this little script wokring..

Did you ever check the value of Random()? It generates a 256 char len for me because of the decimal:

Instead of: Random(1,5)

Try: Random(1,5, 1)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Try this:

Encrypt(500, "TEST", "Money")
ConsoleWrite(Decrypt("TEST", "Money") & @CRLF)

Func Encrypt($Value, $Section, $Player)
    $Level = Random(1, 5, 1)
    $temp = _StringEncrypt(1, $Level, "123456", 3)
    $temp2 = _StringEncrypt(1, $Value, "123456", $Level)
    IniWrite("tempdata.ini", $Section, $Player, $temp2)
    IniWrite("tempdata.ini", $Section, $Player & "Level", $temp)
    Return 1
EndFunc   ;==>Encrypt

Func Decrypt($Section, $Player)
    $Level = _StringEncrypt(0, IniRead("tempdata.ini", $Section, $Player & "Level", ""), "123456", 3)
    $Value = _StringEncrypt(0, IniRead("tempdata.ini", $Section, $Player, ""), "123456", $Level)
    Return $Value
EndFunc
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...