Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use this simple, brute force class to 'crack' your password. I've set the maximum size here to <strong>3</strong>, so I didn't have to wait too long. Increase this if you've got all day!</p> <pre><code>private class BrutePasswordGuesser { private const int MaxAscii = 126; private const int MaxSize = 3; private const int MinAscii = 33; private int _currentLength; public BrutePasswordGuesser() { //Init the length, and current guess array. _currentLength = 0; CurrentGuess = new char[MaxSize]; CurrentGuess[0] = (char) MinAscii; } public char[] CurrentGuess { get; private set; } public bool NextGuess() { if (_currentLength &gt;= MaxSize) { return false; } //Increment the previous digit (Uses recursion!) IncrementDigit(_currentLength); return true; } /// &lt;summary&gt; /// Increment the character at the index by one. If the character is at the maximum /// ASCII value, set it back to the minimum, and increment the previous character. /// Use recursion to do this, so that the proggy will step all the way back as needed. /// If the very bottom of the string is reached, add another character to the guess. /// &lt;/summary&gt; /// &lt;param name="digitIndex"&gt;&lt;/param&gt; private void IncrementDigit(int digitIndex) { //Don't fall out the bottom of the array. //If we're at the bottom of the array, add another character if (digitIndex &lt; 0) { AddCharacter(); } else { //If the current character is max ASCII, set to min ASCII, and increment the previous char. if (CurrentGuess[digitIndex] == (char) MaxAscii) { CurrentGuess[digitIndex] = (char) MinAscii; IncrementDigit(digitIndex - 1); } else { CurrentGuess[digitIndex]++; } } } private void AddCharacter() { _currentLength++; //If we've reached our maximum guess size, leave now and don't come back. if (_currentLength &gt;= MaxSize) { return; } //Initialis as min ASCII. CurrentGuess[_currentLength] = (char) (MinAscii); } } </code></pre> <p>In your example above, use the class like this:</p> <pre><code>private void button1_Click(object sender, EventArgs e) { var guesser = new BrutePasswordGuesser(); var guess = new String(guesser.CurrentGuess); while (textBox1.Text != guess) { textBox2.Text = guess; if (!guesser.NextGuess()) { label1.Text = "Maximum guess size reached."; break; } guess = new String(guesser.CurrentGuess); } if (textBox1.Text == textBox2.Text) { Label1.Text = "Password Correct"; } } </code></pre>
    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.
    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.
    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