3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Crypter{ private $Key; private $Algo; public function __construct($Algo = MCRYPT_BLOWFISH) { $this->Key = substr('key', 0, mcrypt_get_key_size($Algo, MCRYPT_MODE_ECB)); $this->Algo = $Algo; } public function Encrypt($data) { //$iv_size = mcrypt_get_iv_size($this->Algo, MCRYPT_MODE_ECB); //$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $blocksize = mcrypt_get_block_size('blowfish', 'ecb'); // get block size $pkcs = $blocksize - (strlen($data) % $blocksize); // get pkcs5 pad length $data.= str_repeat(chr($pkcs), $pkcs); // append pkcs5 padding to the data $crypt = mcrypt_encrypt($this->Algo, $this->Key, $data, MCRYPT_MODE_ECB); return rtrim(base64_encode($crypt)); } public function Decrypt($data) { $crypt = base64_decode($data); $iv_size = mcrypt_get_iv_size($this->Algo, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $decrypt = mcrypt_decrypt($this->Algo, $this->Key, $crypt, MCRYPT_MODE_ECB, $iv); return rtrim($decrypt); } } $crypter = new Crypter(); $data = "Some data to encrypt"; $encryptedData = $crypter->Encrypt($crypter); $decryptedData = $crypter->Decrypt($encryptedDate); echo "Decripted Data = [$decryptedData]\n";
Output for 7.0.6 - 7.1.0
Notice: Use of undefined constant MCRYPT_BLOWFISH - assumed 'MCRYPT_BLOWFISH' in /in/EZTeG on line 7 Fatal error: Uncaught Error: Call to undefined function mcrypt_get_key_size() in /in/EZTeG:9 Stack trace: #0 /in/EZTeG(39): Crypter->__construct() #1 {main} thrown in /in/EZTeG on line 9
Process exited with code 255.
Output for 5.4.0 - 5.5.34, 5.6.0 - 5.6.20, 7.0.0 - 7.0.5
Warning: strlen() expects parameter 1 to be string, object given in /in/EZTeG on line 20 Catchable fatal error: Object of class Crypter could not be converted to string in /in/EZTeG on line 21
Process exited with code 255.
Output for 5.0.0 - 5.3.29, 5.5.35 - 5.5.38, 5.6.21 - 5.6.28
Notice: Use of undefined constant MCRYPT_BLOWFISH - assumed 'MCRYPT_BLOWFISH' in /in/EZTeG on line 7 Fatal error: Call to undefined function mcrypt_get_key_size() in /in/EZTeG on line 9
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/EZTeG on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/EZTeG on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/EZTeG on line 4
Process exited with code 255.