3v4l.org

run code in 300+ PHP versions simultaneously
<?php class encryption_class { var $scramble1; // 1st string of ASCII characters var $scramble2; // 2nd string of ASCII characters var $errors; // array of error messages var $adj; // 1st adjustment value (optional) var $mod; // 2nd adjustment value (optional) function encryption_class () { // Each of these two strings must contain the same characters, but in a different order. // Use only printable characters from the ASCII table. // Each character can only appear once in each string EXCEPT for the first character // which must be duplicated at the end (this gets round a bijou problemette when the // first character of the password is also the first character in $scramble1) $this->scramble1 = '! "#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~!'; $this->scramble2 = 'f^jAE]okI\OzU[2&q1{3`h5w_794p@6s8?BgP>dFV=m D<TcS%Ze|r:lGK/uCy.Jx)HiQ!"#$\'~(;Lt-R}Ma,NvW+Ynb*0Xf'; if (strlen($this->scramble1) <> strlen($this->scramble2)) { $this->errors[] = '** SCRAMBLE1 is not same length as SCRAMBLE2 **'; } // if $this->adj = 1.75; // this value is added to the rolling fudgefactors $this->mod = 3; // if divisible by this the adjustment is made negative } // constructor function encrypt ($key, $source, $sourcelen=0) { $this->errors = array(); $fudgefactor = $this->_convertKey($key); if ($this->errors) return; if (empty($source)) { $this->errors[] = 'No value has been supplied for encryption'; return; } // if while (strlen($source) < $sourcelen) { $source .= ' '; } // while $target = NULL; $factor2 = 0; for ($i = 0; $i < strlen($source); $i++) { $char1 = substr($source, $i, 1); $num1 = strpos($this->scramble1, $char1); if ($num1 === false) { $this->errors[] = "Source string contains an invalid character ($char1)"; return; } // if $adj = $this->_applyFudgeFactor($fudgefactor); $factor1 = $factor2 + $adj; $num2 = round($factor1) + $num1; // generate offset for $scramble2 $num2 = $this->_checkRange($num2); // check range $factor2 = $factor1 + $num2; // accumulate in $factor $char2 = substr($this->scramble2, $num2, 1); $target .= $char2; } // for return $target; } // encrypt function _convertKey ($key) { if (empty($key)) { $this->errors[] = 'No value has been supplied for the encryption key'; return; } // if $array[] = strlen($key); $tot = 0; for ($i = 0; $i < strlen($key); $i++) { $char = substr($key, $i, 1); $num = strpos($this->scramble1, $char); if ($num === false) { $this->errors[] = "Key contains an invalid character ($char)"; return; } // if $array[] = $num; $tot = $tot + $num; } // for $array[] = $tot; return $array; } // _convertKey function _applyFudgeFactor (&$fudgefactor) { $fudge = array_shift($fudgefactor); $fudge = $fudge + $this->adj; $fudgefactor[] = $fudge; if (!empty($this->mod)) { // if modifier has been supplied if ($fudge % $this->mod == 0) { // if it is divisible by modifier $fudge = $fudge * -1; // reverse then sign } // if } // if return $fudge; } // _applyFudgeFactor function _checkRange ($num) { $limit = strlen($this->scramble1)-1; while ($num > $limit) { $num = $num - $limit; } // while while ($num < 0) { $num = $num + $limit; } // while return $num; } // _checkRange function decrypt ($key, $source) { $this->errors = array(); $fudgefactor = $this->_convertKey($key); if ($this->errors) return; if (empty($source)) { $this->errors[] = 'No value has been supplied for decryption'; return; } // if $target = NULL; $factor2 = 0; for ($i = 0; $i < strlen($source); $i++) { $char2 = substr($source, $i, 1); $num2 = strpos($this->scramble2, $char2); if ($num2 === false) { $this->errors[] = "Source string contains an invalid character ($char2)"; return; } // if if ($num2 == 0) { // use the last occurrence of this letter, not the first $num2 = strlen($this->scramble1)-1; } // if $adj = $this->_applyFudgeFactor($fudgefactor); $factor1 = $factor2 + $adj; $num1 = round($factor1*-1) + $num2; // generate offset for $scramble1 $num1 = $this->_checkRange($num1); // check range $factor2 = $factor1 + $num2; // accumulate in $factor2 $char1 = substr($this->scramble1, $num1, 1); $target .= $char1; } // for return rtrim($target); } // decrypt } $crypt = new encryption_class; echo $crypt->decrypt("ptufenkji", "bN,%vZ+R,rg/\9"); ?>
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/GeE8j on line 77
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/GeE8j on line 77
Output for 8.0.0 - 8.0.30
Output for 7.0.0 - 7.0.31, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; encryption_class has a deprecated constructor in /in/GeE8j on line 2 pascolo
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.38, 7.3.32 - 7.3.33
pascolo

preferences:
216.34 ms | 402 KiB | 316 Q