1

我想制作一个“测试密码”的程序,看看他们需要多长时间才能打破基本的暴力攻击。所以我所做的是制作 2 个文本框。(textbox1textbox2)并编写了程序,因此如果文本框有输入,则会出现“正确的密码”标签,但我想编写程序以便在其中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)
{

}
4

2 回答 2

5

使用这个简单的蛮力类来“破解”您的密码。我在这里将最大尺寸设置为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-06T22:13:56.647 回答
0

需要更多信息;你在随机猜密码吗?字典攻击?你是按顺序猜密码的吗?密码中使用的长度/字符集还有哪些其他限制?

我将假设您的程序在 UI 中自动调用这些尝试,而不是您作为用户。如果是这种情况,我会放弃 UI 策略并使用控制台实现。

“随机”猜测问题很重要的一个原因是,如果您按顺序猜测,所花费的时间长度与您选择的密码直接相关。我不确定你在寻找什么结果。

于 2010-04-05T22:30:22.003 回答