我想做一个“测试密码”的程序,看看他们需要多长时间才能破解基本的暴力破解攻击。所以我做的就是做两个文本框。(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)
{
}
发布于 2010-04-07 06:13:57
使用这个简单的暴力破解类来“破解”你的密码。我在这里设置了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);
}
}
在上面的示例中,使用如下类:
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";
}
}
发布于 2010-04-06 06:30:22
需要更多信息;您是否在随机猜测密码?字典攻击?你是按顺序猜密码的吗?密码中使用的长度/字符集还有哪些其他限制?
我将假设您的程序在UI中自动调用这些尝试,而不是您作为用户。如果是这样的话,我会抛弃UI策略,转而使用控制台实现。
“随机”猜测问题之所以重要,是因为如果你按顺序猜测,它所需的时间长度与你选择的密码直接相关。我不确定你想要的结果是什么。
https://stackoverflow.com/questions/2581532
复制相似问题