Note that there are some explanatory texts on larger screens.

plurals
  1. POPerformance tuning C# permutations and SHA1 code
    primarykey
    data
    text
    <p>Although this is a university assignment (homework) I've come to the best solution I could think of. I would achieve full marks with this code as it matches the question, however I was specially allowed to develop it in C# rather than everyone else using Java, kind of a "yeh, show what c# can do" challenge ;-)</p> <p>The question was:</p> <p>Create a program to find the password of a SHA1 hash using a brute force technique, assuming passwords are 6 characters long and can only contain lower-case a-z and 0-9.</p> <p>I created a LINQ query and after I have the possible combinations I need to run them through SHA1 to get a hash and compare it to the provided password hash.</p> <p>I created this code:</p> <pre><code>public static string BruteForceHash(string hash) { var results = from c0 in Enumerable.Range(0, 36) from c1 in Enumerable.Range(0, 36) from c2 in Enumerable.Range(0, 36) from c3 in Enumerable.Range(0, 36) from c4 in Enumerable.Range(0, 36) from c5 in Enumerable.Range(0, 36) select new string( new[] { Characters[c0], Characters[c1], Characters[c2], Characters[c3], Characters[c4], Characters[c5], } ); string found = null; Parallel.ForEach(results, (result, loopstate, a) =&gt; { string hashed = SHA1(result, Encoding.Default); if (hashed == hash) { found = result; loopstate.Break(); } }); if (found != null) { return found; } return "Not found."; } </code></pre> <p>Now my real problem is that it solved easy passwords quickly ("aaaaaa" is instant) but obviously takes longer the further the password is away from "aaaaaa".</p> <p>I would hope someone could provide some pointers on how to increase the performance.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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