我想打一个程序,“测试的密码”,看看他们需要多长时间一个基本的蛮力攻击打破。因此,我所做的只是让两个文本框。 (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)
{

}
有帮助吗?

解决方案

使用这个简单的,强力班“破解”您的密码。我在这里设置的最大尺寸为 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";
    }
}

其他提示

需要更多的信息;你猜的随机密码?字典攻击?你猜密码顺序?在密码中使用的长度/字符集什么其它约束有哪些?

我要假设你的程序会自动调用这些尝试,而不是作为用户的您,在UI中。如果是这样的话,我会沟UI战略以及与控制台实现去了。

一个原因“随机”猜测的问题是很重要的,因为如果你连续猜,时间将采取长短直接关系到你选择什么样的密码。我不知道是什么结果,你所期待的。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top