3v4l.org

run code in 300+ PHP versions simultaneously
<?php function mcryptPadKey($key, $cipher, $blockMode) { $td = mcrypt_module_open($cipher, '', $blockMode, ''); $size = mcrypt_enc_get_key_size($td); mcrypt_module_close($td); //echo "- " . strlen($key) . " - " . $size . "\n\n"; if (strlen($key) === 0) { $key = str_repeat("\0", $size); } else if (strlen($key) > $size) { return substr($key, 0, $size); } else if (strlen($key) % $size) { $key = $key.str_repeat("\0", $size - (strlen($key) % $size)); } return $key; } function mcryptPadIV($iv, $cipher, $blockMode) { $td = mcrypt_module_open($cipher, '', $blockMode, ''); $size = mcrypt_enc_get_block_size($td); mcrypt_module_close($td); echo "- " . strlen($iv) . " - " . $size . "\n\n"; if (strlen($iv) != $size) { echo 'ok: ' . str_repeat("\0", $size); return str_repeat("\0", $size); } else { return $iv; } } function mcryptPadData($data, $cipher, $blockMode) { if (!is_scalar($data) && $data !== null) { return $data; } $td = mcrypt_module_open($cipher, '', $blockMode, ''); $size = mcrypt_enc_get_block_size($td); mcrypt_module_close($td); //echo "- " . strlen($data) . " - " . $size . "\n\n"; if (strlen($data) < $size) { return str_pad($data, $size, "\0"); } else { return $data; } } function mcryptDataConvert($mixed, $strict = false) { if (is_string($mixed)) { return $mixed; } if ( is_array($mixed) || is_object($mixed) && !method_exists($mixed, '__toString') || is_resource($mixed) ) { return $strict ? null : ''; } else if ($mixed === null) { return ''; } else { return (string)$mixed; } } function encode($input, $mode = "ASCII") { $res = ""; switch ($mode) { case "ASCII": for($i = 0; $i < strlen($input); $i++) $res .= ord($input[$i])."-"; break; case "hex": $unpack = unpack('H*', $input); $res = array_shift($unpack); break; default: $res = $input; break; } return $res; } $data = "52824616"; $key = "khfTiNtfrZ8554khfTiNtf\0\0"; $iv = base64_decode('w1Uy6MvHZNY='); $output = "hex"; echo $iv . "\n\n"; $my_key = $key; $my_key .= substr($my_key,0,8); $iv = $iv !== null ? $iv : "ÃU2èËÇdÖ"; $data = mcryptPadData($data, MCRYPT_3DES, MCRYPT_MODE_CBC); $my_key2 = mcryptPadKey($my_key, MCRYPT_3DES, MCRYPT_MODE_CBC); $iv2 = mcryptPadIV($iv, MCRYPT_3DES, MCRYPT_MODE_CBC); $crypt = mcrypt_encrypt(MCRYPT_3DES, $my_key2, $data, MCRYPT_MODE_CBC, $iv2); echo 'data: ' . $data . "\n"; echo 'key2: ' . $my_key2 . "\n"; echo 'iv2: ' . $iv2 . "\n"; echo $crypt . "\n\n"; echo encode($crypt, $output) . "\n";
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
�U2���d� Fatal error: Uncaught Error: Undefined constant "MCRYPT_3DES" in /in/mVnuJ:106 Stack trace: #0 {main} thrown in /in/mVnuJ on line 106
Process exited with code 255.
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
�U2���d� Warning: Use of undefined constant MCRYPT_3DES - assumed 'MCRYPT_3DES' (this will throw an Error in a future version of PHP) in /in/mVnuJ on line 106 Warning: Use of undefined constant MCRYPT_MODE_CBC - assumed 'MCRYPT_MODE_CBC' (this will throw an Error in a future version of PHP) in /in/mVnuJ on line 106 Fatal error: Uncaught Error: Call to undefined function mcrypt_module_open() in /in/mVnuJ:44 Stack trace: #0 /in/mVnuJ(106): mcryptPadData('52824616', 'MCRYPT_3DES', 'MCRYPT_MODE_CBC') #1 {main} thrown in /in/mVnuJ on line 44
Process exited with code 255.
Output for 7.1.0 - 7.1.20
�U2���d� Notice: Use of undefined constant MCRYPT_3DES - assumed 'MCRYPT_3DES' in /in/mVnuJ on line 106 Notice: Use of undefined constant MCRYPT_MODE_CBC - assumed 'MCRYPT_MODE_CBC' in /in/mVnuJ on line 106 Fatal error: Uncaught Error: Call to undefined function mcrypt_module_open() in /in/mVnuJ:44 Stack trace: #0 /in/mVnuJ(106): mcryptPadData('52824616', 'MCRYPT_3DES', 'MCRYPT_MODE_CBC') #1 {main} thrown in /in/mVnuJ on line 44
Process exited with code 255.

preferences:
179.8 ms | 411 KiB | 5 Q