3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class Crypt { private static $range = 62; private static $goldenPrimes36 = array( /* * Key..: next prime greater than 36 ^ n / 1.618033988749894848 * Value: modular multiplicative inverse */ '1' => '1', '23' => '11', '809' => '809', '28837' => '29485', '1038073' => '179017', '37370153' => '47534873', '1345325473' => '264202849', '48431716939' => '19727015779', '1743541808839' => '1532265214711', '62767505117101' => '67935388019749', '3656158440062987' => '3323780400057251', '131621703842267239' => '14056686818106199' ); private static $goldenPrimes62 = array( /* * Key..: next prime greater than 62 ^ n / 1.618033988749894848 * Value: modular multiplicative inverse */ '1' => '1', '41' => '59', '2377' => '1677', '147299' => '187507', '9132313' => '5952585', '566201239' => '643566407', '35104476161' => '22071637057', '2176477521929' => '294289236153', '134941606358731' => '88879354792675', '8366379594239857' => '7275288500431249', '518715534842869223' => '280042546585394647' ); private static $chars62 = array( // Ascii : 0-9 0 => 48, 1 => 49, 2 => 50, 3 => 51, 4 => 52, 5 => 53, 6 => 54, 7 => 55, 8 => 56, 9 => 57, // Ascii : A-Z 10 => 65, 11 => 66, 12 => 67, 13 => 68, 14 => 69, 15 => 70, 16 => 71, 17 => 72, 18 => 73, 19 => 74, 20 => 75, 21 => 76, 22 => 77, 23 => 78, 24 => 79, 25 => 80, 26 => 81, 27 => 82, 28 => 83, 29 => 84, 30 => 85, 31 => 86, 32 => 87, 33 => 88, 34 => 89, 35 => 90, // Ascii : a-z 36 => 97, 37 => 98, 38 => 99, 39 => 100, 40 => 101, 41 => 102, 42 => 103, 43 => 104, 44 => 105, 45 => 106, 46 => 107, 47 => 108, 48 => 109, 49 => 110, 50 => 111, 51 => 112, 52 => 113, 53 => 114, 54 => 115, 55 => 116, 56 => 117, 57 => 118, 58 => 119, 59 => 120, 60 => 121, 61 => 122 ); /** * Calculates the hash 36 or 62 based range. * @param integer $int * @return string */ private static function baseX($int) { $key = ''; while (bccomp($int, 0) > 0) { $mod = bcmod($int, self::$range); $key .= chr(self::$chars62[$mod]); $int = bcdiv($int, self::$range, 0); } return strrev($key); } /** * Inverse calculation for hashes 36 or 62 based range. * @param string $key * @return integer */ private static function unbaseX($key) { $int = 0; foreach (str_split(strrev($key)) as $i => $char) { $dec = array_search(ord($char), self::$chars62); $int = bcadd(bcmul($dec, bcpow(self::$range, $i)), $int); } return $int; } /** * Generates the hash 62 based chars(a-z, A-Z, 0-9) to a given int number. * Important: * – the biggest cryptable integer with hash length = 5 is 916 132 831. * – the biggest cryptable integer with hash length = 6 is 56 800 235 583. It seems to be enough, no? * * @param integer $num * @param integer $len * @return string */ public static function hash($num, $len = 5) { $ceil = bcpow(self::$range, $len); $primes = array_keys(self::$range === 36 ? self::$goldenPrimes36 : self::$goldenPrimes62); $prime = $primes[$len]; $dec = bcmod(bcmul($num, $prime, 0),$ceil); $hash = self::baseX($dec); return str_pad($hash, $len, '0', STR_PAD_LEFT); } /** * Generates the hash 36 based chars(A-Z, 0-9) to a given int number. * * Important: * * – the biggest cryptable integer with hash length = 5 is 60 466 175. * * – the biggest cryptable integer with hash length = 6 is 2 176 782 335. */ public static function hash36($num, $len = 5) { self::$range = 36; return self::hash($num, $len); } /** * Converts a previous generated hash to its original integer. * @param string $hash * @return integer */ public static function unhash($hash) { $len = strlen($hash); $ceil = bcpow(self::$range, $len); $mmiprimes = array_values(self::$range === 36 ? self::$goldenPrimes36 : self::$goldenPrimes62); $mmi = $mmiprimes[$len]; $num = self::unbaseX($hash); $dec = bcmod(bcmul($num, $mmi), $ceil); return $dec; } } $hashParams = array( 'plopi' => 'gato', 'token' => 'lol' ); var_dump($hashParams); $hashParams = 'poney'; $strEncoded = Crypt::hash(json_encode($hashParams)); echo "\n encoded\t:" . json_encode($hashParams). "\n"; echo "\n encoded\t:" . $strEncoded. "\n"; echo "\n decode encoded\t:" . Crypt::unhash($strEncoded)."\n"; var_dump(json_decode(Crypt::unhash($strEncoded), true));

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.0140.00318.43
8.3.50.0140.00718.05
8.3.40.0090.00618.80
8.3.30.0090.00619.04
8.3.20.0070.00020.34
8.3.10.0060.00321.85
8.3.00.0040.00419.05
8.2.180.0130.00918.41
8.2.170.0090.00922.96
8.2.160.0070.00722.26
8.2.150.0050.00524.18
8.2.140.0000.00824.66
8.2.130.0070.00026.16
8.2.120.0080.00019.79
8.2.110.0090.00022.24
8.2.100.0080.00318.22
8.2.90.0050.00319.29
8.2.80.0030.00717.97
8.2.70.0090.00017.88
8.2.60.0060.00318.04
8.2.50.0060.00318.07
8.2.40.0000.00919.88
8.2.30.0040.00418.22
8.2.20.0040.00417.86
8.2.10.0030.00618.21
8.2.00.0000.00817.71
8.1.270.0060.00319.08
8.1.260.0050.00326.35
8.1.250.0030.00628.09
8.1.240.0030.00623.86
8.1.230.0070.00319.28
8.1.220.0080.00017.74
8.1.210.0090.00018.77
8.1.200.0030.00717.47
8.1.190.0040.00417.35
8.1.180.0040.00418.10
8.1.170.0000.00818.63
8.1.160.0050.00322.00
8.1.150.0040.00418.80
8.1.140.0000.00819.27
8.1.130.0040.00417.80
8.1.120.0000.00817.36
8.1.110.0000.00817.48
8.1.100.0000.00717.42
8.1.90.0000.00717.45
8.1.80.0040.00417.34
8.1.70.0040.00417.37
8.1.60.0000.00817.65
8.1.50.0030.00617.59
8.1.40.0000.00817.58
8.1.30.0030.00517.61
8.1.20.0040.00417.64
8.1.10.0050.00317.57
8.1.00.0000.00817.44
8.0.300.0060.00318.77
8.0.290.0000.00816.75
8.0.280.0000.00818.44
8.0.270.0000.00717.24
8.0.260.0030.00317.15
8.0.250.0030.00317.05
8.0.240.0000.00717.06
8.0.230.0070.00016.95
8.0.220.0030.00316.86
8.0.210.0030.00316.95
8.0.200.0030.00517.03
8.0.190.0080.00417.00
8.0.180.0060.00317.05
8.0.170.0040.00416.90
8.0.160.0000.00716.89
8.0.150.0000.00816.88
8.0.140.0000.00816.96
8.0.130.0030.00313.38
8.0.120.0050.00316.89
8.0.110.0030.00616.92
8.0.100.0070.00016.74
8.0.90.0070.00016.88
8.0.80.0030.01216.94
8.0.70.0000.00716.90
8.0.60.0070.00017.04
8.0.50.0030.00516.84
8.0.30.0090.01116.94
8.0.20.0060.01317.40
8.0.10.0000.00717.21
8.0.00.0110.01016.77
7.4.330.0000.00515.03
7.4.320.0060.00016.58
7.4.300.0030.00316.58
7.4.290.0040.00416.49
7.4.280.0000.00716.40
7.4.270.0070.00016.65
7.4.260.0080.00416.50
7.4.250.0000.00816.61
7.4.240.0030.00416.57
7.4.230.0030.00316.61
7.4.220.0040.01316.72
7.4.210.0040.01116.60
7.4.200.0030.00416.50
7.4.160.0110.00516.44
7.4.150.0070.01217.40
7.4.140.0140.00517.86
7.4.130.0090.01016.62
7.4.120.0080.01016.64
7.4.110.0110.00716.54
7.4.100.0100.00816.52
7.4.90.0180.00016.45
7.4.80.0130.00319.39
7.4.70.0090.00916.55
7.4.60.0030.01316.66
7.4.50.0000.00416.28
7.4.40.0090.00916.57
7.4.30.0110.00716.55
7.4.00.0050.00915.15
7.3.330.0090.00013.42
7.3.320.0030.00313.42
7.3.310.0030.00316.47
7.3.300.0030.00316.43
7.3.290.0060.00916.40
7.3.280.0090.00816.40
7.3.270.0120.00617.40
7.3.260.0060.01216.82
7.3.250.0060.01216.55
7.3.240.0070.01016.71
7.3.230.0160.00516.54
7.3.210.0110.00716.38
7.3.200.0090.00919.39
7.3.190.0070.01016.57
7.3.180.0080.00816.35
7.3.170.0150.00616.42
7.3.160.0110.01016.37
7.3.120.0060.01314.89
7.3.110.0030.01414.96
7.3.100.0060.00915.09
7.3.90.0080.00315.09
7.3.80.0060.00314.69
7.3.70.0090.00614.61
7.3.60.0060.00914.91
7.3.50.0110.00314.52
7.3.40.0060.00915.01
7.3.30.0080.00414.91
7.3.20.0040.01216.48
7.3.10.0100.00616.65
7.3.00.0070.00416.86
7.2.330.0030.01816.79
7.2.320.0060.01216.57
7.2.310.0090.00916.48
7.2.300.0000.01716.52
7.2.290.0070.01016.57
7.2.250.0030.01214.89
7.2.240.0130.00715.16
7.2.230.0060.00915.06
7.2.220.0100.00615.27
7.2.210.0070.01114.77
7.2.200.0080.00414.99
7.2.190.0060.00614.80
7.2.180.0070.01015.09
7.2.170.0090.00315.23
7.2.120.0090.00616.73
7.2.110.0100.00316.71
7.2.100.0100.00716.64
7.2.90.0100.00316.64
7.2.80.0040.01116.81
7.2.70.0090.00616.76
7.2.60.0070.00717.03
7.2.50.0100.00317.10
7.2.40.0030.01217.01
7.2.30.0040.01116.92
7.2.20.0130.00016.96
7.2.10.0100.00616.84
7.2.00.0020.01018.29
7.1.330.0060.00915.93
7.1.320.0070.00715.86
7.1.310.0100.00315.78
7.1.300.0070.01015.91
7.1.290.0090.00615.77
7.1.280.0000.00915.59
7.1.270.0100.00715.64
7.1.260.0070.00716.04
7.1.240.0070.00715.82
7.1.230.0110.00015.77
7.1.220.0000.01116.01
7.1.210.0050.00315.72
7.1.200.0060.00515.88
7.1.190.0000.01515.82
7.1.180.0050.00515.99
7.1.170.0040.01115.93
7.1.160.0030.01015.78
7.1.150.0040.00415.91
7.1.140.0110.00415.78
7.1.130.0030.00715.95
7.1.120.0040.00816.01
7.1.110.0040.01115.79
7.1.100.0090.00416.89
7.1.90.0030.00916.04
7.1.80.0090.00315.65
7.1.70.0060.01016.38
7.1.60.0070.01017.59
7.1.50.0050.01216.14
7.1.40.0070.00715.80
7.1.30.0040.00815.92
7.1.20.0040.00815.81
7.1.10.0000.01415.98
7.1.00.0080.03819.11
7.0.320.0060.00615.55
7.0.310.0000.00815.41
7.0.300.0060.00915.18
7.0.290.0080.00415.30
7.0.280.0040.00915.09
7.0.270.0090.00615.09
7.0.260.0100.00015.30
7.0.250.0040.01115.25
7.0.240.0070.00715.48
7.0.230.0000.01015.53
7.0.220.0030.00615.14
7.0.210.0060.00615.50
7.0.200.0050.00516.09
7.0.190.0110.00315.60
7.0.180.0100.00015.50
7.0.170.0000.01315.44
7.0.160.0030.01015.55
7.0.150.0040.00415.44
7.0.140.0080.02118.62
7.0.130.0090.00315.50
7.0.120.0060.00615.40
7.0.110.0060.00615.48
7.0.100.0040.00815.37
7.0.90.0070.04617.79
7.0.80.0090.04317.61
7.0.70.0100.03517.68
7.0.60.0010.04317.72
7.0.50.0400.04417.95
7.0.40.0030.02816.78
7.0.30.0070.04516.72
7.0.20.0110.03516.81
7.0.10.0120.03816.77
7.0.00.0080.04016.80
5.6.380.0000.01114.51
5.6.370.0030.00614.39
5.6.360.0060.00314.46
5.6.350.0030.01214.48
5.6.340.0060.00614.27
5.6.330.0030.00714.36
5.6.320.0130.00314.12
5.6.310.0030.01014.66
5.6.300.0000.00714.54
5.6.290.0030.01014.65
5.6.280.0030.04017.72
5.6.270.0060.00314.52
5.6.260.0060.00914.41
5.6.250.0000.00914.83
5.6.240.0070.00714.41
5.6.230.0040.04917.42
5.6.220.0080.04417.65
5.6.210.0070.04417.45
5.6.200.0080.04517.74
5.6.190.0060.02617.91
5.6.180.0080.03017.70
5.6.170.0130.02317.93
5.6.160.0050.04617.87
5.6.150.0120.02817.82
5.6.140.0030.02717.77
5.6.130.0050.04417.77
5.6.120.0080.03017.89
5.6.110.0080.02317.73
5.6.100.0050.03017.75
5.6.90.0030.04017.68
5.6.80.0060.04017.38
5.6.70.0060.03917.44
5.6.60.0050.04017.34
5.6.50.0150.03617.48
5.6.40.0030.04917.35
5.6.30.0160.03217.52
5.6.20.0100.03917.45
5.6.10.0030.04717.30
5.6.00.0050.04117.29
5.5.380.0060.00611.08
5.5.370.0060.04415.90
5.5.360.0050.04515.79
5.5.350.0070.03715.79
5.5.340.0100.03616.13
5.5.330.0020.02715.89
5.5.320.0060.02215.86
5.5.310.0050.04316.07
5.5.300.0070.02616.00
5.5.290.0070.03815.88
5.5.280.0080.03816.02
5.5.270.0110.03915.78
5.5.260.0100.04015.91
5.5.250.0050.03315.83
5.5.240.0050.02515.63
5.5.230.0060.03615.66
5.5.220.0050.04015.59
5.5.210.0100.03515.66
5.5.200.0070.02515.71
5.5.190.0100.03515.62
5.5.180.0070.03215.72
5.5.170.0000.00914.51
5.5.160.0020.04315.72
5.5.150.0030.04515.70
5.5.140.0050.04015.67
5.5.130.0020.02415.60
5.5.120.0080.04215.56
5.5.110.0080.04015.65
5.5.100.0070.02615.38
5.5.90.0090.03715.50
5.5.80.0020.04615.53
5.5.70.0050.04315.66
5.5.60.0080.03115.53
5.5.50.0080.04015.49
5.5.40.0120.03415.61
5.5.30.0040.04415.52
5.5.20.0070.03815.45
5.5.10.0030.02515.48
5.5.00.0000.05015.46
5.4.450.0120.03815.13
5.4.440.0030.03515.10
5.4.430.0080.04115.18
5.4.420.0100.03515.30
5.4.410.0020.02914.99
5.4.400.0080.02814.98
5.4.390.0030.02514.94
5.4.380.0030.03614.98
5.4.370.0110.03214.99
5.4.360.0070.02515.04
5.4.350.0080.03815.16
5.4.340.0040.03915.04
5.4.330.0040.00711.21
5.4.320.0030.03815.04
5.4.310.0020.04514.96
5.4.300.0100.03715.22
5.4.290.0050.02415.14
5.4.280.0000.02915.06
5.4.270.0070.02714.98
5.4.260.0050.04015.02
5.4.250.0070.03614.80
5.4.240.0030.03014.93
5.4.230.0080.04114.95
5.4.220.0050.04114.88
5.4.210.0110.03815.12
5.4.200.0070.03814.95
5.4.190.0090.04015.08
5.4.180.0020.02515.01
5.4.170.0100.04014.92
5.4.160.0040.03815.04
5.4.150.0100.03815.02
5.4.140.0070.02613.50
5.4.130.0020.03613.65
5.4.120.0010.04113.81
5.4.110.0110.02813.64
5.4.100.0090.02013.71
5.4.90.0050.04113.72
5.4.80.0040.03613.59
5.4.70.0060.02213.57
5.4.60.0050.02513.79
5.4.50.0030.03013.71
5.4.40.0070.02213.72
5.4.30.0030.04313.73
5.4.20.0040.04213.66
5.4.10.0050.03813.79
5.4.00.0070.03713.30
5.3.290.0030.04112.70
5.3.280.0030.03012.62
5.3.270.0070.03812.71
5.3.260.0050.04612.60
5.3.250.0110.03112.75
5.3.240.0080.03012.56
5.3.230.0080.03612.53
5.3.220.0100.03512.48
5.3.210.0080.03812.58
5.3.200.0030.02512.42
5.3.190.0060.02212.58
5.3.180.0070.04512.72
5.3.170.0060.03812.59
5.3.160.0050.03912.71
5.3.150.0020.04412.66
5.3.140.0090.03312.69
5.3.130.0080.03712.49
5.3.120.0070.03212.65
5.3.110.0070.03512.58
5.3.100.0020.03812.34
5.3.90.0050.03812.47
5.3.80.0100.03612.27
5.3.70.0020.04212.20
5.3.60.0050.03912.25
5.3.50.0020.02812.30
5.3.40.0020.03512.38
5.3.30.0030.01912.32
5.3.20.0050.03812.26
5.3.10.0120.01511.93
5.3.00.0080.03211.90
5.2.170.0050.03310.57
5.2.160.0080.02810.58
5.2.150.0000.02610.44
5.2.140.0050.02010.56
5.2.130.0020.03510.55
5.2.120.0030.02410.44
5.2.110.0050.03710.50
5.2.100.0060.01810.54
5.2.90.0000.02210.51
5.2.80.0100.02710.56
5.2.70.0030.03010.42
5.2.60.0050.02710.51
5.2.50.0060.03010.50
5.2.40.0050.02310.38
5.2.30.0020.02910.50
5.2.20.0060.02710.38
5.2.10.0030.03310.38
5.2.00.0030.03310.27
5.1.60.0020.0309.86
5.1.50.0030.0189.98
5.1.40.0000.0239.96
5.1.30.0040.03010.10
5.1.20.0020.02010.16
5.1.10.0020.03010.00
5.1.00.0000.0239.90
5.0.50.0000.0299.21
5.0.40.0020.0259.18
5.0.30.0070.0259.05
5.0.20.0020.0279.00
5.0.10.0040.0239.06
5.0.00.0010.0259.00
4.4.90.0020.0139.00
4.4.80.0020.0209.00
4.4.70.0050.0179.00
4.4.60.0030.0209.00
4.4.50.0030.0159.00
4.4.40.0050.0139.00
4.4.30.0030.0189.00
4.4.20.0050.0179.00
4.4.10.0030.0209.00
4.4.00.0000.0309.00
4.3.110.0030.0189.00
4.3.100.0020.0209.00
4.3.90.0020.0109.00
4.3.80.0050.0239.00
4.3.70.0000.0219.00
4.3.60.0050.0079.00
4.3.50.0030.0139.00
4.3.40.0010.0189.00
4.3.30.0000.0179.00
4.3.20.0030.0189.00
4.3.10.0000.0169.00
4.3.00.0000.0179.00

preferences:
88.59 ms | 400 KiB | 5 Q