3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * http://stackoverflow.com/questions/9262109/php-simplest-two-way-encryption/30189841#30189841 * * This is not safe to use */ class UnsafeCrypto { const METHOD = 'aes-256-ctr'; /** * Encrypts (but does not authenticate) a message * * @param string $message - plaintext message * @param string $key - encryption key (raw binary expected) * @param boolean $encode - set to TRUE to return a base64-encoded * @return string (raw binary) */ public static function encrypt($message, $key, $encode = false) { $nonceSize = openssl_cipher_iv_length(self::METHOD); $nonce = openssl_random_pseudo_bytes($nonceSize); $ciphertext = openssl_encrypt( $message, self::METHOD, $key, OPENSSL_RAW_DATA, $nonce ); // Now let's pack the IV and the ciphertext together // Naively, we can just concatenate if ($encode) { return base64_encode($nonce.$ciphertext); } return $nonce.$ciphertext; } /** * Decrypts (but does not verify) a message * * @param string $message - ciphertext message * @param string $key - encryption key (raw binary expected) * @param boolean $encoded - are we expecting an encoded string? * @return string */ public static function decrypt($message, $key, $encoded = false) { if ($encoded) { $message = base64_decode($message, true); if ($message === false) { throw new Exception('Encryption failure'); } } $nonceSize = openssl_cipher_iv_length(self::METHOD); $nonce = mb_substr($message, 0, $nonceSize, '8bit'); $ciphertext = mb_substr($message, $nonceSize, null, '8bit'); $plaintext = openssl_decrypt( $ciphertext, self::METHOD, $key, OPENSSL_RAW_DATA, $nonce ); return $plaintext; } } $message = 'Ready your ammunition; we attack at dawn.'; $key = hex2bin('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'); $encrypted = UnsafeCrypto::encrypt($message, $key); $decrypted = UnsafeCrypto::decrypt($encrypted, $key); print_r($encrypted); //var_dump($encrypted, $decrypted);

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.0090.00618.31
8.3.50.0100.00716.35
8.3.40.0110.00418.83
8.3.30.0070.00718.83
8.3.20.0040.00422.09
8.3.10.0070.00023.48
8.3.00.0040.00422.02
8.2.180.0140.00718.04
8.2.170.0070.00722.96
8.2.160.0070.00719.05
8.2.150.0030.00624.18
8.2.140.0080.00024.66
8.2.130.0040.00421.04
8.2.120.0070.00726.35
8.2.110.0060.00620.95
8.2.100.0090.00317.78
8.2.90.0050.00319.08
8.2.80.0000.00817.97
8.2.70.0000.00917.50
8.2.60.0090.00017.80
8.2.50.0030.00618.10
8.2.40.0000.00720.64
8.2.30.0040.00421.03
8.2.20.0020.00518.04
8.2.10.0080.00018.05
8.2.00.0000.00818.13
8.1.280.0150.00025.92
8.1.270.0050.00322.31
8.1.260.0090.00026.35
8.1.250.0080.00028.09
8.1.240.0070.01023.98
8.1.230.0000.01219.20
8.1.220.0000.00917.91
8.1.210.0050.00518.77
8.1.200.0060.00317.48
8.1.190.0000.00817.36
8.1.180.0000.00818.10
8.1.170.0030.00618.65
8.1.160.0000.00719.06
8.1.150.0000.00920.66
8.1.140.0050.00319.58
8.1.130.0050.00318.93
8.1.120.0050.00217.39
8.1.110.0060.00317.32
8.1.100.0040.00417.42
8.1.90.0080.00017.48
8.1.80.0040.00417.46
8.1.70.0050.00317.51
8.1.60.0040.00417.64
8.1.50.0000.00817.58
8.1.40.0030.00517.51
8.1.30.0000.00817.63
8.1.20.0040.00417.68
8.1.10.0060.00317.63
8.1.00.0000.00717.55
8.0.300.0000.00818.77
8.0.290.0070.00016.75
8.0.280.0070.00018.45
8.0.270.0030.00317.13
8.0.260.0030.00316.87
8.0.250.0030.00316.99
8.0.240.0000.00817.07
8.0.230.0030.00316.88
8.0.220.0030.00316.86
8.0.210.0070.00016.84
8.0.200.0030.00316.93
8.0.190.0030.00616.89
8.0.180.0000.00716.87
8.0.170.0030.00316.96
8.0.160.0000.00716.91
8.0.150.0050.00216.82
8.0.140.0050.00216.91
8.0.130.0030.00313.34
8.0.120.0070.00016.94
8.0.110.0000.00816.97
8.0.100.0070.00016.86
8.0.90.0040.00416.98
8.0.80.0030.01817.00
8.0.70.0000.00717.04
8.0.60.0000.00816.86
8.0.50.0000.00716.83
8.0.30.0120.00617.06
8.0.20.0140.01117.44
8.0.10.0040.00416.95
8.0.00.0110.00616.96
7.4.330.0000.00515.55
7.4.320.0070.00016.46
7.4.300.0000.00616.46
7.4.290.0030.00516.56
7.4.280.0060.00316.65
7.4.270.0000.00716.49
7.4.260.0000.00613.29
7.4.250.0040.00416.54
7.4.240.0070.00016.52
7.4.230.0070.00016.41
7.4.220.0130.00616.69
7.4.210.0070.00716.77
7.4.200.0040.00416.64
7.4.160.0070.01016.62
7.4.150.0070.01017.40
7.4.140.0070.01317.86
7.4.130.0090.00916.51
7.4.120.0040.01516.55
7.4.110.0120.01216.55
7.4.100.0070.01116.39
7.4.90.0180.00016.40
7.4.80.0090.00919.39
7.4.70.0130.00316.63
7.4.60.0070.01316.56
7.4.50.0000.01716.72
7.4.40.0080.01216.52
7.4.30.0090.00916.43
7.4.00.0070.01115.13
7.3.330.0060.00013.42
7.3.320.0030.00313.49
7.3.310.0000.00716.43
7.3.300.0030.00316.27
7.3.290.0080.00616.38
7.3.280.0100.00716.39
7.3.270.0060.01217.40
7.3.260.0100.01016.46
7.3.250.0130.00716.49
7.3.240.0120.00716.50
7.3.230.0120.01416.43
7.3.210.0110.01116.30
7.3.200.0070.01616.29
7.3.190.0170.00316.49
7.3.180.0070.01016.36
7.3.170.0080.00816.36
7.3.160.0140.00616.57
7.3.120.0100.00714.98
7.3.110.0120.00414.79
7.3.100.0080.00814.79
7.3.90.0040.01414.63
7.3.80.0110.00314.91
7.3.70.0060.00914.94
7.3.60.0030.01314.87
7.3.50.0100.00315.02
7.3.40.0070.00714.95
7.3.30.0030.01014.48
7.3.20.0040.01216.61
7.3.10.0070.00716.74
7.3.00.0060.00916.49
7.2.330.0150.00316.48
7.2.320.0060.01116.73
7.2.310.0090.00616.38
7.2.300.0100.00716.42
7.2.290.0080.00816.69
7.2.250.0030.01615.02
7.2.240.0100.00714.89
7.2.230.0070.00715.20
7.2.220.0060.00914.71
7.2.210.0120.00615.05
7.2.200.0000.01114.96
7.2.190.0120.00315.02
7.2.180.0060.00614.88
7.2.170.0000.01014.96
7.2.60.0060.00916.38
7.2.00.0030.01019.39
7.1.330.0030.01415.65
7.1.320.0060.00615.88
7.1.310.0090.00615.79
7.1.300.0090.00615.84
7.1.290.0040.00815.53
7.1.280.0070.00715.76
7.1.270.0030.00715.50
7.1.260.0050.00515.50
7.1.100.0060.00618.51
7.1.70.0070.01017.43
7.1.60.0160.01735.23
7.1.50.0200.01735.12
7.1.40.0310.01734.71
7.1.30.0310.01834.93
7.1.20.0270.01034.82
7.1.10.0060.00916.77
7.1.00.0000.01616.89
7.0.200.0040.01116.92
7.0.190.0030.01216.69
7.0.180.0090.01316.25
7.0.170.0070.01416.52
7.0.160.0160.00616.38
7.0.150.0000.01416.43
7.0.140.0030.01316.52
7.0.130.0050.01016.52
7.0.120.0040.01116.52
7.0.110.0080.01116.57
7.0.100.0030.01316.43
7.0.90.0060.00916.48
7.0.80.0000.01516.66
7.0.70.0060.00916.60
7.0.60.0040.01116.15
7.0.50.0080.00816.45
7.0.40.0070.00716.72
7.0.30.0070.01016.55
7.0.20.0060.01316.66
7.0.10.0100.00316.53
7.0.00.0050.00816.72
5.6.300.0070.08220.84
5.6.290.0070.06021.00
5.6.280.0130.05720.93
5.6.270.0070.05820.91
5.6.260.0200.04421.15
5.6.250.0100.05620.92
5.6.240.0130.05821.08
5.6.230.0130.06021.06
5.6.220.0130.05020.87
5.6.210.0100.06421.11
5.6.200.0130.05621.14
5.6.190.0070.06021.15
5.6.180.0100.05421.14
5.6.170.0110.06020.86
5.6.160.0100.05821.00
5.6.150.0100.05820.90
5.6.140.0190.06121.13
5.6.130.0170.06020.84
5.6.120.0060.06421.19
5.6.110.0070.05920.90
5.6.100.0000.07321.18
5.6.90.0100.06320.89
5.6.80.0090.06120.47
5.6.70.0070.06920.41
5.6.60.0100.06120.41
5.6.50.0090.06020.58
5.6.40.0130.07020.25
5.6.30.0000.06420.52
5.6.20.0100.05720.24
5.6.10.0130.06020.22
5.6.00.0170.04620.37
5.5.380.0130.05417.58
5.5.370.0120.05717.63
5.5.360.0160.05617.64
5.5.350.0160.04917.49
5.5.340.0120.06018.09
5.5.330.0100.05618.18
5.5.320.0160.04718.10
5.5.310.0070.06018.09
5.5.300.0070.05717.93
5.5.290.0100.05618.16
5.5.280.0130.05218.09
5.5.270.0070.05818.14
5.5.260.0070.06118.18
5.5.250.0070.05718.04
5.5.240.0100.07217.28
5.5.230.0100.05317.54
5.5.220.0030.05817.52
5.5.210.0100.05317.53
5.5.200.0030.05717.57
5.5.190.0130.05017.53
5.5.180.0030.06117.46
5.5.160.0070.05917.50
5.5.150.0100.06917.24
5.5.140.0160.05117.25
5.5.130.0060.05917.52
5.5.120.0190.04117.49
5.5.110.0030.05817.48
5.5.100.0100.05217.42
5.5.90.0100.04917.31
5.5.80.0060.05517.18
5.5.70.0070.05417.15
5.5.60.0200.03917.17
5.5.50.0100.04917.50
5.5.40.0060.05517.34
5.5.30.0100.04917.16
5.5.20.0100.05917.41
5.5.10.0070.05517.30
5.5.00.0060.05517.47
5.4.450.0130.05219.52
5.4.440.0030.06219.55
5.4.430.0070.05819.52
5.4.420.0130.05119.37
5.4.410.0070.05419.39
5.4.400.0060.07419.29
5.4.390.0030.06419.08
5.4.380.0200.03919.06
5.4.370.0100.05419.24
5.4.360.0130.05619.07
5.4.350.0100.04919.36
5.4.340.0130.05919.09
5.4.320.0070.05619.05
5.4.310.0060.05719.36
5.4.300.0060.05819.04
5.4.290.0190.05419.06
5.4.280.0070.05719.19
5.4.270.0110.04919.05
5.4.260.0100.05019.36
5.4.250.0130.04719.05
5.4.240.0100.05519.33
5.4.230.0070.05319.09
5.4.220.0200.04219.27
5.4.210.0100.06019.07
5.4.200.0170.04319.19
5.4.190.0100.06319.04
5.4.180.0060.05319.28
5.4.170.0100.06719.08
5.4.160.0070.05619.16
5.4.150.0030.05819.03
5.4.140.0060.05516.52
5.4.130.0140.04116.58
5.4.120.0070.05216.38
5.4.110.0030.05416.64
5.4.100.0130.04916.51
5.4.90.0100.04416.57
5.4.80.0130.04316.52
5.4.70.0070.05016.63
5.4.60.0100.04616.64
5.4.50.0070.04716.68
5.4.40.0100.04416.71
5.4.30.0100.04516.68
5.4.20.0190.04216.65
5.4.10.0100.06916.51
5.4.00.0130.04616.15
5.3.290.0170.04314.73
5.3.280.0220.03514.87
5.3.270.0030.05814.91
5.3.260.0160.04214.80
5.3.250.0090.04714.68
5.3.240.0030.05914.67
5.3.230.0090.05614.82
5.3.220.0070.06014.63
5.3.210.0060.05214.86
5.3.200.0070.05014.64
5.3.190.0160.04114.86
5.3.180.0110.04514.69
5.3.170.0070.04814.86
5.3.160.0060.04814.63
5.3.150.0070.05514.75
5.3.140.0100.04914.75
5.3.130.0060.05514.62
5.3.120.0070.05214.74
5.3.110.0000.06614.82
5.3.100.0160.05514.34
5.3.90.0100.06314.08
5.3.80.0150.05014.33
5.3.70.0100.06214.24
5.3.60.0130.06014.29
5.3.50.0170.04314.24
5.3.40.0060.06414.16
5.3.30.0070.04814.22
5.3.20.0200.03614.00
5.3.10.0130.05513.70
5.3.00.0030.06513.64
5.2.170.0090.04311.46
5.2.160.0060.04211.04
5.2.150.0130.04511.37
5.2.140.0170.03811.15
5.2.130.0130.04311.17
5.2.120.0030.04711.38
5.2.110.0100.03711.24
5.2.100.0100.04511.17
5.2.90.0030.04411.08
5.2.80.0100.03811.28
5.2.70.0100.03611.32
5.2.60.0030.04511.18
5.2.50.0090.04711.03
5.2.40.0130.04611.22
5.2.30.0150.04510.98
5.2.20.0100.05211.16
5.2.10.0070.04410.75
5.2.00.0000.05811.04
5.1.60.0130.03810.23
5.1.50.0110.03910.31
5.1.40.0030.04710.25
5.1.30.0150.04210.65
5.1.20.0030.05110.54
5.1.10.0130.03910.38
5.1.00.0140.03910.37
5.0.50.0030.0328.67
5.0.40.0090.0258.55
5.0.30.0060.0428.48
5.0.20.0000.0398.43
5.0.10.0060.0358.22
5.0.00.0100.0458.39
4.4.90.0030.0236.69
4.4.80.0030.0236.69
4.4.70.0030.0316.69
4.4.60.0100.0166.69
4.4.50.0160.0136.69
4.4.40.0070.0376.69
4.4.30.0100.0226.69
4.4.20.0040.0296.69
4.4.10.0000.0336.69
4.4.00.0030.0346.69
4.3.110.0060.0256.69
4.3.100.0030.0246.69
4.3.90.0090.0216.69
4.3.80.0040.0366.69
4.3.70.0090.0236.69
4.3.60.0070.0256.69
4.3.50.0130.0176.69
4.3.40.0060.0316.69
4.3.30.0030.0246.69
4.3.20.0090.0186.69
4.3.10.0060.0226.69
4.3.00.0100.0196.69

preferences:
54.96 ms | 401 KiB | 5 Q