1 c# passwords algorithm textbox brute-force
我想创建一个"测试密码"的程序,看看它们需要多长时间才能打破基本的暴力攻击.所以我做的是制作2个文本框.(textbox1和textbox2)编写程序所以如果文本框有输入,会出现一个"正确的密码"标签,但我想编写程序,以便在其中textbox2运行一个强力算法,当它遇到正确的密码,它会停止.我真的需要帮助,如果你可以在我的附加代码中添加正确的添加剂,这将是非常好的.到目前为止,该程序非常简单,但我对此非常陌生,所以.
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox2.Text == textBox1.Text)
{
label1.Text = "Password Correct";
}
else
{
label1.Text = "Password Wrong";
}
}
private void label1_Click(object sender, EventArgs e)
{
}
Run Code Online (Sandbox Code Playgroud)
使用这个简单的强力类来"破解"你的密码.我把这里的最大尺寸设置为3,所以我不必等待太久.如果你有一整天都增加这个!
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 >= MaxSize)
{
return false;
}
//Increment the previous digit (Uses recursion!)
IncrementDigit(_currentLength);
return true;
}
/// <summary>
/// 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.
/// </summary>
/// <param name="digitIndex"></param>
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 < 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 >= MaxSize)
{
return;
}
//Initialis as min ASCII.
CurrentGuess[_currentLength] = (char) (MinAscii);
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,使用如下所示的类:
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";
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8512 次 |
| 最近记录: |