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, true); $decrypted = UnsafeCrypto::decrypt($encrypted, $key, true); 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.4.20.0080.00017.89
8.4.10.0090.01217.63
8.3.150.0120.00617.36
8.3.140.0090.00917.06
8.3.130.0040.00419.15
8.3.120.0090.00018.88
8.3.110.0130.00718.12
8.3.100.0150.00616.67
8.3.90.0140.00221.65
8.3.80.0230.00216.69
8.3.70.0170.00516.69
8.3.60.0230.00520.23
8.3.50.0160.00519.51
8.3.40.0110.00618.04
8.3.30.0120.00619.64
8.3.20.0100.00620.54
8.3.10.0140.00221.94
8.3.00.0060.00920.40
8.2.260.0040.00418.63
8.2.250.0040.00418.71
8.2.240.0060.00317.06
8.2.230.0080.00419.42
8.2.220.0050.00719.97
8.2.210.0070.00521.66
8.2.200.0100.00316.69
8.2.190.0110.00516.69
8.2.180.0060.01017.50
8.2.170.0120.00720.36
8.2.160.0120.00620.10
8.2.150.0120.00321.51
8.2.140.0100.00621.98
8.2.130.0080.00822.32
8.2.120.0100.00720.75
8.2.110.0090.00821.33
8.2.100.0100.00720.46
8.2.90.0120.00819.90
8.2.80.0120.00720.10
8.2.70.0100.00719.30
8.2.60.0100.00619.50
8.2.50.0110.00419.71
8.2.40.0080.00619.55
8.2.30.0090.00619.44
8.2.20.0080.00819.36
8.2.10.0110.00519.16
8.2.00.0110.00519.21
8.1.310.0130.00616.66
8.1.300.0130.00917.29
8.1.290.0140.00820.34
8.1.280.0100.00920.95
8.1.270.0080.00522.32
8.1.260.0100.00623.17
8.1.250.0100.00423.19
8.1.240.0090.00420.41
8.1.230.0080.00520.22
8.1.220.0060.00619.76
8.1.210.0080.00520.43
8.1.200.0090.00819.68
8.1.190.0090.00419.22
8.1.180.0090.00519.87
8.1.170.0100.00619.60
8.1.160.0110.00519.63
8.1.150.0090.00519.56
8.1.140.0080.00619.05
8.1.130.0110.00518.88
8.1.120.0100.00518.88
8.1.110.0090.00518.75
8.1.100.0080.00518.62
8.1.90.0080.00618.46
8.1.80.0110.00418.52
8.1.70.0100.00618.55
8.1.60.0090.00718.53
8.1.50.0100.00718.63
8.1.40.0120.00618.49
8.1.30.0110.00618.61
8.1.20.0130.00518.60
8.1.10.0120.00518.32
8.1.00.0110.00518.37
8.0.300.0070.00619.73
8.0.290.0110.00419.26
8.0.280.0120.00418.94
8.0.270.0110.00318.77
8.0.260.0070.00618.54
8.0.250.0100.00418.46
8.0.240.0100.00618.33
8.0.230.0110.00518.05
8.0.220.0120.00418.14
8.0.210.0120.00517.96
8.0.200.0110.00518.09
8.0.190.0100.00518.22
8.0.180.0110.00518.17
8.0.170.0110.00418.06
8.0.160.0100.00618.05
8.0.150.0120.00517.90
8.0.140.0100.00617.74
8.0.130.0100.00617.64
8.0.120.0090.00517.27
8.0.110.0100.00517.63
8.0.100.0100.00417.46
8.0.90.0110.00517.49
8.0.80.0120.00417.47
8.0.70.0100.00617.43
8.0.60.0110.00517.49
8.0.50.0130.00517.47
8.0.30.0100.00617.42
8.0.20.0110.00617.47
8.0.10.0120.00617.52
8.0.00.0100.00717.58
7.4.330.0100.00423.34
7.4.320.0130.00618.04
7.4.300.0120.00517.93
7.4.290.0130.00617.89
7.4.280.0140.00517.62
7.4.270.0130.00417.45
7.4.260.0150.00417.47
7.4.250.0120.00516.95
7.4.240.0110.00617.23
7.4.230.0130.00417.17
7.4.220.0110.00517.32
7.4.210.0120.00617.25
7.4.200.0140.00417.27
7.4.190.0100.00517.25
7.4.180.0120.00517.28
7.4.160.0110.00517.24
7.4.150.0110.00517.19
7.4.140.0110.00617.14
7.4.130.0130.00616.93
7.4.120.0120.00616.96
7.4.110.0130.00716.93
7.4.100.0120.00716.95
7.4.90.0140.00716.86
7.4.80.0140.00716.94
7.4.70.0130.00716.84
7.4.60.0140.00816.85
7.4.50.0140.00716.79
7.4.40.0140.00716.76
7.4.30.0130.00816.81
7.4.20.0130.00716.82
7.4.10.0130.00816.77
7.4.00.0120.00716.69
7.3.330.0120.00421.48
7.3.320.0130.00616.99
7.3.310.0140.00517.13
7.3.300.0140.00517.14
7.3.290.0150.00517.12
7.3.280.0120.00716.88
7.3.270.0140.00516.98
7.3.260.0130.00716.95
7.3.250.0140.00616.90
7.3.240.0130.00616.90
7.3.230.0140.00616.82
7.3.220.0160.00616.78
7.3.210.0160.00616.76
7.3.200.0150.00616.77
7.3.190.0150.00716.74
7.3.180.0130.00816.70
7.3.170.0150.00716.73
7.3.160.0140.00716.69
7.3.150.0140.00716.71
7.3.140.0130.00816.72
7.3.130.0130.00716.65
7.3.120.0140.00716.55
7.3.110.0130.00716.48
7.3.100.0130.00716.47
7.3.90.0130.00716.60
7.3.80.0130.00716.38
7.3.70.0130.00816.27
7.3.60.0130.00716.28
7.3.50.0120.00716.24
7.3.40.0120.00816.21
7.3.30.0120.00716.17
7.3.20.0230.00716.55
7.3.10.0320.00716.47
7.3.00.0210.00716.51
7.2.340.0150.00616.85
7.2.330.0150.00716.80
7.2.320.0160.00716.82
7.2.310.0140.00816.76
7.2.300.0150.00716.75
7.2.290.0140.00816.75
7.2.280.0160.00616.76
7.2.270.0160.00716.76
7.2.260.0130.00816.71
7.2.250.0130.00816.66
7.2.240.0150.00716.59
7.2.230.0150.00816.58
7.2.220.0140.00916.56
7.2.210.0140.00816.47
7.2.200.0140.00916.42
7.2.190.0130.00916.38
7.2.180.0140.00816.35
7.2.170.0130.00716.34
7.2.160.0130.00816.28
7.2.150.0270.00716.75
7.2.140.0290.00816.73
7.2.130.0220.00816.76
7.2.120.0320.00716.74
7.2.110.0340.00716.75
7.2.100.0270.00816.74
7.2.90.0230.00816.73
7.2.80.0240.00816.72
7.2.70.0250.00816.72
7.2.60.0240.00816.71
7.2.50.0230.00716.70
7.2.40.0230.00816.72
7.2.30.0210.00816.75
7.2.20.0220.00716.73
7.2.10.0200.00816.73
7.2.00.0220.00716.74
7.1.330.0180.00816.27
7.1.320.0170.00816.20
7.1.310.0180.00616.07
7.1.300.0180.00815.96
7.1.290.0170.00715.97
7.1.280.0200.00715.94
7.1.270.0200.00715.88
7.1.260.0180.00715.88
7.1.250.0230.00715.71
7.1.240.0370.00715.74
7.1.230.0330.00715.81
7.1.220.0330.00715.75
7.1.210.0290.00815.73
7.1.200.0290.00815.74
7.1.190.0240.00715.79
7.1.180.0250.00715.71
7.1.170.0260.00715.74
7.1.160.0260.00715.71
7.1.150.0260.00815.73
7.1.140.0240.00815.70
7.1.130.0230.00715.70
7.1.120.0220.00715.69
7.1.110.0250.00715.74
7.1.100.0270.00815.73
7.1.90.0220.00815.72
7.1.80.0210.00815.75
7.1.70.0220.00715.70
7.1.60.0210.00715.97
7.1.50.0240.00815.98
7.1.40.0230.00715.94
7.1.30.0210.00815.98
7.1.20.0210.00715.96
7.1.10.0220.00715.72
7.1.00.0200.00815.69
7.0.330.0370.00715.56
7.0.320.0260.00715.47
7.0.310.0270.00715.41
7.0.300.0250.00715.40
7.0.290.0250.00715.42
7.0.280.0250.00715.47
7.0.270.0240.00715.42
7.0.260.0220.00715.40
7.0.250.0240.00715.49
7.0.240.0220.00715.48
7.0.230.0250.00715.49
7.0.220.0230.00715.48
7.0.210.0220.00815.49
7.0.200.0260.00715.45
7.0.190.0220.00815.45
7.0.180.0210.00815.45
7.0.170.0210.00715.50
7.0.160.0230.00715.47
7.0.150.0250.00715.41
7.0.140.0240.00715.43
7.0.130.0210.00815.45
7.0.120.0220.00815.46
7.0.110.0200.00715.43
7.0.100.0210.00715.42
7.0.90.0210.00715.40
7.0.80.0210.00715.39
7.0.70.0210.00715.39
7.0.60.0210.00715.42
7.0.50.0190.00815.40
7.0.40.0210.00715.42
7.0.30.0190.00715.40
7.0.20.0210.00715.34
7.0.10.0220.00715.41
7.0.00.0190.00815.40
5.6.400.0150.00815.69
5.6.390.0150.00915.70
5.6.380.0150.00915.58
5.6.370.0150.00915.54
5.6.360.0140.00915.55
5.6.350.0140.00815.54
5.6.340.0140.00815.56
5.6.330.0140.00815.57
5.6.320.0140.00915.53
5.6.310.0150.00815.56
5.6.300.0150.00815.50
5.6.290.0140.00815.56
5.6.280.0140.00815.55
5.6.270.0140.00815.55
5.6.260.0140.00915.55
5.6.250.0150.00815.51
5.6.240.0140.00915.57
5.6.230.0140.00915.55
5.6.220.0140.00915.50
5.6.210.0150.00815.54
5.6.200.0140.00815.54
5.6.190.0140.00915.55
5.6.180.0140.00815.53
5.6.170.0140.00915.58
5.6.160.0140.00915.58
5.6.150.0140.00815.56
5.6.140.0150.00715.56
5.6.130.0150.00815.55
5.6.120.0140.00815.56
5.6.110.0140.00815.50
5.6.100.0130.00915.52
5.6.90.0140.00815.53
5.6.80.0140.00815.48
5.6.70.0130.00815.48
5.6.60.0130.00815.50
5.6.50.0130.00815.44
5.6.40.0130.00815.48
5.6.30.0140.00815.46
5.6.20.0140.00815.44
5.6.10.0130.00915.43
5.6.00.0140.00715.45
5.5.380.0140.00915.24
5.5.370.0140.00815.24
5.5.360.0140.00815.20
5.5.350.0140.00815.18
5.5.340.0140.00815.20
5.5.330.0140.00815.20
5.5.320.0150.00715.19
5.5.310.0150.00815.21
5.5.300.0140.00815.17
5.5.290.0150.00815.18
5.5.280.0150.00815.13
5.5.270.0140.00815.13
5.5.260.0150.00815.14
5.5.250.0150.00715.11
5.5.240.0150.00815.13
5.5.230.0140.00815.11
5.5.220.0130.00815.13
5.5.210.0140.00815.13
5.5.200.0140.00815.08
5.5.190.0140.00815.09
5.5.180.0150.00815.10
5.5.170.0130.00815.15
5.5.160.0140.00815.08
5.5.150.0130.00915.11
5.5.140.0140.00815.05
5.5.130.0140.00815.05
5.5.120.0130.00815.08
5.5.110.0140.00815.11
5.5.100.0140.00815.11
5.5.90.0140.00815.09
5.5.80.0140.00815.12
5.5.70.0150.00815.14
5.5.60.0130.00915.10
5.5.50.0140.00815.13
5.5.40.0140.00815.13
5.5.30.0140.00715.10
5.5.20.0130.00815.11
5.5.10.0140.00715.09
5.5.00.0130.00815.10
5.4.450.0120.00512.90
5.4.440.0110.00612.89
5.4.430.0120.00512.89
5.4.420.0120.00612.89
5.4.410.0110.00612.90
5.4.400.0120.00612.85
5.4.390.0120.00612.84
5.4.380.0110.00612.86
5.4.370.0120.00512.82
5.4.360.0120.00512.86
5.4.350.0110.00612.85
5.4.340.0110.00612.84
5.4.330.0110.00612.85
5.4.320.0110.00512.87
5.4.310.0110.00612.86
5.4.300.0120.00512.87
5.4.290.0110.00612.85
5.4.280.0110.00612.85
5.4.270.0110.00612.86
5.4.260.0110.00612.84
5.4.250.0120.00612.82
5.4.240.0110.00612.83
5.4.230.0110.00612.81
5.4.220.0110.00612.79
5.4.210.0120.00512.79
5.4.200.0110.00612.79
5.4.190.0110.00612.77
5.4.180.0120.00612.79
5.4.170.0110.00612.79
5.4.160.0120.00612.83
5.4.150.0110.00612.83
5.4.140.0110.00612.88
5.4.130.0110.00612.83
5.4.120.0110.00612.85
5.4.110.0110.00612.87
5.4.100.0110.00612.86
5.4.90.0100.00612.87
5.4.80.0110.00612.86
5.4.70.0110.00612.88
5.4.60.0110.00512.87
5.4.50.0110.00512.86
5.4.40.0100.00612.87
5.4.30.0110.00512.88
5.4.20.0100.00612.88
5.4.10.0100.00612.87
5.4.00.0100.00612.82

preferences:
57.2 ms | 403 KiB | 5 Q