A simple two-way function to encrypt or decrypt a string

This function will provide you a two-way system to encrypt a string or decrypt an encrypted string.

So, how to encrypt a string?
Just call this function and pass your string. Additionally set your second parameter to 'e' (optional). To encrypt Hello World!, write-

It’ll generate a encrypted string RTlOMytOZStXdjdHbDZtamNDWFpGdz09

And, how to decrypt?
Pass your encrypted string to the function and set second parameter to 'd'.


Need help with your WordPress tasks?

  • Wladimir Jr

    Thank you!!!

  • Forrest Rave

    in the first line
    function my_simple_crypt( $string, $action = ‘e’ ) {
    you set the parameter $action to = ‘e’, how come?

    • This is the default action, where e stands for encrypt. That means, if you pass a string as first parameter and do not pass second parameter, it’ll assume that you are going to encrypt the string.
      Bu if you want to decrypt a string, you must assign second parameter as d.
      Hope it helps.

  • hi nazmul ahsan, thanks for your script, what if i want the length of encryption to be only 16 characters long not 32. is it possible?