PHP script to find if an MD5 hashes to itself? -


this hypothetical program- there 2^128 combinations (or 2^128-1? not sure. or should 128 replaced 127?) doesn't work.

<?php  $end = (int)base_convert("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",36,10); $count = 0; for($count = 0; $count < $end; $count++) {     $starthash = base_convert((string)$count,10,36);     //add zeros beginning if length less 32     while(strlen($starthash) < 32) {         $starthash = "0" + $starthash;     }     $endhash = md5($starthash);     if($starthash == $endhash) {         file_put_contents("md5.txt", file_get_contents("md5.txt") + $starthash + "\n");     } }  ?> 

i'm not sure why; doesn't throw errors. i'm expecting uses 100% of cpu, doesn't use more 0.1%.

do have idea what's going on?

like mike says, casing wrong. besides that, md5 hash 16 character value represented in 32 bytes let consist of letters , numbers. will, in case, consist of numbers 0 9 , letters f (or f?), need check those. make wrong assumption 32 character md5 code base 36 number.

the md5 function has second parameter allows 16 byte raw code.

another problem may face php not fast , has time-out. may better write program in different language, add threading, , save value regularly, can resume program after shutdown.

[edit] maybe give idea of how long wait. md5 = 16 bytes = 4 integer maximum of 4 billion ($ffffffff) each. loop through values of these 16 bytes, need nest 4 loops each run 4 billion:

<? for($a = 0; $a <= 0xffffffff; $a++){     for($b = 0; $b <= 0xffffffff; $b++){         for($c = 0; $d <= 0xffffffff; $c++){             for($d = 0; $d <= 0xffffffff; $d++){                 $code =                      str_pad(dechex($a), 8, "0", str_pad_left).                     str_pad(dechex($b), 8, "0", str_pad_left).                     str_pad(dechex($c), 8, "0", str_pad_left).                     str_pad(dechex($d), 8, "0", str_pad_left);                 $md5code = md5($code);                 if ($code == $md5code)                 {                     echo $code . "\n"; // found 1                 }             }         }     } } echo 'done'; 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -