Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function encode($string, $key = NULL) {
- if(!$key)
- $key = ENCRYPTION_KEY;
- $key = sha1($key);
- $strLen = strlen($string);
- $keyLen = strlen($key);
- $j = 0;
- $hash = "";
- for ($i = 0; $i < $strLen; $i++) {
- $ordStr = ord(substr($string, $i, 1));
- if ($j == $keyLen) {
- $j = 0;
- }
- $ordKey = ord(substr($key, $j, 1));
- $j++;
- $hash .= strrev(base_convert(dechex($ordStr + $ordKey), 16, 36));
- }
- $hash = $hash . "-" . md5($string);
- return $hash;
- }
- function decode($string, $key = NULL) {
- $hash = "";
- if(!empty($string)) {
- $strings = explode("-", $string);
- $string = $strings[0];
- if(!$key)
- $key = ENCRYPTION_KEY;
- $key = sha1($key);
- $strLen = strlen($string);
- $keyLen = strlen($key);
- $j = 0;
- $hash = "";
- for ($i = 0; $i < $strLen; $i+=2) {
- $ordStr = hexdec(base_convert(strrev(substr($string, $i, 2)), 36, 16));
- if ($j == $keyLen) {
- $j = 0;
- }
- $ordKey = ord(substr($key, $j, 1));
- $j++;
- $hash .= chr($ordStr - $ordKey);
- }
- //hash check
- if (md5($hash) != $strings[1])
- return "-";
- }
- return $hash;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement