what the best way to encrypt alphanumeric string to another alphanumeric (no unique char)? and also decryptable... thx
If you don't have to decrypt it you can just use md5() or something like it, for example for passwords.
/** * Encrypt/decrypt url * Encrypts and decrypts url * Usage example: - 'index.php?A='.encrypt_url("somedata") * - decrypt_url($GET['A']) */ function encrypt_url($string) { $key = "123abc"; //preset key to use on all encrypt and decrypts. $result = ''; for($i=0; $i<strlen($string); $i++) { $char = substr($string, $i, 1); $keychar = substr($key, ($i % strlen($key))-1, 1); $char = chr(ord($char)+ord($keychar)); $result.=$char; } return urlencode(base64_encode($result)); } function decrypt_url($string) { $key = "123abc"; $result = ''; $string = base64_decode(urldecode($string)); for($i=0; $i<strlen($string); $i++) { $char = substr($string, $i, 1); $keychar = substr($key, ($i % strlen($key))-1, 1); $char = chr(ord($char)-ord($keychar)); $result.=$char; } return $result; } PHP:
I just currently installed mcrypt library for a project, Nice one, very hard to decrypt data unless you know the key. But encrypted value has loads of special or must say very special characters