3v4l.org

run code in 300+ PHP versions simultaneously
<?php class EAHashor { //initialise the class function __construct() { } function eaEncode($string){ $a = "67452301"; $b = "EFCDAB89"; $c = "98BADCFE"; $d = "10325476"; $words = $this->init($string); for($i = 0; $i <= count($words)/16-1; $i++){ $A = $a; $B = $b; $C = $c; $D = $d; /* ROUND 1 */ $this->FF ($A, $B, $C, $D, $words[0 + ($i * 16)], 7, "d76aa478"); $this->FF ($D, $A, $B, $C, $words[1 + ($i * 16)], 12, "e8c7b756"); $this->FF ($C, $D, $A, $B, $words[2 + ($i * 16)], 17, "242070db"); $this->FF ($B, $C, $D, $A, $words[3 + ($i * 16)], 22, "c1bdceee"); $this->FF ($A, $B, $C, $D, $words[4 + ($i * 16)], 7, "f57c0faf"); $this->FF ($D, $A, $B, $C, $words[5 + ($i * 16)], 12, "4787c62a"); $this->FF ($C, $D, $A, $B, $words[6 + ($i * 16)], 17, "a8304613"); $this->FF ($B, $C, $D, $A, $words[7 + ($i * 16)], 22, "fd469501"); $this->FF ($A, $B, $C, $D, $words[8 + ($i * 16)], 7, "698098d8"); $this->FF ($D, $A, $B, $C, $words[9 + ($i * 16)], 12, "8b44f7af"); $this->FF ($C, $D, $A, $B, $words[10 + ($i * 16)], 17, "ffff5bb1"); $this->FF ($B, $C, $D, $A, $words[11 + ($i * 16)], 22, "895cd7be"); $this->FF ($A, $B, $C, $D, $words[12 + ($i * 16)], 7, "6b901122"); $this->FF ($D, $A, $B, $C, $words[13 + ($i * 16)], 12, "fd987193"); $this->FF ($C, $D, $A, $B, $words[14 + ($i * 16)], 17, "a679438e"); $this->FF ($B, $C, $D, $A, $words[15 + ($i * 16)], 22, "49b40821"); /* ROUND 2 */ $this->GG ($A, $B, $C, $D, $words[1 + ($i * 16)], 5, "f61e2562"); $this->GG ($D, $A, $B, $C, $words[6 + ($i * 16)], 9, "c040b340"); $this->GG ($C, $D, $A, $B, $words[11 + ($i * 16)], 14, "265e5a51"); $this->GG ($B, $C, $D, $A, $words[0 + ($i * 16)], 20, "e9b6c7aa"); $this->GG ($A, $B, $C, $D, $words[5 + ($i * 16)], 5, "d62f105d"); $this->GG ($D, $A, $B, $C, $words[10 + ($i * 16)], 9, "02441453"); $this->GG ($C, $D, $A, $B, $words[15 + ($i * 16)], 14, "d8a1e681"); $this->GG ($B, $C, $D, $A, $words[4 + ($i * 16)], 20, "e7d3fbc8"); $this->GG ($A, $B, $C, $D, $words[9 + ($i * 16)], 5, "21e1cde6"); $this->GG ($D, $A, $B, $C, $words[14 + ($i * 16)], 9, "c33707d6"); $this->GG ($C, $D, $A, $B, $words[3 + ($i * 16)], 14, "f4d50d87"); $this->GG ($B, $C, $D, $A, $words[8 + ($i * 16)], 20, "455a14ed"); $this->GG ($A, $B, $C, $D, $words[13 + ($i * 16)], 5, "a9e3e905"); $this->GG ($D, $A, $B, $C, $words[2 + ($i * 16)], 9, "fcefa3f8"); $this->GG ($C, $D, $A, $B, $words[7 + ($i * 16)], 14, "676f02d9"); $this->GG ($B, $C, $D, $A, $words[12 + ($i * 16)], 20, "8d2a4c8a"); /* ROUND 3 */ $this->HH ($A, $B, $C, $D, $words[5 + ($i * 16)], 4, "fffa3942"); $this->HH ($D, $A, $B, $C, $words[8 + ($i * 16)], 11, "8771f681"); //HH ($C, $D, $A, $B, $words[11 + ($i * 16)], 16, "6d9d6122"); //EA change to use 14 rather than 16 as seen in the commented line $this->HH ($C, $D, $A, $B, $words[11 + ($i * 16)], 14, "6d9d6122"); $this->HH ($B, $C, $D, $A, $words[14 + ($i * 16)], 23, "fde5380c"); $this->HH ($A, $B, $C, $D, $words[1 + ($i * 16)], 4, "a4beea44"); $this->HH ($D, $A, $B, $C, $words[4 + ($i * 16)], 11, "4bdecfa9"); $this->HH ($C, $D, $A, $B, $words[7 + ($i * 16)], 16, "f6bb4b60"); $this->HH ($B, $C, $D, $A, $words[10 + ($i * 16)], 23, "bebfbc70"); $this->HH ($A, $B, $C, $D, $words[13 + ($i * 16)], 4, "289b7ec6"); $this->HH ($D, $A, $B, $C, $words[0 + ($i * 16)], 11, "eaa127fa"); $this->HH ($C, $D, $A, $B, $words[3 + ($i * 16)], 16, "d4ef3085"); $this->HH ($B, $C, $D, $A, $words[6 + ($i * 16)], 23, "04881d05"); $this->HH ($A, $B, $C, $D, $words[9 + ($i * 16)], 4, "d9d4d039"); $this->HH ($D, $A, $B, $C, $words[12 + ($i * 16)], 11, "e6db99e5"); $this->HH ($C, $D, $A, $B, $words[15 + ($i * 16)], 16, "1fa27cf8"); $this->HH ($B, $C, $D, $A, $words[2 + ($i * 16)], 23, "c4ac5665"); /* ROUND 4 */ $this->II ($A, $B, $C, $D, $words[0 + ($i * 16)], 6, "f4292244"); $this->II ($D, $A, $B, $C, $words[7 + ($i * 16)], 10, "432aff97"); $this->II ($C, $D, $A, $B, $words[14 + ($i * 16)], 15, "ab9423a7"); $this->II ($B, $C, $D, $A, $words[5 + ($i * 16)], 21, "fc93a039"); $this->II ($A, $B, $C, $D, $words[12 + ($i * 16)], 6, "655b59c3"); $this->II ($D, $A, $B, $C, $words[3 + ($i * 16)], 10, "8f0ccc92"); $this->II ($C, $D, $A, $B, $words[10 + ($i * 16)], 15, "ffeff47d"); $this->II ($B, $C, $D, $A, $words[1 + ($i * 16)], 21, "85845dd1"); $this->II ($A, $B, $C, $D, $words[8 + ($i * 16)], 6, "6fa87e4f"); $this->II ($D, $A, $B, $C, $words[15 + ($i * 16)], 10, "fe2ce6e0"); $this->II ($C, $D, $A, $B, $words[6 + ($i * 16)], 15, "a3014314"); $this->II ($B, $C, $D, $A, $words[13 + ($i * 16)], 21, "4e0811a1"); $this->II ($A, $B, $C, $D, $words[4 + ($i * 16)], 6, "f7537e82"); $this->II ($D, $A, $B, $C, $words[11 + ($i * 16)], 10, "bd3af235"); $this->II ($C, $D, $A, $B, $words[2 + ($i * 16)], 15, "2ad7d2bb"); $this->II ($B, $C, $D, $A, $words[9 + ($i * 16)], 21, "eb86d391"); //EA change to use this last line twice $this->II ($B, $C, $D, $A, $words[9 + ($i * 16)], 21, "eb86d391"); $this->addVars($a, $b, $c, $d, $A, $B, $C, $D); } $MD5 = ''; foreach (array($a, $b, $c, $d) as $x) { $MD5 .= implode('', array_reverse(str_split($this->leftpad($x, 8), 2))); } return $MD5; } /* General functions */ function hexbin($str){ $hexbinmap = array( "0" => "0000", "1" => "0001", "2" => "0010", "3" => "0011" , "4" => "0100" , "5" => "0101" , "6" => "0110" , "7" => "0111" , "8" => "1000" , "9" => "1001" , "A" => "1010" , "a" => "1010" , "B" => "1011" , "b" => "1011" , "C" => "1100" , "c" => "1100" , "D" => "1101" , "d" => "1101" , "E" => "1110" , "e" => "1110" , "F" => "1111" , "f" => "1111"); $bin = ""; for ($i = 0; $i < strlen($str); $i++){ $bin .= $hexbinmap[$str[$i]]; } $bin = ltrim($bin, '0'); // echo "Original: ".$str." New: ".$bin."<br />"; return $bin; } function strhex($str){ $hex = ""; for ($i = 0; $i < strlen($str); $i++){ $hex = $hex.$this->leftpad(dechex(ord($str[$i])), 2); } return $hex; } /* MD5-specific functions */ function init($string){ $len = strlen($string) * 8; $hex = $this->strhex($string); // convert ascii string to hex $bin = $this->leftpad($this->hexbin($hex), $len); // convert hex string to bin $padded = $this->pad($bin); $padded = $this->pad($padded, 1, $len); $block = str_split($padded, 32); foreach ($block as $bk => $b) { $block[$bk] = implode('', array_reverse(str_split($b, 8))); } return $block; } function pad($bin, $type=0, $len = 0){ if($type == 0){ $bin = $bin."1"; $buff = strlen($bin) % 512; if($buff != 448){ while(strlen($bin) % 512 != 448){ $bin = $bin."0"; } } } // append length (b) of string to latter 64 bits elseif($type == 1){ $bLen = $this->leftpad(decbin($len), 64); $bin .= implode('', array_reverse(str_split($bLen, 8))); } return $bin; } /* MD5 base functions */ function F($X, $Y, $Z){ $X = hexdec($X); $Y = hexdec($Y); $Z = hexdec($Z); $calc = (($X & $Y) | ((~ $X) & $Z)); // X AND Y OR NOT X AND Z return $calc; } function G($X, $Y, $Z){ $X = hexdec($X); $Y = hexdec($Y); $Z = hexdec($Z); $calc = (($X & $Z) | ($Y & (~ $Z))); // X AND Z OR Y AND NOT Z return $calc; } function H($X, $Y, $Z){ $X = hexdec($X); $Y = hexdec($Y); $Z = hexdec($Z); $calc = ($X ^ $Y ^ $Z); // X XOR Y XOR Z return $calc; } function I($X, $Y, $Z){ $X = hexdec($X); $Y = hexdec($Y); $Z = hexdec($Z); $calc = ($Y ^ ($X | (~ $Z))) ; // Y XOR (X OR NOT Z) return $calc; } /* MD5 round functions */ /* $A - hex, $B - hex, $C - hex, $D - hex (F - dec) $M - binary $s - decimal $t - hex */ function FF(&$A, $B, $C, $D, $M, $s, $t){ $A = hexdec($A); $t = hexdec($t); $M = bindec($M); $A = ($A + $this->F($B, $C, $D) + $M + $t) & 0xffffffff; //decimal $A = $this->rotate($A, $s); $A = dechex((hexdec($B) + hexdec($A)) & 0xffffffff); } function GG(&$A, $B, $C, $D, $M, $s, $t){ $A = hexdec($A); $t = hexdec($t); $M = bindec($M); $A = ($A + $this->G($B, $C, $D) + $M + $t) & 0xffffffff; //decimal $A = $this->rotate($A, $s); $A = dechex((hexdec($B) + hexdec($A)) & 0xffffffff); } function HH(&$A, $B, $C, $D, $M, $s, $t){ $A = hexdec($A); $t = hexdec($t); $M = bindec($M); $A = ($A + $this->H($B, $C, $D) + $M + $t) & 0xffffffff; //decimal $A = $this->rotate($A, $s); $A = dechex((hexdec($B) + hexdec($A)) & 0xffffffff); } function II(&$A, $B, $C, $D, $M, $s, $t){ $A = hexdec($A); $t = hexdec($t); $M = bindec($M); $A = ($A + $this->I($B, $C, $D) + $M + $t) & 0xffffffff; //decimal $A = $this->rotate($A, $s); $A = dechex((hexdec($B) + hexdec($A)) & 0xffffffff); } // shift function rotate ($decimal, $bits) { //returns hex return dechex((($decimal << $bits) | ($decimal >> (32 - $bits))) & 0xffffffff); } function addVars(&$a, &$b, &$c, &$d, $A, $B, $C, $D){ $A = hexdec($A); $B = hexdec($B); $C = hexdec($C); $D = hexdec($D); $aa = hexdec($a); $bb = hexdec($b); $cc = hexdec($c); $dd = hexdec($d); $aa = ($aa + $A) & 0xffffffff; $bb = ($bb + $B) & 0xffffffff; $cc = ($cc + $C) & 0xffffffff; $dd = ($dd + $D) & 0xffffffff; $a = dechex($aa); $b = dechex($bb); $c = dechex($cc); $d = dechex($dd); } function leftpad($needs_padding, $alignment) { if (strlen($needs_padding) % $alignment) { $pad_amount = $alignment - strlen($needs_padding) % $alignment; $left_pad = implode('', array_fill(0, $pad_amount, '0')); $needs_padding = $left_pad . $needs_padding; } return $needs_padding; } } $eahashor = new EAHashor(); $hash = $eahashor->eaEncode('test'); echo $hash;

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.0090.00917.00
8.3.50.0140.00916.61
8.3.40.0110.00419.26
8.3.30.0120.00419.24
8.3.20.0050.00319.20
8.3.10.0060.00319.16
8.3.00.0080.01119.38
8.2.180.0160.00016.63
8.2.170.0190.00322.96
8.2.160.0080.00819.20
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0030.00526.16
8.2.120.0100.00319.65
8.2.110.0030.00719.39
8.2.100.0140.00517.77
8.2.90.0080.00018.13
8.2.80.0080.00019.16
8.2.70.0040.00417.88
8.2.60.0080.00017.88
8.2.50.0060.00318.30
8.2.40.0000.01019.35
8.2.30.0090.00017.97
8.2.20.0060.00617.97
8.2.10.0000.00818.05
8.2.00.0000.01018.00
8.1.280.0110.00725.92
8.1.270.0080.00023.99
8.1.260.0080.00026.35
8.1.250.0050.00328.09
8.1.240.0080.00320.92
8.1.230.0080.00421.00
8.1.220.0030.00618.86
8.1.210.0030.00518.77
8.1.200.0070.00317.60
8.1.190.0030.00617.38
8.1.180.0040.00418.10
8.1.170.0030.00617.62
8.1.160.0080.00019.31
8.1.150.0030.00618.89
8.1.140.0030.00717.66
8.1.130.0030.00519.24
8.1.120.0060.00317.77
8.1.110.0000.00817.61
8.1.100.0040.00417.66
8.1.90.0040.00417.71
8.1.80.0000.00817.75
8.1.70.0040.00417.61
8.1.60.0030.00617.84
8.1.50.0040.00417.81
8.1.40.0060.00317.63
8.1.30.0030.00617.79
8.1.20.0060.00617.82
8.1.10.0000.00817.86
8.1.00.0030.00517.71
8.0.300.0050.00518.77
8.0.290.0000.00817.13
8.0.280.0040.00418.82
8.0.270.0070.00017.42
8.0.260.0040.00417.01
8.0.250.0030.00517.28
8.0.240.0050.00217.21
8.0.230.0040.00417.27
8.0.220.0030.00617.07
8.0.210.0040.00417.16
8.0.200.0040.00417.30
8.0.190.0060.00317.32
8.0.180.0030.00617.29
8.0.170.0060.00317.24
8.0.160.0060.00317.21
8.0.150.0000.00817.17
8.0.140.0060.00317.05
8.0.130.0040.00413.63
8.0.120.0060.00317.00
8.0.110.0100.00017.32
8.0.100.0000.00817.11
8.0.90.0080.00017.10
8.0.80.0110.01117.20
8.0.70.0000.00817.23
8.0.60.0000.00917.24
8.0.50.0030.00517.03
8.0.30.0030.01717.13
8.0.20.0060.01317.24
8.0.10.0000.00817.38
8.0.00.0080.01216.99
7.4.330.0030.00313.20
7.4.320.0030.00316.88
7.4.300.0000.00716.77
7.4.290.0040.00416.75
7.4.280.0060.00316.71
7.4.270.0030.00316.76
7.4.260.0030.00313.54
7.4.250.0060.00316.74
7.4.240.0070.00016.75
7.4.230.0040.00416.84
7.4.220.0130.01316.77
7.4.210.0120.00916.66
7.4.200.0080.00016.59
7.4.190.0090.00016.81
7.4.160.0100.00716.77
7.4.150.0090.01116.74
7.4.140.0060.01617.86
7.4.130.0070.02016.79
7.4.120.0030.01416.58
7.4.110.0110.01116.70
7.4.100.0060.01616.91
7.4.90.0180.00316.70
7.4.80.0030.01819.39
7.4.70.0110.00716.88
7.4.60.0120.00616.68
7.4.50.0030.00316.71
7.4.40.0050.01116.70
7.4.30.0100.01016.69
7.4.00.0070.00714.95
7.3.330.0030.00313.42
7.3.320.0000.00613.59
7.3.310.0030.00516.44
7.3.300.0070.00016.55
7.3.290.0110.00816.63
7.3.280.0150.00016.52
7.3.270.0080.01116.82
7.3.260.0100.01016.87
7.3.240.0100.01016.59
7.3.230.0060.01216.75
7.3.210.0130.00616.53
7.3.200.0110.00816.73
7.3.190.0130.00716.88
7.3.180.0110.01116.87
7.3.170.0150.00616.91
7.3.160.0100.00716.62
7.3.120.0110.00715.00
7.2.330.0110.00816.71
7.2.320.0040.01616.80
7.2.310.0140.01116.98
7.2.300.0030.01417.05
7.2.290.0030.01616.70
7.2.00.0070.01019.29
7.1.100.0030.01318.05
7.1.70.0060.00616.93
7.1.60.0060.01919.21
7.1.50.0070.01816.69
7.1.00.0000.03722.57
7.0.200.0090.00916.64
7.0.140.0030.07721.95
7.0.120.0000.07722.04
7.0.100.0130.04020.27
7.0.90.0270.03720.22
7.0.80.0030.09020.15
7.0.70.0070.05720.13
7.0.60.0100.06720.27
7.0.50.0230.07720.41
7.0.40.0030.05320.11
7.0.30.0070.07020.09
7.0.20.0030.05320.06
7.0.10.0030.09320.09
7.0.00.0070.08320.00
5.6.280.0000.07321.03
5.6.250.0130.08020.89
5.6.240.0030.05020.82
5.6.230.0000.08720.75
5.6.220.0130.06720.68
5.6.210.0170.05720.86
5.6.200.0200.07721.18
5.6.190.0070.05021.26
5.6.180.0100.05021.15
5.6.170.0100.08021.15
5.6.160.0000.07321.17
5.6.150.0030.08321.14
5.6.140.0170.07321.17
5.6.130.0030.05721.16
5.6.120.0170.04321.16
5.6.110.0130.06321.21
5.6.100.0070.08321.07
5.6.90.0100.10021.17
5.6.80.0100.05020.52
5.6.70.0170.07020.46
5.6.60.0000.07020.56
5.6.50.0030.07720.57
5.6.40.0070.08020.52
5.6.30.0070.05320.51
5.6.20.0030.05020.55
5.6.10.0030.06720.49
5.6.00.0170.06720.55
5.5.380.0130.07720.57
5.5.370.0070.08020.64
5.5.360.0070.09720.61
5.5.350.0070.05020.55
5.5.340.0030.07320.89
5.5.330.0030.08721.05
5.5.320.0070.05720.99
5.5.310.0030.05021.00
5.5.300.0100.07320.88
5.5.290.0070.04020.77
5.5.280.0100.07720.92
5.5.270.0100.07021.02
5.5.260.0200.07320.92
5.5.250.0030.09020.66
5.5.240.0130.05020.28
5.5.230.0000.09020.40
5.5.220.0070.06320.27
5.5.210.0070.05020.43
5.5.200.0000.05320.27
5.5.190.0100.06720.21
5.5.180.0070.07720.31
5.5.160.0030.08320.36
5.5.150.0070.06720.18
5.5.140.0030.08320.37
5.5.130.0100.06720.24
5.5.120.0130.03720.38
5.5.110.0030.08320.35
5.5.100.0070.06320.28
5.5.90.0100.07720.23
5.5.80.0070.07720.27
5.5.70.0000.07020.30
5.5.60.0030.07720.18
5.5.50.0030.08320.16
5.5.40.0130.07320.26
5.5.30.0070.04720.16
5.5.20.0170.03320.12
5.5.10.0130.06320.16
5.5.00.0070.03720.16
5.4.450.0100.06719.40
5.4.440.0100.07319.38
5.4.430.0070.05319.41
5.4.420.0030.08319.55
5.4.410.0070.07319.43
5.4.400.0030.06719.24
5.4.390.0230.03018.95
5.4.380.0100.06319.09
5.4.370.0030.06319.04
5.4.360.0100.07019.06
5.4.350.0030.04719.17
5.4.340.0030.08018.96
5.4.320.0030.06019.00
5.4.310.0100.05019.27
5.4.300.0000.08018.94
5.4.290.0100.07018.94
5.4.280.0070.04019.23
5.4.270.0070.08019.00
5.4.260.0030.06319.08
5.4.250.0070.04319.12
5.4.240.0100.07019.23
5.4.230.0100.07718.99
5.4.220.0070.08019.12
5.4.210.0030.04319.13
5.4.200.0100.07719.23
5.4.190.0100.07319.00
5.4.180.0030.04318.90
5.4.170.0030.04019.27
5.4.160.0000.04018.93
5.4.150.0070.04019.08
5.4.140.0030.03316.55
5.4.130.0030.03016.42
5.4.120.0100.03016.47
5.4.110.0030.03016.58
5.4.100.0000.04016.58
5.4.90.0100.03016.53
5.4.80.0030.03316.36
5.4.70.0030.06716.59
5.4.60.0030.03716.54
5.4.50.0070.03716.42
5.4.40.0000.04316.39
5.4.30.0030.03716.45
5.4.20.0000.03716.51
5.4.10.0000.04016.56
5.4.00.0030.03715.78
5.3.290.0100.04314.89
5.3.280.0070.07314.89
5.3.270.0000.04014.76
5.3.260.0100.03314.84
5.3.250.0030.03014.74
5.3.240.0030.03714.78
5.3.230.0070.03014.80
5.3.220.0030.03014.72
5.3.210.0000.04014.77
5.3.200.0030.04014.72
5.3.190.0030.05714.77
5.3.180.0030.05014.71
5.3.170.0130.06314.79
5.3.160.0070.03314.77
5.3.150.0100.03314.78
5.3.140.0070.05714.82
5.3.130.0030.04314.75
5.3.120.0100.03014.73
5.3.110.0170.02314.89
5.3.100.0070.03714.33
5.3.90.0000.04014.20
5.3.80.0000.04014.15
5.3.70.0030.03714.27
5.3.60.0070.03714.23
5.3.50.0000.04014.25
5.3.40.0030.03714.21
5.3.30.0030.07014.20
5.3.20.0070.04014.00
5.3.10.0030.03713.92
5.3.00.0100.06713.81

preferences:
42.29 ms | 401 KiB | 5 Q