BASIC

Author Topic: encrypt & decrypt strings  (Read 5517 times)

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5013
  • O Rly?
    • View Profile
encrypt & decrypt strings
« 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]
« Last Edit: 2008-Aug-25 by Schranz0r »
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10695
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: encrypt & decrypt strings
« Reply #1 on: 2008-Aug-25 »
why do floats crash? You're crypting a string, don't you?
Is it GP2X safe?

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5013
  • O Rly?
    • View Profile
Re: encrypt & decrypt strings
« Reply #2 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 :)
« Last Edit: 2008-Aug-25 by Schranz0r »
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage
Re: encrypt & decrypt strings
« Reply #3 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? :-)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10695
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: encrypt & decrypt strings
« Reply #4 on: 2008-Sep-04 »
There is encrpy _and_ decrypt functions, no?

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5013
  • O Rly?
    • View Profile
Re: encrypt & decrypt strings
« Reply #5 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 ...
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage
Re: encrypt & decrypt strings
« Reply #6 on: 2008-Sep-04 »
It's a bit hard to call it from PHP now, isn't it?

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5013
  • O Rly?
    • View Profile
Re: encrypt & decrypt strings
« Reply #7 on: 2008-Sep-04 »
yepp, its just for files/offlinemode... sorry
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard