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); 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.0070.01117.00
8.3.60.0130.01124.05
8.3.50.0070.01222.63
8.3.40.0160.00720.81
8.3.30.0130.01021.12
8.3.20.0140.00823.03
8.3.10.0120.00723.49
8.3.00.0130.00622.46
8.2.180.0170.00625.92
8.2.170.0150.00821.36
8.2.160.0150.01123.04
8.2.150.0190.00323.58
8.2.140.0140.00723.26
8.2.130.0110.00826.19
8.2.120.0130.00422.72
8.2.110.0100.00722.69
8.2.100.0180.00521.33
8.2.90.0170.00720.74
8.2.80.0170.00520.94
8.2.70.0110.00624.45
8.2.60.0120.00724.29
8.2.50.0130.00624.21
8.2.40.0100.00723.44
8.2.30.0110.00522.35
8.2.20.0100.00521.59
8.2.10.0100.00621.55
8.2.00.0110.00521.38
8.1.280.0090.00825.92
8.1.270.0140.00423.94
8.1.260.0120.00824.89
8.1.250.0120.00725.22
8.1.240.0130.00422.65
8.1.230.0110.00621.75
8.1.220.0130.00520.41
8.1.210.0150.00420.85
8.1.200.0130.00525.52
8.1.190.0150.00425.32
8.1.180.0120.00625.50
8.1.170.0120.00723.53
8.1.160.0110.00622.94
8.1.150.0120.00522.95
8.1.140.0120.00422.28
8.1.130.0110.00520.61
8.1.120.0120.00520.69
8.1.110.0120.00520.22
8.1.100.0110.00620.55
8.1.90.0110.00519.86
8.1.80.0110.00519.86
8.1.70.0110.00519.57
8.1.60.0120.00519.82
8.1.50.0120.00519.46
8.1.40.0120.00519.28
8.1.30.0120.00419.04
8.1.20.0100.00618.89
8.1.10.0110.00619.04
8.1.00.0130.00519.02
8.0.300.0170.00520.18
8.0.290.0140.00330.92
8.0.280.0130.00522.62
8.0.270.0120.00521.91
8.0.260.0110.00420.81
8.0.250.0110.00520.17
8.0.240.0120.00420.20
8.0.230.0120.00520.12
8.0.220.0120.00319.30
8.0.210.0110.00519.56
8.0.200.0110.00419.40
8.0.190.0120.00519.31
8.0.180.0110.00418.92
8.0.170.0110.00418.76
8.0.160.0120.00418.67
8.0.150.0110.00518.54
8.0.140.0120.00518.42
8.0.130.0110.00618.27
8.0.120.0120.00418.28
8.0.110.0110.00418.16
8.0.100.0100.00418.04
8.0.90.0110.00417.96
8.0.80.0100.00517.87
8.0.70.0100.00517.89
8.0.60.0100.00617.85
8.0.50.0110.00517.88
8.0.30.0100.00717.58
8.0.20.0110.00717.63
8.0.10.0110.00717.67
8.0.00.0100.00717.63
7.4.330.0090.00320.48
7.4.320.0140.00419.60
7.4.300.0110.00418.35
7.4.290.0120.00518.44
7.4.280.0120.00517.96
7.4.270.0110.00517.93
7.4.260.0120.00518.03
7.4.250.0130.00517.88
7.4.240.0110.00517.75
7.4.230.0110.00517.70
7.4.220.0110.00517.73
7.4.210.0100.00517.56
7.4.200.0110.00517.63
7.4.190.0110.00517.65
7.4.180.0110.00517.69
7.4.160.0110.00617.35
7.4.150.0120.00617.27
7.4.140.0110.00617.20
7.4.130.0110.00717.15
7.4.120.0110.00617.11
7.4.110.0110.00717.10
7.4.100.0110.00717.13
7.4.90.0100.00717.03
7.4.80.0100.00717.04
7.4.70.0110.00717.04
7.4.60.0110.00717.00
7.4.50.0110.00716.93
7.4.40.0110.00716.94
7.4.30.0110.00716.94
7.4.20.0110.00716.91
7.4.10.0100.00716.85
7.4.00.0090.00816.82
7.3.330.0130.00417.83
7.3.320.0130.00417.77
7.3.310.0130.00417.77
7.3.300.0120.00417.62
7.3.290.0110.00517.46
7.3.280.0120.00517.27
7.3.270.0110.00617.13
7.3.260.0120.00617.09
7.3.250.0120.00617.04
7.3.240.0120.00717.01
7.3.230.0110.00717.01
7.3.220.0130.00616.95
7.3.210.0120.00716.92
7.3.200.0120.00716.91
7.3.190.0120.00716.91
7.3.180.0120.00716.88
7.3.170.0120.00716.86
7.3.160.0120.00716.84
7.3.150.0110.00816.83
7.3.140.0120.00716.80
7.3.130.0120.00716.74
7.3.120.0110.00716.64
7.3.110.0110.00816.56
7.3.100.0110.00716.49
7.3.90.0110.00716.61
7.3.80.0110.00716.46
7.3.70.0110.00716.43
7.3.60.0110.00716.40
7.3.50.0110.00716.36
7.3.40.0110.00716.34
7.3.30.0110.00716.33
7.3.20.0150.00716.67
7.3.10.0200.00716.56
7.3.00.0180.00716.55
7.2.340.0150.00717.00
7.2.330.0150.00716.97
7.2.320.0150.00816.95
7.2.310.0140.00816.91
7.2.300.0150.00816.90
7.2.290.0140.00816.89
7.2.280.0140.00816.88
7.2.270.0140.00816.84
7.2.260.0140.00816.79
7.2.250.0130.00816.72
7.2.240.0140.00816.67
7.2.230.0130.00816.61
7.2.220.0130.00816.57
7.2.210.0130.00816.53
7.2.200.0130.00816.57
7.2.190.0130.00816.50
7.2.180.0130.00816.47
7.2.170.0130.00816.49
7.2.160.0130.00816.47
7.2.150.0170.00816.85
7.2.140.0160.00816.85
7.2.130.0200.00816.83
7.2.120.0200.00816.81
7.2.110.0210.00816.78
7.2.100.0220.00816.77
7.2.90.0200.00816.76
7.2.80.0190.00816.76
7.2.70.0210.00816.77
7.2.60.0190.00816.76
7.2.50.0210.00816.76
7.2.40.0200.00816.80
7.2.30.0210.00816.80
7.2.20.0200.00816.79
7.2.10.0190.00816.79
7.2.00.0190.00816.81
7.1.330.0160.00716.20
7.1.320.0160.00816.06
7.1.310.0150.00716.02
7.1.300.0150.00715.96
7.1.290.0150.00715.96
7.1.280.0150.00715.93
7.1.270.0170.00816.00
7.1.260.0150.00715.89
7.1.250.0200.00715.76
7.1.240.0220.00815.77
7.1.230.0210.00815.78
7.1.220.0220.00815.76
7.1.210.0210.00815.76
7.1.200.0210.00815.76
7.1.190.0200.00715.77
7.1.180.0210.00815.74
7.1.170.0220.00715.74
7.1.160.0230.00715.75
7.1.150.0210.00715.75
7.1.140.0200.00715.77
7.1.130.0200.00715.78
7.1.120.0210.00815.75
7.1.110.0220.00715.78
7.1.100.0210.00715.77
7.1.90.0190.00715.78
7.1.80.0200.00715.80
7.1.70.0200.00715.72
7.1.60.0210.00715.97
7.1.50.0190.00815.97
7.1.40.0190.00815.95
7.1.30.0190.00715.96
7.1.20.0190.00815.94
7.1.10.0210.00715.76
7.1.00.0210.00715.78
7.0.330.0210.00715.52
7.0.320.0200.00715.50
7.0.310.0220.00715.46
7.0.300.0210.00715.48
7.0.290.0220.00715.47
7.0.280.0210.00815.47
7.0.270.0200.00715.48
7.0.260.0210.00715.49
7.0.250.0220.00715.54
7.0.240.0210.00715.57
7.0.230.0200.00715.54
7.0.220.0200.00715.53
7.0.210.0190.00815.51
7.0.200.0180.00715.52
7.0.190.0190.00715.50
7.0.180.0180.00715.52
7.0.170.0210.00715.54
7.0.160.0190.00715.48
7.0.150.0200.00715.50
7.0.140.0190.00715.51
7.0.130.0190.00715.58
7.0.120.0180.00815.52
7.0.110.0190.00715.50
7.0.100.0180.00715.48
7.0.90.0170.00815.48
7.0.80.0190.00715.46
7.0.70.0180.00815.47
7.0.60.0180.00815.49
7.0.50.0170.00715.48
7.0.40.0170.00715.50
7.0.30.0190.00715.50
7.0.20.0180.00715.47
7.0.10.0170.00715.50
7.0.00.0170.00715.47
5.6.400.0130.00815.82
5.6.390.0140.00915.82
5.6.380.0140.00815.71
5.6.370.0140.00815.70
5.6.360.0140.00815.70
5.6.350.0140.00915.70
5.6.340.0140.00815.70
5.6.330.0140.00815.71
5.6.320.0140.00815.72
5.6.310.0140.00815.72
5.6.300.0150.00815.68
5.6.290.0140.00815.71
5.6.280.0140.00815.72
5.6.270.0140.00815.70
5.6.260.0130.00815.71
5.6.250.0140.00815.70
5.6.240.0140.00815.71
5.6.230.0140.00815.73
5.6.220.0140.00915.75
5.6.210.0140.00915.71
5.6.200.0140.00815.74
5.6.190.0140.00815.75
5.6.180.0140.00915.72
5.6.170.0140.00915.75
5.6.160.0140.00815.75
5.6.150.0140.00815.74
5.6.140.0150.00815.73
5.6.130.0140.00815.74
5.6.120.0140.00815.73
5.6.110.0140.00915.70
5.6.100.0140.00915.69
5.6.90.0140.00915.68
5.6.80.0140.00815.65
5.6.70.0130.00915.70
5.6.60.0140.00815.69
5.6.50.0130.00815.64
5.6.40.0140.00815.69
5.6.30.0130.00915.65
5.6.20.0130.00915.62
5.6.10.0140.00815.63
5.6.00.0140.00815.63
5.5.380.0140.00815.50
5.5.370.0140.00915.51
5.5.360.0150.00815.43
5.5.350.0140.00815.43
5.5.340.0140.00815.43
5.5.330.0150.00815.44
5.5.320.0140.00915.43
5.5.310.0150.00815.45
5.5.300.0140.00815.41
5.5.290.0150.00815.42
5.5.280.0140.00815.42
5.5.270.0150.00815.41
5.5.260.0150.00715.41
5.5.250.0150.00815.41
5.5.240.0140.00815.44
5.5.230.0140.00815.39
5.5.220.0140.00815.40
5.5.210.0140.00815.42
5.5.200.0140.00815.35
5.5.190.0140.00815.36
5.5.180.0150.00815.36
5.5.170.0140.00815.42
5.5.160.0140.00815.38
5.5.150.0140.00815.33
5.5.140.0140.00815.33
5.5.130.0140.00815.31
5.5.120.0140.00815.31
5.5.110.0140.00815.35
5.5.100.0140.00815.41
5.5.90.0140.00815.41
5.5.80.0140.00815.40
5.5.70.0140.00815.45
5.5.60.0140.00815.41
5.5.50.0140.00815.42
5.5.40.0140.00815.41
5.5.30.0140.00815.41
5.5.20.0140.00815.42
5.5.10.0140.00815.35
5.5.00.0130.00815.33
5.4.450.0110.00612.99
5.4.440.0110.00613.00
5.4.430.0110.00612.98
5.4.420.0110.00612.98
5.4.410.0110.00612.99
5.4.400.0110.00612.94
5.4.390.0110.00612.94
5.4.380.0120.00612.94
5.4.370.0120.00612.95
5.4.360.0110.00612.95
5.4.350.0120.00612.94
5.4.340.0110.00613.03
5.4.330.0110.00612.94
5.4.320.0120.00612.97
5.4.310.0120.00612.95
5.4.300.0110.00612.96
5.4.290.0110.00612.96
5.4.280.0110.00612.95
5.4.270.0110.00712.96
5.4.260.0120.00612.94
5.4.250.0120.00612.93
5.4.240.0110.00612.93
5.4.230.0110.00612.87
5.4.220.0110.00612.86
5.4.210.0120.00612.87
5.4.200.0120.00612.87
5.4.190.0110.00612.86
5.4.180.0120.00612.87
5.4.170.0120.00612.89
5.4.160.0120.00612.89
5.4.150.0110.00612.88
5.4.140.0110.00612.96
5.4.130.0110.00612.95
5.4.120.0110.00612.98
5.4.110.0110.00612.97
5.4.100.0110.00612.97
5.4.90.0110.00612.96
5.4.80.0110.00612.99
5.4.70.0110.00612.98
5.4.60.0110.00612.98
5.4.50.0110.00612.95
5.4.40.0110.00612.97
5.4.30.0110.00612.98
5.4.20.0110.00613.00
5.4.10.0110.00612.99
5.4.00.0110.00612.88

preferences:
63.04 ms | 401 KiB | 5 Q