3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = "wpdPVWejqNRYqDTeUJ2Iw06/rnfHAoy5jtgTojiilD0="; $pwd = "ICS2015"; $salt = "7"; $dec = Decrypt($data, $pwd, $salt); echo "Dec: " . $dec . "\r\n"; $enc = Encrypt("boy10@naver.com", $salt); echo "Enc: " . $enc . "\r\n"; function Decrypt($ciphertext, $password, $salt) { $ciphertext = base64_decode($ciphertext); $key = PBKDF1($password, $salt, 100, 32); $iv = PBKDF1($password, $salt, 100, 16); // NB: Need 128 not 256 and CBC mode to be compatible $decpad = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $ciphertext, MCRYPT_MODE_CBC, $iv); $pad = ord($decpad[($len = strlen($decpad)) - 1]); $dec = substr($decpad, 0, strlen($decpad) - $pad); return $dec; } function Encrypt($pass, $salt) { $derived = PBKDF1($pass, $salt, 100, 48); $key = bin2hex(substr($derived, 0, 32)); $iv = bin2hex(substr($derived, 32, 16)); return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $pass, MCRYPT_MODE_CBC, $iv)); } function PBKDF1($pass, $salt, $count, $cb) { // This is very approximately the way that the Microsoft version of // PasswordDeriveBytes works. /// /// !!!WARNING!!! /// // This is a BAD function! // Irrespective of the fact that the use of PBKDF1 is not recommended anyway. // // This really should be put into a class with a constructor taking the // $pass, $salt and $count. // Then there should be a Reset() method to start from scratch each time a new pwd/salt is used. // And there should be a GetBytes(int) method to get the required info. // But for the sake of simplicity we are assuming the same pwd and salt for each call to // this function. This will not stand up to any scrutiny! static $base; static $extra; static $extracount= 0; static $hashno; static $state = 0; if ($state == 0) { $hashno = 0; $state = 1; $key = $pass . $salt; $base = sha1($key, true); for($i = 2; $i < $count; $i++) { $base = sha1($base, true); } } $result = ""; // Check if we have any bytes left over from a previous iteration. // This is the way MS appears to do it. To me it looks very badly wrong // in the line: "$result = substr($extra, $rlen, $rlen);" // I'm sure it should be more like "$result = substr($extra, $extracount, $rlen);" // Mono have provided what looks like a fixed version at // https://github.com/mono/mono/blob/master/mcs/class/corlib/System.Security.Cryptography/PasswordDeriveBytes.cs // But I'm no cryptographer so I might be wrong. // But this seems to work for low values of $hashno and seems to work // with C# implementations. if ($extracount > 0) { $rlen = strlen($extra) - $extracount; if ($rlen >= $cb) { $result = substr($extra, $extracount, $cb); if ($rlen > $cb) { $extracount += $cb; } else { $extra = null; $extracount = 0; } return $result; } $result = substr($extra, $rlen, $rlen); } $current = ""; $clen = 0; $remain = $cb - strlen($result); while ($remain > $clen) { if ($hashno == 0) { $current = sha1($base, true); } else if ($hashno < 1000) { $n = sprintf("%d", $hashno); $tmp = $n . $base; $current .= sha1($tmp, true); } $hashno++; $clen = strlen($current); } // $current now holds at least as many bytes as we need $result .= substr($current, 0, $remain); // Save any left over bytes for any future requests if ($clen > $remain) { $extra = $current; $extracount = $remain; } return $result; } ?>

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.40.0080.00818.93
8.3.30.0070.00718.79
8.3.20.0040.00420.35
8.3.10.0050.00323.66
8.3.00.0090.00023.45
8.2.170.0110.00419.21
8.2.160.0190.00322.96
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0080.00418.13
8.2.120.0050.00326.35
8.2.110.0040.00422.08
8.2.100.0100.00318.05
8.2.90.0000.00819.20
8.2.80.0080.00017.97
8.2.70.0030.00617.75
8.2.60.0060.00317.93
8.2.50.0040.00418.07
8.2.40.0030.00522.28
8.2.30.0020.00520.69
8.2.20.0030.00517.87
8.2.10.0000.00818.25
8.2.00.0040.00418.19
8.1.270.0040.01522.18
8.1.260.0040.00428.09
8.1.250.0080.00028.09
8.1.240.0060.00323.91
8.1.230.0110.00019.02
8.1.220.0030.00517.79
8.1.210.0030.00618.77
8.1.200.0030.00617.47
8.1.190.0030.00617.48
8.1.180.0000.00818.10
8.1.170.0000.00818.45
8.1.160.0020.00520.73
8.1.150.0000.00718.99
8.1.140.0000.01019.62
8.1.130.0030.00317.76
8.1.120.0030.00517.43
8.1.110.0030.00517.41
8.1.100.0060.00317.52
8.1.90.0070.00017.41
8.1.80.0030.00617.52
8.1.70.0000.00717.54
8.1.60.0030.00517.60
8.1.50.0040.00417.39
8.1.40.0040.00417.61
8.1.30.0000.00817.66
8.1.20.0000.00917.75
8.1.10.0000.00717.51
8.1.00.0050.00317.58
8.0.300.0030.00518.77
8.0.290.0030.00616.75
8.0.280.0070.00018.47
8.0.270.0000.00717.30
8.0.260.0060.00017.32
8.0.250.0000.00717.04
8.0.240.0000.00716.97
8.0.230.0050.00217.10
8.0.220.0000.00817.01
8.0.210.0000.00717.00
8.0.200.0000.00717.06
8.0.190.0080.00016.97
8.0.180.0030.00617.03
8.0.170.0040.00417.02
8.0.160.0040.00416.91
8.0.150.0000.00816.93
8.0.140.0040.00416.93
8.0.130.0000.00613.39
8.0.120.0050.00317.03
8.0.110.0000.00716.90
8.0.100.0040.00416.98
8.0.90.0080.00016.82
8.0.80.0060.00916.93
8.0.70.0040.00416.80
8.0.60.0040.00416.87
8.0.50.0050.00317.08
8.0.30.0100.01017.06
8.0.20.0100.00917.40
8.0.10.0000.00817.05
8.0.00.0140.00816.91
7.4.330.0050.00016.74
7.4.320.0060.00016.58
7.4.300.0030.00316.53
7.4.290.0000.00816.48
7.4.280.0030.00716.61
7.4.270.0030.00316.56
7.4.260.0000.00716.64
7.4.250.0040.00416.62
7.4.240.0000.00716.52
7.4.230.0040.00416.63
7.4.220.0160.00916.73
7.4.210.0090.00716.64
7.4.200.0030.00316.45
7.4.160.0140.00316.81
7.4.150.0180.00017.40
7.4.140.0110.00817.86
7.4.130.0090.00716.61
7.4.120.0110.00616.63
7.4.110.0060.01216.61
7.4.100.0140.01016.38
7.4.90.0150.00916.64
7.4.80.0140.00619.39
7.4.70.0100.00716.46
7.4.60.0100.00616.62
7.4.50.0090.00616.54
7.4.40.0050.01116.77
7.4.30.0170.00716.57
7.4.00.0120.00315.18
7.3.330.0000.00513.34
7.3.320.0000.00613.43
7.3.310.0030.00316.51
7.3.300.0070.00016.34
7.3.290.0000.00716.52
7.3.280.0090.01016.49
7.3.270.0070.01017.40
7.3.260.0150.00616.68
7.3.250.0120.00916.56
7.3.240.0080.00816.57
7.3.230.0080.01216.52
7.3.210.0170.00016.50
7.3.200.0150.00419.39
7.3.190.0060.01216.74
7.3.180.0170.00016.66
7.3.170.0160.00616.59
7.3.160.0060.01216.67
7.2.330.0030.01416.48
7.2.320.0080.00816.75
7.2.310.0040.01816.74
7.2.300.0180.02616.58
7.2.290.0040.01416.81
7.2.110.0070.01116.48
7.2.60.0130.00316.95
7.2.00.0060.00619.23
7.1.200.0030.00615.80
7.1.100.0070.00317.93
7.1.70.0040.00417.01
7.1.60.0180.00419.06
7.1.50.0030.01017.00
7.1.00.0030.07322.45
7.0.200.0310.00414.61
7.0.60.0000.07021.82
7.0.50.0030.04018.03
7.0.40.0070.08720.25
7.0.30.0300.07720.34
7.0.20.0370.07320.30
7.0.10.0100.08320.30
7.0.00.0100.04720.09
5.6.280.0100.06720.93
5.6.210.0030.06720.77
5.6.200.0000.07318.20
5.6.190.0130.07020.42
5.6.180.0230.08320.57
5.6.170.0300.08320.48
5.6.160.0070.08320.47
5.6.150.0030.04018.19
5.6.140.0100.05318.19
5.6.130.0030.08318.29
5.6.120.0130.07021.12
5.6.110.0130.07721.04
5.6.100.0070.08721.03
5.6.90.0100.07021.06
5.6.80.0070.08020.46
5.5.350.0030.06320.44
5.5.340.0070.05718.02
5.5.330.0070.08320.45
5.5.320.0200.04020.27
5.5.310.0170.04020.42
5.5.300.0070.03317.95
5.5.290.0000.04717.99
5.5.280.0070.08320.90
5.5.270.0200.07020.82
5.5.260.0100.08320.72
5.5.250.0300.07020.82
5.5.240.0130.03320.09

preferences:
54.92 ms | 400 KiB | 5 Q