3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function encode($string,$key) { $key = sha1($key); $strLen = strlen($string); $keyLen = strlen($key); 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)); } return $hash; } function decode($string,$key) { $key = sha1($key); $strLen = strlen($string); $keyLen = strlen($key); 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); } return $hash; } echo encode("Please Encode Me!","This is a key"); echo decode(encode("Please Encode Me!","This is a key"),"This is a key"); ?>
Output for 5.0.4 - 7.1.0
Notice: Undefined variable: j in /in/9GeEM on line 8 Notice: Undefined variable: j in /in/9GeEM on line 9 Notice: Undefined variable: j in /in/9GeEM on line 10 Notice: Undefined variable: hash in /in/9GeEM on line 11 p3e4e4241674d2r4m4i5o464a4f2p3k5c2 Notice: Undefined variable: j in /in/9GeEM on line 8 Notice: Undefined variable: j in /in/9GeEM on line 9 Notice: Undefined variable: j in /in/9GeEM on line 10 Notice: Undefined variable: hash in /in/9GeEM on line 11 Notice: Undefined variable: j in /in/9GeEM on line 22 Notice: Undefined variable: j in /in/9GeEM on line 23 Notice: Undefined variable: j in /in/9GeEM on line 24 Notice: Undefined variable: hash in /in/9GeEM on line 25 Please Encode Me!
Output for 4.3.0 - 5.0.3
Notice: Undefined variable: j in /in/9GeEM on line 8 Notice: Undefined variable: j in /in/9GeEM on line 9 Notice: Undefined variable: j in /in/9GeEM on line 10 Notice: Undefined variable: hash in /in/9GeEM on line 11 p3e4e4241674d2r4m4i5o464a4f2p3k5c2 Notice: Undefined variable: j in /in/9GeEM on line 8 Notice: Undefined variable: j in /in/9GeEM on line 9 Notice: Undefined variable: j in /in/9GeEM on line 10 Notice: Undefined variable: hash in /in/9GeEM on line 11 Notice: Undefined variable: j in /in/9GeEM on line 22 Notice: Undefined variable: j in /in/9GeEM on line 23 Notice: Undefined variable: j in /in/9GeEM on line 24 Notice: Undefined variable: hash in /in/9GeEM on line 25 Please Encode Me!