PageRenderTime 61ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/code/eahashor.php

https://github.com/ComputerScientistPHD/FIFA13-Ultimate-Team-Search
PHP | 296 lines | 241 code | 36 blank | 19 comment | 10 complexity | baa721041776c5024fa8d05a385cb2c3 MD5 | raw file
  1. <?php
  2. echo MD("password");
  3. function MD($string){
  4. $a = "67452301";
  5. $b = "EFCDAB89";
  6. $c = "98BADCFE";
  7. $d = "10325476";
  8. $words = init($string);
  9. for($i = 0; $i <= count($words)/16-1; $i++){
  10. $A = $a;
  11. $B = $b;
  12. $C = $c;
  13. $D = $d;
  14. /* ROUND 1 */
  15. FF ($A, $B, $C, $D, $words[0 + ($i * 16)], 7, "d76aa478");
  16. FF ($D, $A, $B, $C, $words[1 + ($i * 16)], 12, "e8c7b756");
  17. FF ($C, $D, $A, $B, $words[2 + ($i * 16)], 17, "242070db");
  18. FF ($B, $C, $D, $A, $words[3 + ($i * 16)], 22, "c1bdceee");
  19. FF ($A, $B, $C, $D, $words[4 + ($i * 16)], 7, "f57c0faf");
  20. FF ($D, $A, $B, $C, $words[5 + ($i * 16)], 12, "4787c62a");
  21. FF ($C, $D, $A, $B, $words[6 + ($i * 16)], 17, "a8304613");
  22. FF ($B, $C, $D, $A, $words[7 + ($i * 16)], 22, "fd469501");
  23. FF ($A, $B, $C, $D, $words[8 + ($i * 16)], 7, "698098d8");
  24. FF ($D, $A, $B, $C, $words[9 + ($i * 16)], 12, "8b44f7af");
  25. FF ($C, $D, $A, $B, $words[10 + ($i * 16)], 17, "ffff5bb1");
  26. FF ($B, $C, $D, $A, $words[11 + ($i * 16)], 22, "895cd7be");
  27. FF ($A, $B, $C, $D, $words[12 + ($i * 16)], 7, "6b901122");
  28. FF ($D, $A, $B, $C, $words[13 + ($i * 16)], 12, "fd987193");
  29. FF ($C, $D, $A, $B, $words[14 + ($i * 16)], 17, "a679438e");
  30. FF ($B, $C, $D, $A, $words[15 + ($i * 16)], 22, "49b40821");
  31. /* ROUND 2 */
  32. GG ($A, $B, $C, $D, $words[1 + ($i * 16)], 5, "f61e2562");
  33. GG ($D, $A, $B, $C, $words[6 + ($i * 16)], 9, "c040b340");
  34. GG ($C, $D, $A, $B, $words[11 + ($i * 16)], 14, "265e5a51");
  35. GG ($B, $C, $D, $A, $words[0 + ($i * 16)], 20, "e9b6c7aa");
  36. GG ($A, $B, $C, $D, $words[5 + ($i * 16)], 5, "d62f105d");
  37. GG ($D, $A, $B, $C, $words[10 + ($i * 16)], 9, "02441453");
  38. GG ($C, $D, $A, $B, $words[15 + ($i * 16)], 14, "d8a1e681");
  39. GG ($B, $C, $D, $A, $words[4 + ($i * 16)], 20, "e7d3fbc8");
  40. GG ($A, $B, $C, $D, $words[9 + ($i * 16)], 5, "21e1cde6");
  41. GG ($D, $A, $B, $C, $words[14 + ($i * 16)], 9, "c33707d6");
  42. GG ($C, $D, $A, $B, $words[3 + ($i * 16)], 14, "f4d50d87");
  43. GG ($B, $C, $D, $A, $words[8 + ($i * 16)], 20, "455a14ed");
  44. GG ($A, $B, $C, $D, $words[13 + ($i * 16)], 5, "a9e3e905");
  45. GG ($D, $A, $B, $C, $words[2 + ($i * 16)], 9, "fcefa3f8");
  46. GG ($C, $D, $A, $B, $words[7 + ($i * 16)], 14, "676f02d9");
  47. GG ($B, $C, $D, $A, $words[12 + ($i * 16)], 20, "8d2a4c8a");
  48. /* ROUND 3 */
  49. HH ($A, $B, $C, $D, $words[5 + ($i * 16)], 4, "fffa3942");
  50. HH ($D, $A, $B, $C, $words[8 + ($i * 16)], 11, "8771f681");
  51. //HH ($C, $D, $A, $B, $words[11 + ($i * 16)], 16, "6d9d6122");
  52. //EA change to use 14 rather than 16 as seen in the commented line
  53. HH ($C, $D, $A, $B, $words[11 + ($i * 16)], 14, "6d9d6122");
  54. HH ($B, $C, $D, $A, $words[14 + ($i * 16)], 23, "fde5380c");
  55. HH ($A, $B, $C, $D, $words[1 + ($i * 16)], 4, "a4beea44");
  56. HH ($D, $A, $B, $C, $words[4 + ($i * 16)], 11, "4bdecfa9");
  57. HH ($C, $D, $A, $B, $words[7 + ($i * 16)], 16, "f6bb4b60");
  58. HH ($B, $C, $D, $A, $words[10 + ($i * 16)], 23, "bebfbc70");
  59. HH ($A, $B, $C, $D, $words[13 + ($i * 16)], 4, "289b7ec6");
  60. HH ($D, $A, $B, $C, $words[0 + ($i * 16)], 11, "eaa127fa");
  61. HH ($C, $D, $A, $B, $words[3 + ($i * 16)], 16, "d4ef3085");
  62. HH ($B, $C, $D, $A, $words[6 + ($i * 16)], 23, "04881d05");
  63. HH ($A, $B, $C, $D, $words[9 + ($i * 16)], 4, "d9d4d039");
  64. HH ($D, $A, $B, $C, $words[12 + ($i * 16)], 11, "e6db99e5");
  65. HH ($C, $D, $A, $B, $words[15 + ($i * 16)], 16, "1fa27cf8");
  66. HH ($B, $C, $D, $A, $words[2 + ($i * 16)], 23, "c4ac5665");
  67. /* ROUND 4 */
  68. II ($A, $B, $C, $D, $words[0 + ($i * 16)], 6, "f4292244");
  69. II ($D, $A, $B, $C, $words[7 + ($i * 16)], 10, "432aff97");
  70. II ($C, $D, $A, $B, $words[14 + ($i * 16)], 15, "ab9423a7");
  71. II ($B, $C, $D, $A, $words[5 + ($i * 16)], 21, "fc93a039");
  72. II ($A, $B, $C, $D, $words[12 + ($i * 16)], 6, "655b59c3");
  73. II ($D, $A, $B, $C, $words[3 + ($i * 16)], 10, "8f0ccc92");
  74. II ($C, $D, $A, $B, $words[10 + ($i * 16)], 15, "ffeff47d");
  75. II ($B, $C, $D, $A, $words[1 + ($i * 16)], 21, "85845dd1");
  76. II ($A, $B, $C, $D, $words[8 + ($i * 16)], 6, "6fa87e4f");
  77. II ($D, $A, $B, $C, $words[15 + ($i * 16)], 10, "fe2ce6e0");
  78. II ($C, $D, $A, $B, $words[6 + ($i * 16)], 15, "a3014314");
  79. II ($B, $C, $D, $A, $words[13 + ($i * 16)], 21, "4e0811a1");
  80. II ($A, $B, $C, $D, $words[4 + ($i * 16)], 6, "f7537e82");
  81. II ($D, $A, $B, $C, $words[11 + ($i * 16)], 10, "bd3af235");
  82. II ($C, $D, $A, $B, $words[2 + ($i * 16)], 15, "2ad7d2bb");
  83. II ($B, $C, $D, $A, $words[9 + ($i * 16)], 21, "eb86d391");
  84. //EA change to use this last line twice
  85. II ($B, $C, $D, $A, $words[9 + ($i * 16)], 21, "eb86d391");
  86. addVars($a, $b, $c, $d, $A, $B, $C, $D);
  87. }
  88. $MD5 = '';
  89. foreach (array($a, $b, $c, $d) as $x) {
  90. $MD5 .= implode('', array_reverse(str_split(leftpad($x, 8), 2)));
  91. }
  92. return $MD5;
  93. }
  94. /* General functions */
  95. function hexbin($str){
  96. $hexbinmap = array( "0" => "0000",
  97. "1" => "0001",
  98. "2" => "0010",
  99. "3" => "0011"
  100. , "4" => "0100"
  101. , "5" => "0101"
  102. , "6" => "0110"
  103. , "7" => "0111"
  104. , "8" => "1000"
  105. , "9" => "1001"
  106. , "A" => "1010"
  107. , "a" => "1010"
  108. , "B" => "1011"
  109. , "b" => "1011"
  110. , "C" => "1100"
  111. , "c" => "1100"
  112. , "D" => "1101"
  113. , "d" => "1101"
  114. , "E" => "1110"
  115. , "e" => "1110"
  116. , "F" => "1111"
  117. , "f" => "1111");
  118. $bin = "";
  119. for ($i = 0; $i < strlen($str); $i++){
  120. $bin .= $hexbinmap[$str[$i]];
  121. }
  122. $bin = ltrim($bin, '0');
  123. // echo "Original: ".$str." New: ".$bin."<br />";
  124. return $bin;
  125. }
  126. function strhex($str){
  127. $hex = "";
  128. for ($i = 0; $i < strlen($str); $i++){
  129. $hex = $hex.leftpad(dechex(ord($str[$i])), 2);
  130. }
  131. return $hex;
  132. }
  133. /* MD5-specific functions */
  134. function init($string){
  135. $len = strlen($string) * 8;
  136. $hex = strhex($string); // convert ascii string to hex
  137. $bin = leftpad(hexbin($hex), $len); // convert hex string to bin
  138. $padded = pad($bin);
  139. $padded = pad($padded, 1, $len);
  140. $block = str_split($padded, 32);
  141. foreach ($block as &$b) {
  142. $b = implode('', array_reverse(str_split($b, 8)));
  143. }
  144. return $block;
  145. }
  146. function pad($bin, $type=0, $len = 0){
  147. if($type == 0){
  148. $bin = $bin."1";
  149. $buff = strlen($bin) % 512;
  150. if($buff != 448){
  151. while(strlen($bin) % 512 != 448){
  152. $bin = $bin."0";
  153. }
  154. }
  155. }
  156. // append length (b) of string to latter 64 bits
  157. elseif($type == 1){
  158. $bLen = leftpad(decbin($len), 64);
  159. $bin .= implode('', array_reverse(str_split($bLen, 8)));
  160. }
  161. return $bin;
  162. }
  163. /* MD5 base functions */
  164. function F($X, $Y, $Z){
  165. $X = hexdec($X);
  166. $Y = hexdec($Y);
  167. $Z = hexdec($Z);
  168. $calc = (($X & $Y) | ((~ $X) & $Z)); // X AND Y OR NOT X AND Z
  169. return $calc;
  170. }
  171. function G($X, $Y, $Z){
  172. $X = hexdec($X);
  173. $Y = hexdec($Y);
  174. $Z = hexdec($Z);
  175. $calc = (($X & $Z) | ($Y & (~ $Z))); // X AND Z OR Y AND NOT Z
  176. return $calc;
  177. }
  178. function H($X, $Y, $Z){
  179. $X = hexdec($X);
  180. $Y = hexdec($Y);
  181. $Z = hexdec($Z);
  182. $calc = ($X ^ $Y ^ $Z); // X XOR Y XOR Z
  183. return $calc;
  184. }
  185. function I($X, $Y, $Z){
  186. $X = hexdec($X);
  187. $Y = hexdec($Y);
  188. $Z = hexdec($Z);
  189. $calc = ($Y ^ ($X | (~ $Z))) ; // Y XOR (X OR NOT Z)
  190. return $calc;
  191. }
  192. /* MD5 round functions */
  193. /* $A - hex, $B - hex, $C - hex, $D - hex (F - dec)
  194. $M - binary
  195. $s - decimal
  196. $t - hex
  197. */
  198. function FF(&$A, $B, $C, $D, $M, $s, $t){
  199. $A = hexdec($A);
  200. $t = hexdec($t);
  201. $M = bindec($M);
  202. $A = ($A + F($B, $C, $D) + $M + $t) & 0xffffffff; //decimal
  203. $A = rotate($A, $s);
  204. $A = dechex((hexdec($B) + hexdec($A)) & 0xffffffff);
  205. }
  206. function GG(&$A, $B, $C, $D, $M, $s, $t){
  207. $A = hexdec($A);
  208. $t = hexdec($t);
  209. $M = bindec($M);
  210. $A = ($A + G($B, $C, $D) + $M + $t) & 0xffffffff; //decimal
  211. $A = rotate($A, $s);
  212. $A = dechex((hexdec($B) + hexdec($A)) & 0xffffffff);
  213. }
  214. function HH(&$A, $B, $C, $D, $M, $s, $t){
  215. $A = hexdec($A);
  216. $t = hexdec($t);
  217. $M = bindec($M);
  218. $A = ($A + H($B, $C, $D) + $M + $t) & 0xffffffff; //decimal
  219. $A = rotate($A, $s);
  220. $A = dechex((hexdec($B) + hexdec($A)) & 0xffffffff);
  221. }
  222. function II(&$A, $B, $C, $D, $M, $s, $t){
  223. $A = hexdec($A);
  224. $t = hexdec($t);
  225. $M = bindec($M);
  226. $A = ($A + I($B, $C, $D) + $M + $t) & 0xffffffff; //decimal
  227. $A = rotate($A, $s);
  228. $A = dechex((hexdec($B) + hexdec($A)) & 0xffffffff);
  229. }
  230. // shift
  231. function rotate ($decimal, $bits) { //returns hex
  232. return dechex((($decimal << $bits) | ($decimal >> (32 - $bits))) & 0xffffffff);
  233. }
  234. function addVars(&$a, &$b, &$c, &$d, $A, $B, $C, $D){
  235. $A = hexdec($A);
  236. $B = hexdec($B);
  237. $C = hexdec($C);
  238. $D = hexdec($D);
  239. $aa = hexdec($a);
  240. $bb = hexdec($b);
  241. $cc = hexdec($c);
  242. $dd = hexdec($d);
  243. $aa = ($aa + $A) & 0xffffffff;
  244. $bb = ($bb + $B) & 0xffffffff;
  245. $cc = ($cc + $C) & 0xffffffff;
  246. $dd = ($dd + $D) & 0xffffffff;
  247. $a = dechex($aa);
  248. $b = dechex($bb);
  249. $c = dechex($cc);
  250. $d = dechex($dd);
  251. }
  252. function leftpad($needs_padding, $alignment) {
  253. if (strlen($needs_padding) % $alignment) {
  254. $pad_amount = $alignment - strlen($needs_padding) % $alignment;
  255. $left_pad = implode('', array_fill(0, $pad_amount, '0'));
  256. $needs_padding = $left_pad . $needs_padding;
  257. }
  258. return $needs_padding;
  259. }
  260. ?>