GLBasic forum

Codesnippets => Userlibs [ *.gbal] => Topic started by: Schranz0r on 2008-Aug-25

Title: encrypt & decrypt strings
Post by: Schranz0r on 2008-Aug-25
This gbal encrypt and decrypt a string with a char like "x".
More math inside that functions!

Example:
Code: (glbasic) [Select]
Code$ = "test"

encrypt_code$ = encrypt$(Code$,"x")

decrypt_code$ = decrypt$(encrypt_code$,"x")

WHILE TRUE

PRINT  encrypt_code$,10,10 // test decryped are: 33408-29088-33120-33408
PRINT  decrypt_code$,10,20

SHOWSCREEN
WEND
END

You can de/encrypt levelpasswords, variables (integer/floats/strings), etc... 

"HOWTO": de/encrypt integer/float variables

Code: (glbasic) [Select]
// set variable
my_var = 123

// set variable as string
Code$ = ""+my_var

// encrypt string
encrypt_code$ = encrypt$(Code$,"x")

// decrypt string
decrypt_code$ = decrypt$(encrypt_code$,"x")

// set decrypted string to integer
decrypt_var = decrypt_code$  // Thats GLBasic style :D


WHILE TRUE

// see the results
PRINT  encrypt_code$,10,10
PRINT  decrypt_var,10,30

SHOWSCREEN
WEND
END

Thats it ;)

[attachment deleted by admin]
Title: Re: encrypt & decrypt strings
Post by: Kitty Hello on 2008-Aug-25
why do floats crash? You're crypting a string, don't you?
Is it GP2X safe?
Title: Re: encrypt & decrypt strings
Post by: Schranz0r on 2008-Aug-25
why do floats crash? You're crypting a string, don't you?
Is it GP2X safe?

Whoops, floats are ok   :whistle:


Code: (glbasic) [Select]
// set variable
my_var = 1876.08

// set variable as String
Code$ = ""+my_var

// encrypt string
encrypt_code$ = encrypt$(Code$,"x")

// decrypt string
decrypt_code$ = decrypt$(encrypt_code$,"x")

// set decrypted string to integer/float
decrypt_var = decrypt_code$


WHILE TRUE

// see the results
PRINT  encrypt_code$,10,10
PRINT  decrypt_var,10,30

SHOWSCREEN
WEND
END

Yes, its GP2X safe :)
Title: Re: encrypt & decrypt strings
Post by: Moru on 2008-Sep-04
Since I can't see how it's done, I can't use it... no use encoding something if I can't decode it on the other side, now is there? :-)
Title: Re: encrypt & decrypt strings
Post by: Kitty Hello on 2008-Sep-04
There is encrpy _and_ decrypt functions, no?
Title: Re: encrypt & decrypt strings
Post by: Schranz0r on 2008-Sep-04
Yes Gernot.

this codeexample encrypt a variable to a local variable (encrypt_code$ )
and decrypt to variable (decrypt_code$)

You can encrypt to a file, and decrypt from it for example.
Ther you can save levelpasswords/highscores ...
Title: Re: encrypt & decrypt strings
Post by: Moru on 2008-Sep-04
It's a bit hard to call it from PHP now, isn't it?
Title: Re: encrypt & decrypt strings
Post by: Schranz0r on 2008-Sep-04
yepp, its just for files/offlinemode... sorry