Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are doing a "<a href="http://en.wikipedia.org/wiki/Depth-first_search" rel="nofollow">Depth first</a>" search (and of unlimited depth!), this is almost guaranteed to fail ( exhausting your stack) if you do not add some depth check.</p> <p>You <s>should probably better</s> might want to do a <a href="http://en.wikipedia.org/wiki/Breadth-first_search" rel="nofollow">Breadth first search</a> : your loop should first try all the combinations that results in adding a character, and only then, if no success, try to recursively call the method with each augmented string.</p> <p>In any case, you should add some depth check, always.</p> <p>Edited: thinking it twice, I'm not so sure you should not stick with depth first. Breadth first is only rasonable here for small depths and combinations (character ranges). A possible implementation</p> <pre><code> // Breadth first returns null if not found public String bruteforce(List&lt;String&gt; prefixes, String md5,int availdepth) { if(availabledepth&lt;0) return null; List&lt;String&gt; newprefixes = new ArrayList&lt;String&gt;(); for(String prefix : prefixes) { for (char c = ' '; c &lt; '~'; ++c) { String attempt = prefix + Character.toString(c); generatedMd5 = generateMD5(attempt); if (hashesMatch(md5, generatedMd5)) return attempt; newprefixes.add(attempt); } } // no success in this level go for next return bruteforce(newprefixes,md5,availddepth-1); } // Depth first - returns null if not found public String bruteforce(String prefix, String md5,int availdepth) { if(availdepth &lt;= 0) return null; for (char c = ' '; c &lt; '~'; ++c) { String attempt = prefix + Character.toString(c); if (hashesMatch(md5, generateMD5(attempt))) return attempt; String res = bruteforce(attempt, md5, availdepth-1); if(res != null) return res; } return null; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload