3v4l.org

run code in 300+ PHP versions simultaneously
<?php class EAHashor { private $right32; //initialise the class public function __construct() { // This is a 32- and 64-bit safe way to get an integer with only the // right-most 32-bits set $this->right32 = ~((-1 << 16) << 16); } public 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"); //the line below has been changed 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"); //this last line is used 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 */ private 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; } private 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 */ private 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 &$b) { $b = implode('', array_reverse(str_split($b, 8))); } return $block; } private 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 */ private 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; } private 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; } private 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; } private 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 */ private function FF(&$A, $B, $C, $D, $M, $s, $t){ $A = hexdec($A); $t = hexdec($t); $M = bindec($M); $A = $this->add($A, $this->F($B, $C, $D), $M, $t) & $this->right32; //decimal $A = $this->rotate($A, $s); $A = dechex($this->add(hexdec($B), hexdec($A)) & $this->right32); } private function GG(&$A, $B, $C, $D, $M, $s, $t){ $A = hexdec($A); $t = hexdec($t); $M = bindec($M); $A = $this->add($A, $this->G($B, $C, $D), $M, $t) & $this->right32; //decimal $A = $this->rotate($A, $s); $A = dechex($this->add(hexdec($B), hexdec($A)) & $this->right32); } private function HH(&$A, $B, $C, $D, $M, $s, $t){ $A = hexdec($A); $t = hexdec($t); $M = bindec($M); $A = $this->add($A, $this->H($B, $C, $D), $M, $t) & $this->right32; //decimal $A = $this->rotate($A, $s); $A = dechex($this->add(hexdec($B), hexdec($A)) & $this->right32); } private function II(&$A, $B, $C, $D, $M, $s, $t){ $A = hexdec($A); $t = hexdec($t); $M = bindec($M); $A = $this->add($A, $this->I($B, $C, $D), $M, $t) & $this->right32; //decimal $A = $this->rotate($A, $s); $A = dechex($this->add(hexdec($B), hexdec($A)) & $this->right32); } // shift private function rotate ($decimal, $bits) { //returns hex return dechex((($decimal << $bits) | ($decimal >> (32 - $bits))) & $this->right32); } private 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 = $this->add($aa, $A) & $this->right32; $bb = $this->add($bb, $B) & $this->right32; $cc = $this->add($cc, $C) & $this->right32; $dd = $this->add($dd, $D) & $this->right32; $a = dechex($aa); $b = dechex($bb); $c = dechex($cc); $d = dechex($dd); } private 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; } // shamelessly stolen from http://stackoverflow.com/a/4068918/889949 private function binarySafeAddition($a, $b) { $carry = $a & $b; $result = $a ^ $b; while($carry != 0) { $shiftedcarry = $carry << 1; $carry = $result & $shiftedcarry; $result ^= $shiftedcarry; } return $result; } private function add() { $result = 0; foreach (func_get_args() as $int) { $result = $this->binarySafeAddition($result, $int); } return $result; } } $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.0120.00416.88
8.3.50.0160.00521.98
8.3.40.0060.00919.04
8.3.30.0120.00319.43
8.3.20.0040.00420.45
8.3.10.0050.00323.28
8.3.00.0070.00319.51
8.2.180.0060.00918.54
8.2.170.0120.01222.96
8.2.160.0090.00620.42
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0060.00322.26
8.2.110.0090.00019.52
8.2.100.0040.00817.97
8.2.90.0000.00919.45
8.2.80.0030.00917.97
8.2.70.0090.00018.00
8.2.60.0080.00018.18
8.2.50.0090.00018.10
8.2.40.0050.00318.41
8.2.30.0060.00318.48
8.2.20.0050.00317.88
8.2.10.0000.00818.25
8.2.00.0080.00518.05
8.1.280.0070.00725.92
8.1.270.0090.00022.30
8.1.260.0030.00526.35
8.1.250.0060.00328.09
8.1.240.0060.00322.60
8.1.230.0090.00621.15
8.1.220.0080.00017.91
8.1.210.0030.00618.77
8.1.200.0040.00417.60
8.1.190.0030.00617.60
8.1.180.0030.00618.10
8.1.170.0080.00418.58
8.1.160.0000.01022.20
8.1.150.0000.00818.91
8.1.140.0000.00817.71
8.1.130.0090.00017.99
8.1.120.0000.00717.77
8.1.110.0080.00017.59
8.1.100.0000.00817.75
8.1.90.0050.00317.71
8.1.80.0000.00717.70
8.1.70.0050.00317.67
8.1.60.0090.00017.85
8.1.50.0060.00317.80
8.1.40.0060.00317.70
8.1.30.0040.00417.86
8.1.20.0080.00017.86
8.1.10.0060.00317.72
8.1.00.0050.00317.75
8.0.300.0080.00020.27
8.0.290.0050.00316.88
8.0.280.0030.00518.70
8.0.270.0020.00517.51
8.0.260.0070.00017.53
8.0.250.0000.00717.26
8.0.240.0060.00317.12
8.0.230.0030.00517.17
8.0.220.0000.00817.16
8.0.210.0030.00517.15
8.0.200.0030.00317.14
8.0.190.0000.00917.20
8.0.180.0050.00317.12
8.0.170.0040.00417.07
8.0.160.0040.00417.09
8.0.150.0040.00417.22
8.0.140.0040.00417.08
8.0.130.0070.00013.61
8.0.120.0040.00417.02
8.0.110.0080.00017.05
8.0.100.0030.00617.09
8.0.90.0030.00617.05
8.0.80.0030.01317.13
8.0.70.0060.00317.00
8.0.60.0030.00517.02
8.0.50.0040.00416.94
8.0.30.0090.01117.44
8.0.20.0110.00917.40
8.0.10.0000.00917.09
8.0.00.0090.01016.90
7.4.330.0070.00015.00
7.4.320.0030.00316.78
7.4.300.0000.00716.78
7.4.290.0040.00416.90
7.4.280.0000.00816.77
7.4.270.0060.00316.86
7.4.260.0060.00316.74
7.4.250.0040.00416.70
7.4.240.0000.00716.87
7.4.230.0040.00416.66
7.4.220.0080.01216.66
7.4.210.0020.01416.88
7.4.200.0000.00716.57
7.4.190.0040.00416.80
7.4.160.0060.01216.54
7.4.150.0030.01717.40
7.4.140.0110.00817.86
7.4.130.0130.00516.77
7.4.120.0070.01016.86
7.4.110.0110.00716.59
7.4.100.0100.01016.66
7.4.90.0060.01316.75
7.4.80.0080.01219.39
7.4.70.0070.01116.76
7.4.60.0130.00516.74
7.4.50.0040.00416.82
7.4.40.0040.00922.77
7.4.30.0060.01216.68
7.4.00.0000.01815.30
7.3.330.0000.00613.61
7.3.320.0060.00313.59
7.3.310.0050.00316.62
7.3.300.0000.00816.61
7.3.290.0070.01416.53
7.3.280.0090.01016.58
7.3.270.0090.01017.40
7.3.260.0040.01516.69
7.3.250.0100.00916.64
7.3.240.0060.01216.56
7.3.230.0120.00616.87
7.3.210.0060.01216.63
7.3.200.0040.02019.39
7.3.190.0090.01316.77
7.3.180.0070.01016.77
7.3.170.0060.01216.81
7.3.160.0000.01616.59
7.3.120.0060.00915.25
7.2.330.0090.00917.16
7.2.320.0090.00917.14
7.2.310.0060.01316.75
7.2.300.0110.00716.73
7.2.290.0090.00916.86
7.2.60.0000.01517.15
7.2.00.0000.01819.57
7.1.200.0060.00915.60
7.1.100.0090.00618.14
7.1.70.0060.01217.26
7.1.60.0070.01319.33
7.1.50.0200.01634.66
7.1.00.0100.07322.38
7.0.200.0090.00616.86
7.0.140.0030.07322.18
7.0.100.0100.07720.31
7.0.90.0230.06320.10
7.0.80.0070.04020.12
7.0.70.0000.04020.25
7.0.60.0000.04320.29
7.0.50.0030.06320.46
7.0.40.0030.06320.09
7.0.30.0030.04320.04
7.0.20.0000.05020.15
7.0.10.0130.05720.14
7.0.00.0070.04020.09
5.6.280.0130.06721.26
5.6.250.0170.07720.82
5.6.240.0100.08020.89
5.6.230.0100.08320.70
5.6.220.0070.04020.87
5.6.210.0030.05020.63
5.6.200.0030.06321.27
5.6.190.0030.04721.16
5.6.180.0070.04021.15
5.6.170.0100.04721.30
5.6.160.0070.04021.10
5.6.150.0100.04021.14
5.6.140.0070.04021.23
5.6.130.0070.04021.26
5.6.120.0130.04321.17
5.6.110.0170.04321.20
5.6.100.0070.08321.15
5.6.90.0070.06321.24
5.6.80.0070.03320.63
5.6.70.0030.04720.61
5.6.60.0030.04720.67
5.6.50.0070.03720.53
5.6.40.0100.06720.55
5.6.30.0130.03320.51
5.6.20.0030.04720.41
5.6.10.0030.03720.55
5.6.00.0130.07020.48
5.5.380.0100.08320.51
5.5.370.0100.04320.48
5.5.360.0030.04720.50
5.5.350.0030.04720.50
5.5.340.0000.04720.78
5.5.330.0030.04320.93
5.5.320.0000.04320.97
5.5.310.0030.04321.01
5.5.300.0070.04020.90
5.5.290.0070.04021.02
5.5.280.0000.04720.93
5.5.270.0030.04320.89
5.5.260.0100.05720.96
5.5.250.0130.03020.83
5.5.240.0030.04020.32
5.5.230.0070.03720.25
5.5.220.0100.03020.39
5.5.210.0070.07020.34
5.5.200.0000.04020.40
5.5.190.0070.05720.34
5.5.180.0130.07320.28
5.5.160.0100.07720.39
5.5.150.0030.05020.30
5.5.140.0030.05020.31
5.5.130.0130.04320.25
5.5.120.0130.07320.34
5.5.110.0100.04320.39
5.5.100.0100.08020.08
5.5.90.0070.06020.05
5.5.80.0100.06720.11
5.5.70.0070.04720.29
5.5.60.0070.07020.25
5.5.50.0030.08320.27
5.5.40.0100.06720.09
5.5.30.0070.03720.09
5.5.20.0100.07320.09
5.5.10.0070.07320.24
5.5.00.0070.07720.16
5.4.450.0000.04319.28
5.4.440.0030.04019.28
5.4.430.0000.04719.24
5.4.420.0070.07719.43
5.4.410.0000.04319.42
5.4.400.0070.03719.18
5.4.390.0030.04019.08
5.4.380.0030.04319.04
5.4.370.0100.06719.21
5.4.360.0100.04319.08
5.4.350.0000.04319.10
5.4.340.0100.07018.92
5.4.320.0130.05018.94
5.4.310.0000.07719.18
5.4.300.0000.08319.27
5.4.290.0100.07719.01
5.4.280.0100.05319.13
5.4.270.0170.06318.95
5.4.260.0100.07319.17
5.4.250.0100.06018.93
5.4.240.0100.06319.20
5.4.230.0000.07319.21
5.4.220.0030.07319.24
5.4.210.0070.07319.24
5.4.200.0000.07719.16
5.4.190.0130.06719.00
5.4.180.0070.05019.16
5.4.170.0000.04319.07
5.4.160.0070.07718.93
5.4.150.0100.07019.20
5.4.140.0070.07016.36
5.4.130.0030.07316.50
5.4.120.0070.07316.48
5.4.110.0030.07716.45
5.4.100.0170.06716.39
5.4.90.0130.07016.45
5.4.80.0070.05716.54
5.4.70.0130.06716.52
5.4.60.0100.07016.48
5.4.50.0030.04316.46
5.4.40.0070.07716.57
5.4.30.0100.07016.50
5.4.20.0170.06316.36
5.4.10.0030.07716.57
5.4.00.0070.04715.83
5.3.290.0100.05714.87
5.3.280.0030.04014.82
5.3.270.0070.04014.86
5.3.260.0200.07014.95
5.3.250.0070.08014.82
5.3.240.0100.07014.93
5.3.230.0070.07714.85
5.3.220.0030.04714.86
5.3.210.0000.07714.74
5.3.200.0130.07314.86
5.3.190.0000.06714.88
5.3.180.0100.07714.76
5.3.170.0070.07014.77
5.3.160.0100.07314.84
5.3.150.0030.06314.74
5.3.140.0030.07314.70
5.3.130.0070.07714.76
5.3.120.0070.08014.79
5.3.110.0000.07714.70
5.3.100.0070.07714.32
5.3.90.0070.07314.30
5.3.80.0070.07314.29
5.3.70.0070.06714.25
5.3.60.0030.07714.28
5.3.50.0070.07314.25
5.3.40.0030.05714.25
5.3.30.0030.04714.25
5.3.20.0100.05714.25
5.3.10.0130.06314.25
5.3.00.0100.07014.25

preferences:
41.84 ms | 401 KiB | 5 Q