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($ivSize); $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); 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.70.0120.00918.43
8.3.60.0120.00318.68
8.3.50.0090.01321.19
8.3.40.0110.00718.91
8.3.30.0070.01118.72
8.3.20.0040.00420.21
8.3.10.0070.00021.82
8.3.00.0000.00817.80
8.2.190.0100.00718.19
8.2.180.0070.01016.86
8.2.170.0090.00622.96
8.2.160.0120.00320.57
8.2.150.0000.00825.66
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0060.00317.37
8.2.110.0120.00922.20
8.2.100.0080.00417.84
8.2.90.0040.00422.15
8.2.80.0050.00317.97
8.2.70.0080.00017.91
8.2.60.0080.00017.80
8.2.50.0060.00318.10
8.2.40.0030.00519.41
8.2.30.0000.00720.80
8.2.20.0000.00817.74
8.2.10.0030.00518.01
8.2.00.0040.00418.19
8.1.280.0060.01225.92
8.1.270.0050.00324.66
8.1.260.0080.00326.35
8.1.250.0040.00428.09
8.1.240.0000.01022.42
8.1.230.0110.00021.17
8.1.220.0040.00417.91
8.1.210.0000.00819.07
8.1.200.0050.00317.35
8.1.190.0000.00817.36
8.1.180.0080.00018.10
8.1.170.0000.00818.67
8.1.160.0000.00722.00
8.1.150.0000.00718.87
8.1.140.0060.00317.37
8.1.130.0000.00717.64
8.1.120.0040.00417.48
8.1.110.0030.00617.35
8.1.100.0000.00717.39
8.1.90.0090.00017.47
8.1.80.0040.00417.47
8.1.70.0000.00717.52
8.1.60.0000.00817.66
8.1.50.0000.00917.62
8.1.40.0090.00017.51
8.1.30.0000.00817.56
8.1.20.0000.00717.74
8.1.10.0000.00817.54
8.1.00.0040.00417.46
8.0.300.0040.00420.17
8.0.290.0050.00316.88
8.0.280.0070.00018.49
8.0.270.0030.00317.26
8.0.260.0080.00017.26
8.0.250.0040.00417.04
8.0.240.0030.00317.02
8.0.230.0070.00016.94
8.0.220.0030.00316.89
8.0.210.0000.00716.93
8.0.200.0000.00717.03
8.0.190.0030.00517.02
8.0.180.0040.00417.00
8.0.170.0000.00817.00
8.0.160.0040.00416.99
8.0.150.0080.00016.99
8.0.140.0070.00016.82
8.0.130.0060.00313.40
8.0.120.0060.00316.81
8.0.110.0040.00416.91
8.0.100.0000.00716.98
8.0.90.0000.00716.76
8.0.80.0090.00616.84
8.0.70.0060.00316.86
8.0.60.0040.00417.02
8.0.50.0040.00416.96
8.0.30.0100.01017.16
8.0.20.0120.00917.34
8.0.10.0110.01017.30
8.0.00.0120.00917.03
7.4.330.0050.00015.08
7.4.320.0070.00016.60
7.4.300.0040.00416.67
7.4.290.0070.00016.61
7.4.280.0000.01016.53
7.4.270.0000.00716.56
7.4.260.0000.00816.46
7.4.250.0060.00316.46
7.4.240.0040.00316.59
7.4.230.0000.00716.41
7.4.220.0060.01216.71
7.4.210.0070.01016.61
7.4.200.0030.00316.65
7.4.160.0060.01016.63
7.4.150.0080.00917.22
7.4.140.0150.00817.40
7.4.130.0130.00916.92
7.4.120.0100.00816.90
7.4.110.0110.00816.90
7.4.100.0120.00816.85
7.4.90.0110.00816.76
7.4.80.0090.01117.23
7.4.70.0120.00816.79
7.4.60.0100.00916.74
7.4.50.0100.00816.71
7.4.40.0110.00816.80
7.4.30.0120.00916.70
7.4.20.0100.01016.76
7.4.10.0140.00716.57
7.4.00.0110.00716.45
7.3.330.0000.00513.39
7.3.320.0050.00013.37
7.3.310.0030.00316.28
7.3.300.0030.00316.38
7.3.290.0080.00716.38
7.3.280.0070.01016.38
7.3.270.0100.01017.17
7.3.260.0080.01116.89
7.3.250.0120.00916.82
7.3.240.0060.01216.92
7.3.230.0100.00716.96
7.3.220.0110.00916.74
7.3.210.0090.01016.77
7.3.200.0080.01116.73
7.3.190.0120.00816.75
7.3.180.0100.00816.63
7.3.170.0070.01316.75
7.3.160.0080.01416.70
7.3.150.0120.00916.74
7.3.140.0110.00916.72
7.3.130.0060.01416.51
7.3.120.0090.01016.37
7.3.110.0080.01116.39
7.3.100.0070.01216.40
7.3.90.0110.00816.45
7.3.80.0100.00816.45
7.3.70.0100.00916.40
7.3.60.0090.00916.41
7.3.50.0110.00616.48
7.3.40.0110.00716.41
7.3.30.0100.00716.46
7.3.20.0090.01016.64
7.3.10.0110.00716.64
7.3.00.0100.00916.65
7.2.340.0180.01117.04
7.2.330.0150.00916.79
7.2.320.0140.01016.78
7.2.310.0120.01216.76
7.2.300.0130.00916.84
7.2.290.0170.00716.69
7.2.280.0140.00916.82
7.2.270.0130.01116.78
7.2.260.0130.00916.54
7.2.250.0130.01016.57
7.2.240.0130.00816.54
7.2.230.0120.01116.57
7.2.220.0110.01216.52
7.2.210.0110.01116.54
7.2.200.0120.00916.56
7.2.190.0110.01016.48
7.2.180.0110.01016.50
7.2.170.0110.00916.53
7.2.160.0120.01116.53
7.2.150.0120.01116.89
7.2.140.0120.01016.78
7.2.130.0120.01116.82
7.2.120.0120.01216.82
7.2.110.0150.01016.83
7.2.100.0180.00916.84
7.2.90.0120.01116.87
7.2.80.0170.00816.80
7.2.70.0150.00816.82
7.2.60.0160.00816.85
7.2.50.0200.00816.79
7.2.40.0150.00816.85
7.2.30.0150.01016.85
7.2.20.0170.01016.78
7.2.10.0190.00616.84
7.2.00.0140.01217.05
7.1.330.0170.01015.94
7.1.320.0200.00916.04
7.1.310.0170.00916.04
7.1.300.0180.00816.03
7.1.290.0190.01016.02
7.1.280.0150.01216.04
7.1.270.0220.00716.00
7.1.260.0160.00915.97
7.1.250.0200.00915.98
7.1.240.0200.00815.99
7.1.230.0190.00816.01
7.1.220.0180.00816.00
7.1.210.0170.00916.00
7.1.200.0160.00815.99
7.1.190.0110.01315.99
7.1.180.0160.00715.97
7.1.170.0140.01015.95
7.1.160.0180.00815.95
7.1.150.0190.01116.02
7.1.140.0160.01216.01
7.1.130.0140.00915.97
7.1.120.0140.01015.99
7.1.110.0210.00915.98
7.1.100.0190.00916.03
7.1.90.0170.01115.98
7.1.80.0210.00716.07
7.1.70.0150.00716.14
7.1.60.0140.00916.16
7.1.50.0170.00916.13
7.1.40.0170.00816.31
7.1.30.0160.00916.30
7.1.20.0130.01116.33
7.1.10.0190.00816.23
7.1.00.0170.00716.28
7.0.330.0150.00915.73
7.0.320.0200.00715.79
7.0.310.0160.01015.76
7.0.300.0230.00915.73
7.0.290.0180.00715.73
7.0.280.0150.01015.74
7.0.270.0140.00815.80
7.0.260.0190.00915.76
7.0.250.0190.00815.80
7.0.240.0270.00815.85
7.0.230.0160.00715.79
7.0.220.0140.00915.84
7.0.210.0150.00815.78
7.0.200.0110.01015.94
7.0.190.0160.00916.11
7.0.180.0140.00916.08
7.0.170.0140.00916.13
7.0.160.0190.00816.06
7.0.150.0160.01016.11
7.0.140.0170.00616.05
7.0.130.0110.01116.11
7.0.120.0170.00815.91
7.0.110.0180.00815.91
7.0.100.0400.00715.87
7.0.90.0190.01015.88
7.0.80.0160.00715.83
7.0.70.0180.00816.00
7.0.60.0160.00816.10
7.0.50.0130.01216.06
7.0.40.0140.00915.81
7.0.30.0170.00715.79
7.0.20.0150.00815.79
7.0.10.0150.00915.83
7.0.00.0150.00815.81
5.6.400.0140.01316.01
5.6.390.0180.01216.05
5.6.380.0170.01016.01
5.6.370.0130.01115.95
5.6.360.0150.01016.02
5.6.350.0150.01216.04
5.6.340.0200.01016.03
5.6.330.0120.01216.00
5.6.320.0140.01215.99
5.6.310.0160.01016.04
5.6.300.0150.01616.63
5.6.290.0140.01416.57
5.6.280.0140.01516.66
5.6.270.0140.01416.57
5.6.260.0150.01316.65
5.6.250.0220.01316.58
5.6.240.0180.01516.56
5.6.230.0150.01816.63
5.6.220.0160.01316.56
5.6.210.0150.01416.48
5.6.200.0140.02016.61
5.6.190.0130.01516.54
5.6.180.0150.01616.55
5.6.170.0160.01316.54
5.6.160.0150.01416.61
5.6.150.0190.01316.60
5.6.140.0170.01316.55
5.6.130.0150.01816.55
5.6.120.0180.01716.55
5.6.110.0190.01016.59
5.6.100.0160.01416.53
5.6.90.0170.01316.55
5.6.80.0150.01516.47
5.6.70.0140.01716.46
5.6.60.0170.01316.50
5.6.50.0170.01716.49
5.6.40.0190.01516.51
5.6.30.0180.01616.44
5.6.20.0130.01516.44
5.6.10.0170.01616.44
5.6.00.0150.01516.39
5.5.380.0160.01416.41
5.5.370.0160.01716.37
5.5.360.0140.02016.40
5.5.350.0150.01916.36
5.5.340.0170.01416.47
5.5.330.0150.01716.44
5.5.320.0170.01816.42
5.5.310.0150.01616.40
5.5.300.0160.01716.42
5.5.290.0180.01316.45
5.5.280.0160.01816.46
5.5.270.0180.02016.41
5.5.260.0160.01716.39
5.5.250.0180.01316.40
5.5.240.0130.01616.37
5.5.230.0200.01516.33
5.5.220.0190.01416.40
5.5.210.0170.01516.38
5.5.200.0160.01516.36
5.5.190.0180.01416.35
5.5.180.0180.01616.30
5.5.170.0180.01216.23
5.5.160.0160.01916.38
5.5.150.0170.01516.36
5.5.140.0200.01516.32
5.5.130.0190.01416.32
5.5.120.0160.01616.35
5.5.110.0140.01816.30
5.5.100.0180.01216.35
5.5.90.0160.01316.35
5.5.80.0160.01616.33
5.5.70.0180.01416.33
5.5.60.0160.01516.29
5.5.50.0170.01516.33
5.5.40.0180.01316.31
5.5.30.0170.01516.29
5.5.20.0190.01416.32
5.5.10.0180.01316.26
5.5.00.0150.01416.23
5.4.450.0150.01114.89
5.4.440.0150.01614.87
5.4.430.0130.01214.85
5.4.420.0130.01314.87
5.4.410.0130.01114.87
5.4.400.0140.01014.77
5.4.390.0120.01314.81
5.4.380.0130.01214.79
5.4.370.0130.01214.82
5.4.360.0160.01614.78
5.4.350.0130.01314.80
5.4.340.0140.01114.77
5.4.330.0130.01114.16
5.4.320.0150.01114.75
5.4.310.0130.01314.82
5.4.300.0120.01414.82
5.4.290.0130.01214.80
5.4.280.0160.01214.78
5.4.270.0160.00914.84
5.4.260.0130.01314.79
5.4.250.0140.01214.83
5.4.240.0130.01214.80
5.4.230.0140.01014.78
5.4.220.0140.01414.78
5.4.210.0170.00914.79
5.4.200.0120.01514.75
5.4.190.0120.01814.79
5.4.180.0120.01314.74
5.4.170.0140.01114.73
5.4.160.0130.01114.77
5.4.150.0140.01114.73
5.4.140.0120.01314.51
5.4.130.0140.01314.43
5.4.120.0100.01414.48
5.4.110.0140.00914.47
5.4.100.0130.01314.47
5.4.90.0110.01414.47
5.4.80.0110.01214.53
5.4.70.0110.01314.46
5.4.60.0140.01314.44
5.4.50.0120.01114.46
5.4.40.0080.01414.51
5.4.30.0110.01314.50
5.4.20.0120.01114.46
5.4.10.0130.01014.45
5.4.00.0120.01314.43
5.3.290.0150.01314.61
5.3.280.0140.01214.54
5.3.270.0150.01314.62
5.3.260.0150.01114.62
5.3.250.0130.01114.58
5.3.240.0140.01414.57
5.3.230.0120.01714.59
5.3.220.0120.01314.57
5.3.210.0140.01314.57
5.3.200.0110.01414.56
5.3.190.0110.01414.63
5.3.180.0130.01214.63
5.3.170.0140.01314.64
5.3.160.0140.01214.61
5.3.150.0110.01414.65
5.3.140.0110.01414.63
5.3.130.0140.01214.61
5.3.120.0150.01814.60
5.3.110.0120.01414.62
5.3.100.0130.01314.60
5.3.90.0120.01314.64
5.3.80.0160.01014.60
5.3.70.0130.01214.58
5.3.60.0090.01614.64
5.3.50.0120.01314.58
5.3.40.0120.01114.59
5.3.30.0120.01214.57
5.3.20.0140.01214.57
5.3.10.0120.01214.47
5.3.00.0110.01214.49
5.2.170.0110.01114.22
5.2.160.0100.01014.29
5.2.150.0100.01114.23
5.2.140.0090.01214.25
5.2.130.0100.01014.22
5.2.120.0110.01114.24
5.2.110.0120.01014.16
5.2.100.0120.00814.19
5.2.90.0080.01214.17
5.2.80.0110.01014.18
5.2.70.0120.01114.18
5.2.60.0090.01014.15
5.2.50.0120.01014.19
5.2.40.0110.01014.23
5.2.30.0100.01214.25
5.2.20.0120.00814.14
5.2.10.0120.01314.11
5.2.00.0100.01114.11
5.1.60.0110.00713.88
5.1.50.0100.00813.87
5.1.40.0090.01013.89
5.1.30.0070.01213.96
5.1.20.0100.00813.89
5.1.10.0090.00913.92
5.1.00.0100.01413.87
5.0.50.0100.00613.79
5.0.40.0090.01213.78
5.0.30.0080.00913.76
5.0.20.0100.00913.76
5.0.10.0110.00813.76
5.0.00.0090.00913.76
4.4.90.0060.00613.76
4.4.80.0070.00613.76
4.4.70.0060.00713.76
4.4.60.0060.00613.76
4.4.50.0070.00313.76
4.4.40.0060.00613.76
4.4.30.0060.00513.76
4.4.20.0070.00513.76
4.4.10.0060.00613.76
4.4.00.0070.00713.76
4.3.110.0070.00613.76
4.3.100.0050.00413.76
4.3.90.0050.00413.76
4.3.80.0060.00513.76
4.3.70.0060.00513.76
4.3.60.0060.00513.76
4.3.50.0050.00613.76
4.3.40.0070.00513.76
4.3.30.0040.00513.76
4.3.20.0030.00613.76
4.3.10.0060.00413.76
4.3.00.0060.00413.76

preferences:
49.27 ms | 401 KiB | 5 Q