3v4l.org

run code in 300+ PHP versions simultaneously
<?php class QR { const METHOD = "aes-256-ctr"; /** * * Encrypts (without authenticating) * * @param string $input - json encoded array * @param string $key - encryption key (raw binary expected) * @param boolean $encode - set to TRUE to return base64-encoded * @return string (raw binary) */ public static function encrypt($input, $key, $encode = false) { $nonceSize = openssl_cipher_iv_length(self::METHOD); $nonce = openssl_random_pseudo_bytes($nonceSize); $ciphertext = openssl_encrypt( $input, self::METHOD, $key, OPENSSL_RAW_DATA, $nonce ); //Pack the IV and ciphertext together - concatenate return ($encode ? base64_encode($nonce.$ciphertext) : $nonce.$ciphertext); } /** * * Decrypts (but does not verify) * * @param string $input - ciphertext message * @param string $key - encryption key * @param boolean $encoded - are we expecting an encoded string? * @return string */ public static function decrypt($input, $key, $encoded = false) { if($encoded){ $input = base64_decode($message, true); if($input===false){ throw new Exception("Encryption failure"); } } $nonceSize = openssl_cipher_iv_length(self::METHOD); $nonce = mb_substr($input, 0, $nonceSize, "8bit"); $ciphertext = mb_substr($input, $nonceSize, null, "8bit"); $plaintext = openssl_decrypt( $ciphertext, self::METHOD, $key, OPENSSL_RAW_DATA, $nonce ); return $plaintext; } } class QRCrypt extends QR { const HASH_ALGO = "sha256"; /** * Encrypts then MACs an input * * @param string $input - plaintext input * @param string $key - encryption key (raw binary expected) * @param boolean $encode - set to TRUE to return a base64-encoded string * @return string (raw binary) */ public static function encrypt($input, $key, $encode = false) { list($encKey, $authKey) = self::splitKeys($key); //Pass to QR::encrypt $ciphertext = parent::encrypt($input, $encKey); //Calculate a MAC of hte IV and ciphertext $mac = hash_hmac(self::HASH_ALGO, $ciphertext, $authKey, true); return ($encode ? base64_encode($mac.$ciphertext) : $mac.$ciphertext); } /** * Decrypts an input (after verifying integrity) * * @param string $input - ciphertext input * @param string $key - encryption key (raw binary expected) * @param boolean $encoded - are we expecting an encoded string? * @return string (raw binary) */ public static function decrypt($input, $key, $encoded = false) { list($encKey, $authKey) = self::splitKeys($key); if($encoded){ $input = base64_decode($input, true); if($input===false){ throw new Exception("Encryption failure"); } } //Hash size in case HASH_ALGO is changed $hs = mb_strlen(hash(self::HASH_ALGO, "", true), "8bit"); $mac = mb_substr($message, 0, $hs, "8bit"); $ciphertext = mb_substr($message, $hs, null, "8bit"); $calculated = hash_hmac( self::HASH_ALGO, $ciphertext, $authKey, true ); if(!self::hashEquals($mac, $calculated)){ throw new Exception("Encryption failure"); } //Pass to QR::decrypt $plaintext = parent::decrypt($ciphertext, $encKey); return $plaintext; } /** * Splits a key into two separate keys; one for encryption * and the other for authenticaiton * * @param string $masterKey (raw binary) * @return array (two raw binary strings) */ protected static function splitKeys($masterKey) { // You really want to implement HKDF here instead! return [ hash_hmac(self::HASH_ALGO, 'ENCRYPTION', $masterKey, true), hash_hmac(self::HASH_ALGO, 'AUTHENTICATION', $masterKey, true) ]; } /** * Compare two strings without leaking timing information * * @param string $a * @param string $b * @ref https://paragonie.com/b/WS1DLx6BnpsdaVQW * @return boolean */ protected static function hashEquals($a, $b) { if (function_exists('hash_equals')) { return hash_equals($a, $b); } $nonce = openssl_random_pseudo_bytes(32); return hash_hmac(self::HASH_ALGO, $a, $nonce) === hash_hmac(self::HASH_ALGO, $b, $nonce); } } /** * QR Code encryption/decryption * */ //Set key here $key = '5B40ACCA3F81EFCFEA49139E7D7B6944ED716B76726F88DE2ECFAD30457ADD01'; //Set directory of qr.classes.php here with trailing slash $class = "./"; //Set input here $input = 'I/hF3LEIAZVC/zbi6naANeS2Zn82CsKcbvjX6CE1xIT8Vo7rJ8jytm60hGwv09JwWQH+npIcfp/0HD37ReP3JbwSk4h+eZqBSUHZPiN5mZY='; //Are we encrypting or decrypting? (Set to "decrypt" for decryption) $decrypt = "decrypt"; /********************************************************************************/ $key = hex2bin($key); $input = trim(htmlspecialchars_decode($input)); $decrypt = $decrypt=="decrypt" ? true : false; exit(($decrypt ? QRCrypt::decrypt($input,$key,true) : QRCrypt::encrypt($input,$key,true)));

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.0140.00716.63
8.3.50.0110.01121.27
8.3.40.0070.00719.02
8.3.30.0180.00418.79
8.3.20.0080.00020.47
8.3.10.0080.00022.05
8.3.00.0040.00420.80
8.2.180.0070.01425.92
8.2.170.0000.01622.96
8.2.160.0100.00719.04
8.2.150.0000.00824.18
8.2.140.0000.00824.66
8.2.130.0000.00822.21
8.2.120.0080.00026.35
8.2.110.0060.00320.94
8.2.100.0070.00418.16
8.2.90.0040.00418.15
8.2.80.0050.00318.34
8.2.70.0060.00318.05
8.2.60.0040.00418.16
8.2.50.0030.00618.10
8.2.40.0050.00520.37
8.2.30.0080.00020.76
8.2.20.0000.00817.98
8.2.10.0050.00218.08
8.2.00.0030.00518.08
8.1.280.0090.00625.92
8.1.270.0040.00423.96
8.1.260.0040.00428.09
8.1.250.0000.00828.09
8.1.240.0000.00922.55
8.1.230.0040.00821.08
8.1.220.0000.00917.79
8.1.210.0000.01019.10
8.1.200.0050.00517.48
8.1.190.0040.00817.23
8.1.180.0060.00318.10
8.1.170.0080.00018.63
8.1.160.0000.00722.21
8.1.150.0080.00018.91
8.1.140.0050.00319.71
8.1.130.0000.00717.54
8.1.120.0050.00317.61
8.1.110.0090.00017.58
8.1.100.0000.00817.50
8.1.90.0000.00817.45
8.1.80.0000.00717.53
8.1.70.0000.00817.51
8.1.60.0090.00017.64
8.1.50.0040.00417.74
8.1.40.0040.00417.57
8.1.30.0000.00817.81
8.1.20.0000.00817.72
8.1.10.0000.00917.63
8.1.00.0000.00817.63
8.0.300.0090.00020.28
8.0.290.0080.00017.00
8.0.280.0030.00318.50
8.0.270.0080.00017.52
8.0.260.0000.00816.95
8.0.250.0030.00317.07
8.0.240.0030.00517.18
8.0.230.0050.00317.08
8.0.220.0040.00417.13
8.0.210.0050.00316.97
8.0.200.0030.00317.06
8.0.190.0030.00617.13
8.0.180.0060.00317.09
8.0.170.0020.00517.11
8.0.160.0040.00417.15
8.0.150.0050.00317.03
8.0.140.0070.00417.00
8.0.130.0000.00613.50
8.0.120.0040.00416.99
8.0.110.0040.00417.13
8.0.100.0030.00517.07
8.0.90.0040.00417.19
8.0.80.0000.01417.00
8.0.70.0050.00316.98
8.0.60.0040.00417.13
8.0.50.0000.00717.08
8.0.30.0120.00717.14
8.0.20.0100.01017.43
8.0.10.0070.00017.07
8.0.00.0100.00816.84
7.4.330.0000.00515.08
7.4.320.0030.00316.65
7.4.300.0000.00616.48
7.4.290.0030.00316.54
7.4.280.0030.00516.59
7.4.270.0070.00016.66
7.4.260.0000.00716.63
7.4.250.0000.00716.42
7.4.240.0070.00016.61
7.4.230.0030.00316.60
7.4.220.0120.00816.77
7.4.210.0050.01416.68
7.4.200.0040.00416.60
7.4.160.0040.01416.53
7.4.150.0200.00317.40
7.4.140.0110.01317.86
7.4.130.0140.00516.58
7.4.120.0100.00716.67
7.4.110.0060.01616.63
7.4.100.0130.01016.53
7.4.90.0100.00716.63
7.4.80.0110.00719.39
7.4.70.0090.00816.66
7.4.60.0110.00616.48
7.4.50.0000.01016.48
7.4.40.0100.00716.49
7.4.30.0070.01016.63
7.4.00.0030.01215.14
7.3.330.0000.00513.51
7.3.320.0000.00513.43
7.3.310.0030.00616.54
7.3.300.0000.00716.61
7.3.290.0070.00016.37
7.3.280.0110.00816.51
7.3.270.0070.01117.40
7.3.260.0100.01016.74
7.3.250.0100.01116.51
7.3.240.0060.01716.55
7.3.230.0180.00316.67
7.3.210.0070.01116.57
7.3.200.0060.01516.54
7.3.190.0080.00916.79
7.3.180.0030.01416.84
7.3.170.0150.01216.67
7.3.160.0040.01516.70
7.3.120.0120.00414.96
7.3.110.0090.00614.77
7.3.100.0030.00915.11
7.3.90.0040.01114.93
7.3.80.0110.00315.11
7.3.70.0090.00614.96
7.3.60.0090.00614.61
7.3.50.0060.01015.10
7.3.40.0070.00714.85
7.3.30.0070.01014.69
7.3.20.0080.00416.55
7.3.10.0080.01116.42
7.3.00.0070.01016.69
7.2.330.0060.01316.58
7.2.320.0100.01016.70
7.2.310.0140.01116.75
7.2.300.0180.00016.71
7.2.290.0170.00016.77
7.2.240.0030.00915.13
7.2.230.0090.00615.22
7.2.220.0040.00814.87
7.2.210.0070.00715.19
7.2.200.0030.01014.85
7.2.190.0060.00314.90
7.2.180.0030.01215.12
7.2.170.0030.00915.21
7.2.160.0030.01215.33
7.2.150.0030.01216.85
7.2.140.0030.00916.88
7.2.130.0080.01016.77
7.2.120.0070.00816.85
7.2.110.0120.00316.73
7.2.100.0070.01116.92
7.2.90.0130.00916.95
7.2.80.0090.01016.88
7.2.70.0120.00816.85
7.2.60.0080.00916.78
7.2.50.0110.00916.78
7.2.40.0130.00816.81
7.2.30.0100.00816.94
7.2.20.0130.00616.62
7.2.10.0110.00716.92
7.2.00.0080.01017.57
7.1.330.0100.00315.80
7.1.320.0000.01315.79
7.1.310.0030.01315.70
7.1.300.0070.00715.94
7.1.290.0070.00315.89
7.1.280.0070.00715.76
7.1.270.0070.00715.58
7.1.260.0110.00315.80
7.1.250.0100.00315.56
7.1.240.0060.00315.93
7.1.230.0110.00015.72
7.1.220.0090.00315.72
7.1.210.0030.01115.72
7.1.200.0000.01215.95
7.1.190.0070.01015.54
7.1.180.0060.00615.86
7.1.170.0030.01015.70
7.1.160.0050.00815.61
7.1.150.0040.00815.86
7.1.140.0040.00415.82
7.1.130.0060.00915.93
7.1.120.0070.00715.59
7.1.110.0090.00615.95
7.1.100.0070.00315.90
7.1.90.0070.00715.86
7.1.80.0030.01415.51
7.1.70.0030.00916.64
7.1.60.0080.01017.48
7.1.50.0120.00716.45
7.1.40.0060.00815.51
7.1.30.0000.01615.67
7.1.20.0000.01515.99
7.1.10.0070.00715.79
7.1.00.0030.04119.19
7.0.330.0030.00915.38
7.0.320.0040.00415.33
7.0.310.0030.00615.39
7.0.300.0000.00815.36
7.0.290.0050.00415.38
7.0.280.0000.00915.57
7.0.270.0060.00315.38
7.0.260.0000.01415.57
7.0.250.0030.00815.57
7.0.240.0030.00915.53
7.0.230.0100.00315.13
7.0.220.0080.00315.47
7.0.210.0030.01015.38
7.0.200.0070.01114.88
7.0.190.0000.01515.36
7.0.180.0100.00315.43
7.0.170.0040.01115.21
7.0.160.0080.00315.47
7.0.150.0000.01315.53
7.0.140.0000.01215.33
7.0.130.0100.00015.29
7.0.120.0110.00415.54
7.0.110.0040.00915.54
7.0.100.0030.00915.43
7.0.90.0070.00715.51
7.0.80.0070.00715.16
7.0.70.0050.00515.45
7.0.60.0050.04518.56
7.0.50.0050.03016.76
7.0.40.0170.03616.85
7.0.30.0070.03816.77
7.0.20.0180.02916.84
7.0.10.0130.04116.69
7.0.00.0220.03316.72
5.6.380.0120.00314.40
5.6.370.0030.01014.52
5.6.360.0040.00714.51
5.6.350.0000.01313.99
5.6.340.0100.00314.62
5.6.330.0080.00514.48
5.6.320.0030.01014.71
5.6.310.0090.00614.45
5.6.300.0070.00314.17
5.6.290.0000.01214.54
5.6.280.0060.04017.93
5.6.270.0030.01214.42
5.6.260.0060.00614.38
5.6.250.0030.00614.13
5.6.240.0030.00614.61
5.6.230.0070.00714.47
5.6.220.0080.00414.32
5.6.210.0070.02517.62
5.6.200.0080.02816.24
5.6.190.0120.03817.44
5.6.180.0130.03417.46
5.6.170.0080.03717.47
5.6.160.0230.03317.32
5.6.150.0220.03317.22
5.6.140.0250.03717.44
5.6.130.0300.03717.33
5.6.120.0150.04617.41
5.6.110.0100.04217.47
5.6.100.0120.03317.59
5.6.90.0150.03717.37
5.6.80.0080.04417.01
5.6.70.0190.02516.96
5.6.60.0080.03517.18
5.6.50.0110.03017.08
5.6.40.0160.02917.01
5.6.30.0360.03817.00
5.6.20.0180.03517.00
5.6.10.0210.03417.03
5.6.00.0230.03117.02
5.5.380.0000.01011.04
5.5.370.0090.00311.46
5.5.360.0030.00511.23
5.5.350.0110.04315.73
5.5.340.0050.02514.69
5.5.330.0150.02715.79
5.5.320.0120.03015.84
5.5.310.0150.02816.00
5.5.300.0180.03515.69
5.5.290.0300.03615.74
5.5.280.0150.04915.80
5.5.270.0120.03315.77
5.5.260.0190.03215.67
5.5.250.0180.02315.68
5.5.240.0130.03215.41
5.5.230.0130.02615.33
5.5.220.0030.03915.43
5.5.210.0120.02815.35
5.5.200.0110.02815.31
5.5.190.0280.02815.33
5.5.180.0180.03315.44
5.5.170.0030.00711.04
5.5.160.0250.03015.44
5.5.150.0280.03215.31
5.5.140.0290.03515.30
5.5.130.0200.04115.36
5.5.120.0310.02515.38
5.5.110.0180.03315.39
5.5.100.0170.03515.30
5.5.90.0230.03015.38
5.5.80.0220.03015.20
5.5.70.0190.03915.22
5.5.60.0270.03915.29
5.5.50.0230.04015.24
5.5.40.0180.03115.41
5.5.30.0180.03115.24
5.5.20.0150.03515.32
5.5.10.0240.02615.28
5.5.00.0200.03215.36

preferences:
46.63 ms | 401 KiB | 5 Q