3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Cipher * * Simple mcrypt interface. * * Cipher is a simple class for working with mcrypt. * * @package Cipher * @author Nathan Lucas <nathan@gimpstraw.com> * @link http://www.gimpstraw.com/ * @copyright Copyright (c) 2008, Nathan Lucas * @version 2.0.0 * * Added $iv to both encrypt() and decrypt() allowing you to use preset IVs * while encrypting/decrypting data. * * Also added getIV(), which returns the instance's current IV in base64 * allowing you to store this IV for use on other instances of Cipher. */ class Cipher { /** * Algorithm to use. * * @access private * @var string */ private $algo; /** * Encryption mode. * * @access private * @var string */ private $mode; /** * Randomization source. * * @access private * @var integer */ private $source; /** * Initialization vector. * * @access private * @var string */ private $iv = null; /** * Encryption key. * * @access private * @var string */ private $key = null; /** * Cipher($algo, $mode, $source) * * Cipher constructor. Sets the algorithm being used, the encryption * mode, and the IV. * * @param string $algo * @param string $mode * @param integer $source (randomization source) * @access public * @return void */ public function __construct($algo = MCRYPT_3DES, $mode = MCRYPT_MODE_CBC, $source = MCRYPT_RAND) { $this->algo = $algo; $this->mode = $mode; $this->source = $source; if (is_null($this->algo) || (strlen($this->algo) == 0)) { $this->algo = MCRYPT_3DES; } if (is_null($this->mode) || (strlen($this->mode) == 0)) { $this->mode = MCRYPT_MODE_CBC; } } /** * encrypt($data, $key, $iv) * * Returns encrpyted $data, base64 encoded. $key must be specified at * least once, it can be changed at any point. * * @param string $data * @param mixed $key * @param string $iv * @access public * @return string */ public function encrypt($data, $key = null, $iv = null) { $key = (strlen($key) == 0) ? $key = null : $key; $this->setKey($key); $this->setIV($iv); $out = mcrypt_encrypt($this->algo, $this->key, $data, $this->mode, $this->iv); return base64_encode($out); } /** * decrypt($data, $key, $iv) * * Returns decrypted $data. $key must be specified at least once, it can * be changed at any point. * * @param mixed $data * @param mixed $key * @param string $iv * @access public * @return string */ public function decrypt($data, $key = null, $iv = null) { $key = (strlen($key) == 0) ? $key = null : $key; $this->setKey($key); $this->setIV($iv); $data = base64_decode($data); $out = mcrypt_decrypt($this->algo, $this->key, $data, $this->mode, $this->iv); return trim($out); } /** * getIV() * * Returns the IV used for encryption so you can use it again in another * Cipher instance to decrypt data. * * @access public * @return string */ public function getIV() { return base64_encode($this->iv); } /** * setIV($iv) * * Sets IV. If $iv is specified, the instance IV will be set to this. If not, * the instance will generate an IV. * * @param string $iv * @access private * @return void */ private function setIV($iv) { if (!is_null($iv)) { $this->iv = base64_decode($iv); } if (is_null($this->iv)) { $iv_size = mcrypt_get_iv_size($this->algo, $this->mode); $this->iv = mcrypt_create_iv($iv_size, $this->source); } } /** * setKey($data, $key) * * Sets Cipher::key. This will be the key used for the encrypt and decrypt * methods until another $key is specified. This will trigger an error if * no initial key is set. * * @param mixed $key * @access private * @return void */ private function setKey($key) { if (!is_null($key)) { $key_size = mcrypt_get_key_size($this->algo, $this->mode); $this->key = hash("sha256", $key, true); $this->key = substr($this->key, 0, $key_size); } if (is_null($this->key)) { trigger_error("You must specify a key at least once in either Cipher::encrpyt() or Cipher::decrypt().", E_USER_ERROR); } } } $cipher = new Cipher(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB); $kunci = "%^$%^&%*HJGHJK"; $string="sembunyikan aku"; $en = $cipher->encrypt($string, $kunci); $de = $cipher->decrypt($en, $kunci); echo "Enkrispi Kata : $string \n"; echo "Hasil Enkripsi : $en \n"; echo "Hasil Dekrispi : $de \n";

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0070.01418.43
8.3.50.0070.01122.89
8.3.40.0070.00718.79
8.3.30.0110.00319.21
8.3.20.0040.00420.34
8.3.10.0050.00321.79
8.3.00.0050.00319.68
8.2.180.0040.01118.63
8.2.170.0170.00322.96
8.2.160.0100.00320.64
8.2.150.0050.00325.66
8.2.140.0000.00824.66
8.2.130.0040.00426.16
8.2.120.0040.00419.23
8.2.110.0090.00020.52
8.2.100.0040.00817.91
8.2.90.0040.00417.63
8.2.80.0080.00018.96
8.2.70.0080.00017.90
8.2.60.0090.00018.05
8.2.50.0050.00318.07
8.2.40.0030.00519.78
8.2.30.0030.00619.57
8.2.20.0040.00417.71
8.2.10.0040.00418.11
8.2.00.0080.00317.69
8.1.280.0130.00725.92
8.1.270.0030.00623.82
8.1.260.0000.00826.35
8.1.250.0040.00428.09
8.1.240.0090.00022.31
8.1.230.0090.00322.23
8.1.220.0030.00617.74
8.1.210.0040.00418.77
8.1.200.0000.00917.48
8.1.190.0000.00817.63
8.1.180.0000.00818.89
8.1.170.0000.00918.72
8.1.160.0030.00618.95
8.1.150.0070.00018.89
8.1.140.0040.00417.46
8.1.130.0000.00817.82
8.1.120.0040.00417.46
8.1.110.0000.00717.47
8.1.100.0040.00417.38
8.1.90.0000.00717.47
8.1.80.0000.00817.46
8.1.70.0030.00517.32
8.1.60.0060.00317.62
8.1.50.0050.00317.55
8.1.40.0040.00417.53
8.1.30.0040.00417.65
8.1.20.0000.00817.50
8.1.10.0030.00517.56
8.1.00.0000.00817.55
8.0.300.0000.00718.77
8.0.290.0000.00816.88
8.0.280.0030.00318.57
8.0.270.0030.00317.36
8.0.260.0030.00317.21
8.0.250.0000.00717.05
8.0.240.0000.00717.08
8.0.230.0000.00717.03
8.0.220.0070.00017.06
8.0.210.0070.00017.02
8.0.200.0040.00416.98
8.0.190.0040.00417.09
8.0.180.0040.00417.05
8.0.170.0030.00616.98
8.0.160.0050.00317.16
8.0.150.0020.00516.98
8.0.140.0040.00416.88
8.0.130.0030.00313.45
8.0.120.0030.00617.05
8.0.110.0040.00416.93
8.0.100.0040.00416.93
8.0.90.0070.00016.82
8.0.80.0030.01217.05
8.0.70.0050.00217.05
8.0.60.0050.00217.01
8.0.50.0020.00516.84
8.0.30.0120.00817.24
8.0.20.0130.00617.40
8.0.10.0040.00417.14
8.0.00.0120.00916.91
7.4.330.0060.00015.08
7.4.320.0020.00516.62
7.4.300.0000.00616.52
7.4.290.0050.00316.71
7.4.280.0000.00716.71
7.4.270.0030.00316.57
7.4.260.0080.00016.45
7.4.250.0000.00716.59
7.4.240.0050.00216.59
7.4.230.0030.00316.64
7.4.220.0070.01116.64
7.4.210.0070.01416.78
7.4.200.0070.00016.70
7.4.160.0060.00916.57
7.4.150.0140.00417.40
7.4.140.0140.00617.86
7.4.130.0080.00916.54
7.4.120.0050.01216.54
7.4.110.0060.01216.57
7.4.100.0070.01416.66
7.4.90.0070.01016.80
7.4.80.0230.00019.39
7.4.70.0070.01116.60
7.4.60.0070.01016.68
7.4.50.0030.00716.33
7.4.40.0120.00616.71
7.4.30.0100.00716.57
7.4.10.0060.01215.14
7.4.00.0070.00914.95
7.3.330.0030.00313.52
7.3.320.0050.00013.29
7.3.310.0000.00716.59
7.3.300.0030.00316.50
7.3.290.0080.00616.46
7.3.280.0090.00916.50
7.3.270.0110.00617.40
7.3.260.0060.01216.75
7.3.250.0120.00716.68
7.3.240.0070.01116.43
7.3.230.0070.01416.68
7.3.210.0100.00716.56
7.3.200.0110.00719.39
7.3.190.0140.00716.62
7.3.180.0030.01416.49
7.3.170.0060.01016.46
7.3.160.0080.00816.76
7.3.130.0060.01214.91
7.3.120.0110.00515.01
7.3.110.0080.01015.03
7.3.100.0040.00914.68
7.3.90.0040.00715.01
7.3.80.0040.01115.03
7.3.70.0060.01014.93
7.3.60.0090.00314.85
7.3.50.0050.00514.80
7.3.40.0030.00914.78
7.3.30.0090.00714.86
7.3.20.0070.00516.60
7.3.10.0080.00816.65
7.3.00.0030.00916.65
7.2.330.0070.01216.58
7.2.320.0070.01116.80
7.2.310.0140.00416.73
7.2.300.0060.01316.75
7.2.290.0120.01116.51
7.2.260.0080.01115.15
7.2.250.0100.00915.14
7.2.240.0020.01314.89
7.2.230.0100.00515.08
7.2.220.0080.00615.03
7.2.210.0060.00714.81
7.2.200.0030.01314.99
7.2.190.0030.01015.15
7.2.180.0060.00915.10
7.2.170.0120.00215.03
7.2.160.0050.00515.05
7.2.150.0060.00917.06
7.2.140.0040.00816.69
7.2.130.0050.00816.99
7.2.120.0060.00916.91
7.2.110.0080.00716.86
7.2.100.0040.00816.75
7.2.90.0100.00517.03
7.2.80.0050.01016.97
7.2.70.0070.00617.04
7.2.60.0080.00916.88
7.2.50.0100.00617.01
7.2.40.0050.00917.05
7.2.30.0070.00816.96
7.2.20.0110.00616.71
7.2.10.0040.00917.01
7.2.00.0090.00817.75
7.1.330.0080.00615.88
7.1.320.0080.00515.87
7.1.310.0050.00815.83
7.1.300.0030.00715.77
7.1.290.0050.00615.67
7.1.280.0070.00615.89
7.1.270.0070.00415.76
7.1.260.0040.00615.42
7.1.250.0060.00615.58
7.1.240.0110.00715.71
7.1.230.0120.00315.77
7.1.220.0070.00715.68
7.1.210.0000.01115.84
7.1.200.0120.00115.73
7.1.190.0090.00315.78
7.1.180.0060.00315.91
7.1.170.0030.00915.64
7.1.160.0070.00715.37
7.1.150.0060.00915.87
7.1.140.0100.00315.70
7.1.130.0070.00715.46
7.1.120.0000.00915.34
7.1.110.0030.00715.68
7.1.100.0040.01115.82
7.1.90.0070.00715.93
7.1.80.0070.00715.79
7.1.70.0040.00816.37
7.1.60.0030.00816.30
7.1.50.0110.00625.12
7.1.40.0040.00815.77
7.1.30.0060.00915.47
7.1.20.0030.01015.64
7.1.10.0030.00815.83
7.1.00.0040.04019.05
7.0.330.0040.01115.22
7.0.320.0000.01415.38
7.0.310.0000.01315.44
7.0.300.0000.00915.35
7.0.290.0030.00915.56
7.0.280.0040.00415.30
7.0.270.0070.00715.14
7.0.260.0070.00415.48
7.0.250.0080.00415.45
7.0.240.0000.00915.46
7.0.230.0100.00315.36
7.0.220.0040.00715.35
7.0.210.0070.00015.49
7.0.200.0070.00716.21
7.0.190.0070.00315.48
7.0.180.0030.00815.44
7.0.170.0040.00815.41
7.0.160.0040.00415.44
7.0.150.0100.00315.33
7.0.140.0050.02218.70
7.0.130.0000.01015.24
7.0.120.0040.01115.59
7.0.110.0070.00715.48
7.0.100.0110.00415.59
7.0.90.0060.00615.25
7.0.80.0090.00315.28
7.0.70.0030.01315.43
7.0.60.0100.04017.71
7.0.50.0030.03016.89
7.0.40.0090.04316.83
7.0.30.0170.04516.87
7.0.20.0250.03016.85
7.0.10.0080.04316.85
7.0.00.0070.02516.79
5.6.400.0060.01014.18
5.6.390.0000.01714.70
5.6.380.0070.00714.38
5.6.370.0030.01014.44
5.6.360.0030.01214.60
5.6.350.0080.00814.70
5.6.340.0060.00314.39
5.6.330.0040.01814.70
5.6.320.0040.01114.39
5.6.310.0030.00714.05
5.6.300.0100.00314.62
5.6.290.0100.00314.51
5.6.280.0080.03517.83
5.6.270.0060.00914.59
5.6.260.0070.00714.46
5.6.250.0110.00414.19
5.6.240.0060.00814.43
5.6.230.0070.00414.52
5.6.220.0080.00414.44
5.6.210.0020.02717.50
5.6.200.0100.03716.14
5.6.190.0110.03717.52
5.6.180.1580.03017.41
5.6.170.0200.03317.51
5.6.160.0090.04217.55
5.6.150.0020.03216.32
5.6.140.0030.02616.33
5.6.130.0060.03616.26
5.6.120.0080.04317.80
5.6.110.0100.04517.79
5.6.100.0080.03317.80
5.6.90.0090.04417.66
5.6.80.0100.03517.51
5.6.70.1850.02317.25
5.6.60.0060.00613.96
5.6.50.0040.00414.11
5.6.40.0060.00614.25
5.6.30.0030.00914.51
5.6.20.0000.00914.37
5.6.10.0070.00714.41
5.6.00.0000.00914.39
5.5.380.0100.00014.22
5.5.370.0090.00614.55
5.5.360.0000.01614.23
5.5.350.0150.03517.45
5.5.340.0060.02416.21
5.5.330.0020.03917.26
5.5.320.0100.02617.45
5.5.310.0190.03017.25
5.5.300.0030.03916.28
5.5.290.0050.03316.23
5.5.280.0100.03317.55
5.5.270.0050.02517.73
5.5.260.0070.04117.61
5.5.250.0130.03617.62
5.5.240.0130.04217.20
5.5.230.0070.00714.47
5.5.220.0060.01013.98
5.5.210.0000.01614.23
5.5.200.0130.00014.42
5.5.190.0080.00414.36
5.5.180.0030.01014.36
5.5.170.0040.01114.36
5.5.160.0060.00314.39
5.5.150.0040.00813.82
5.5.140.0030.01314.03
5.5.130.0050.00514.13
5.5.120.0110.00414.38
5.5.110.0060.00314.37
5.5.100.0060.00314.08
5.5.90.0060.00914.42
5.5.80.0030.01014.06
5.5.70.0040.00814.12
5.5.60.0070.00314.41
5.5.50.0090.00613.99
5.5.40.0120.00314.01
5.5.30.0130.00314.20
5.5.20.0030.00914.13
5.5.10.0070.01014.20
5.5.00.0040.00413.80
5.4.450.1650.02015.44
5.4.440.0080.02015.37
5.4.430.1550.01915.35
5.4.420.1630.01815.42
5.4.410.1670.02015.32
5.4.400.0030.02115.13
5.4.390.1670.02215.21
5.4.380.1860.02115.09
5.4.370.1820.01815.25
5.4.360.1900.02015.22
5.4.350.1860.01715.16
5.4.340.0020.02515.28
5.4.330.0060.00011.37
5.4.320.1550.02215.14
5.4.310.1800.02515.23
5.4.300.1930.02215.23
5.4.290.2020.02215.08
5.4.280.1830.02515.23
5.4.270.2030.02415.19
5.4.260.1880.02115.28
5.4.250.1900.02215.28
5.4.240.1780.02015.18
5.4.230.1850.01815.32
5.4.220.1950.02215.19
5.4.210.1860.02215.26
5.4.200.1870.01815.14
5.4.190.1800.02215.16
5.4.180.2050.02715.13
5.4.170.1880.01815.27
5.4.160.1800.02315.10
5.4.150.1590.01715.26
5.4.140.2350.02413.86
5.4.130.1930.02313.93
5.4.120.1870.02113.88
5.4.110.1790.02013.82
5.4.100.2180.01713.92
5.4.90.2100.02313.89
5.4.80.1900.01813.91
5.4.70.2030.02413.75
5.4.60.2010.02013.96
5.4.50.1720.02013.80
5.4.40.2100.02613.94
5.4.30.1770.02813.95
5.4.20.1880.02213.96
5.4.10.1850.01813.81
5.4.00.2000.02413.63
5.3.290.3830.04314.81
5.3.280.3630.03014.70
5.3.270.3700.03314.64
5.3.260.3730.03014.65
5.3.250.3700.02714.73
5.3.240.4170.04014.61
5.3.230.3600.04014.54
5.3.220.3600.03714.64
5.3.210.3630.04014.50
5.3.200.3800.04314.59
5.3.190.3930.04314.64
5.3.180.3830.04014.75
5.3.170.3870.04014.58
5.3.160.3370.04014.58
5.3.150.3930.04014.57
5.3.140.3770.02714.50
5.3.130.3830.03014.69
5.3.120.3970.04014.57
5.3.110.3970.03014.67
5.3.100.3730.04314.03
5.3.90.3700.03314.04
5.3.80.3670.04014.02
5.3.70.3530.04014.18
5.3.60.3730.03714.16
5.3.50.3670.03713.90
5.3.40.3770.03713.91
5.3.30.3730.03313.84
5.3.20.3470.03313.77
5.3.10.3230.03313.59
5.3.00.3530.03313.58
5.2.170.3000.03311.20
5.2.160.3130.03011.11
5.2.150.2530.02711.11
5.2.140.2730.02311.19
5.2.130.3130.02011.19
5.2.120.2770.03011.27
5.2.110.3200.03311.14
5.2.100.2870.02711.05
5.2.90.3130.02711.05
5.2.80.3430.03311.05
5.2.70.3130.02311.11
5.2.60.2600.03311.01
5.2.50.3100.02311.14
5.2.40.2530.03011.03
5.2.30.1930.02711.01
5.2.20.2200.02310.89
5.2.10.2570.03310.94
5.2.00.2470.02710.68
5.1.60.2370.03010.04
5.1.50.2630.02010.09
5.1.40.2500.0279.94
5.1.30.2400.03010.35
5.1.20.2400.02710.29
5.1.10.2470.02710.09
5.1.00.2500.02710.26
5.0.50.1500.0238.49
5.0.40.1230.0178.38
5.0.30.1430.0308.17
5.0.20.1430.0238.34
5.0.10.1270.0208.13
5.0.00.1430.0338.29
4.4.90.1030.0178.09
4.4.80.0830.0178.09
4.4.70.1270.0208.09
4.4.60.1230.0208.09
4.4.50.1270.0178.09
4.4.40.1230.0238.09
4.4.30.1270.0208.09
4.4.20.1170.0178.09
4.4.10.1400.0178.09
4.4.00.1200.0278.09
4.3.110.1200.0178.09
4.3.100.1400.0178.09
4.3.90.1270.0178.09
4.3.80.1200.0278.09
4.3.70.1030.0208.09
4.3.60.1070.0178.09
4.3.50.1300.0178.09
4.3.40.1270.0208.09
4.3.30.0600.0138.09
4.3.20.0570.0178.09
4.3.10.0570.0178.09
4.3.00.0570.0178.09

preferences:
43.94 ms | 401 KiB | 5 Q