Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#bruteforce应用程序不';调试时不打印任何内容,密码长度超过1个字母时终止_C#_.net Core_Stack Overflow_Brute Force - Fatal编程技术网

C#bruteforce应用程序不';调试时不打印任何内容,密码长度超过1个字母时终止

C#bruteforce应用程序不';调试时不打印任何内容,密码长度超过1个字母时终止,c#,.net-core,stack-overflow,brute-force,C#,.net Core,Stack Overflow,Brute Force,我制作了这个“bruteforce”程序,但当我使用算法2运行它时,密码超过1个字母,它停止并说:进程因StackOverflowException而终止。 另外,当我尝试调试它时,它不会启动并询问算法编号。我做错了什么?(我知道代码不好,但您仍然可以给我反馈和改进意见。) 在Linux和VSCode上使用.NET内核 class Program { static string chars = "- -a-b-c-d-e-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v

我制作了这个“bruteforce”程序,但当我使用算法2运行它时,密码超过1个字母,它停止并说:
进程因StackOverflowException而终止。
另外,当我尝试调试它时,它不会启动并询问算法编号。我做错了什么?(我知道代码不好,但您仍然可以给我反馈和改进意见。)

在Linux和VSCode上使用.NET内核

class Program
{
    static string chars = "- -a-b-c-d-e-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-A-B-C-D-E-F-G-H-I-J-K-L-M-N-O-P-Q-R-S-T-U-V-W-X-Y-Z-0-1-2-3-4-5-6-7-8-9";
    static string[] c = chars.Split("-");
    static string password = "";
    static string attempt = "";
    static Stopwatch sw = new Stopwatch();
    static int i_max_length = 1;

    static char first = Char.Parse(Char.ConvertFromUtf32(32));
    static char last = Char.Parse(Char.ConvertFromUtf32(126));

    static void Main(string[] args)
    {
        Console.ForegroundColor = ConsoleColor.Magenta;
        Console.Write("Algorithm: (1/2) ");
        string algorithm = Console.ReadLine();
        Console.Clear();

        Console.ForegroundColor = ConsoleColor.Cyan;
        Console.Write("Enter password: ");
        password = Console.ReadLine();
        Console.Clear();

        Program.sw.Start();

        if (algorithm == "1")
        {
            Start("");
        }
        else if (algorithm == "2")
        {
            CharForce("");
        }
    }
    static void Start(string previous)
    {
        if (previous.Length >= i_max_length)
            return;

        foreach (string ch in Program.c)
        {
            attempt = previous + ch;
            //Console.WriteLine("{0}", attempt);
            if (attempt == password)
            {
                Program.sw.Stop();
                TimeSpan time = sw.Elapsed;
                Console.WriteLine("Password: {0}", attempt);
                Console.WriteLine("Time elapsed: {0}", time.ToString());
                Environment.Exit(0);
            }
        }

        foreach (string ch in Program.c)
        {
            Start(previous + ch);
        }
    }
    static void CharForce(string p)
    {
        if (attempt != password)
        {
            if (p.Length >= i_max_length)
                return;

            for (char f = first; f <= last; f++)
            {
                attempt = p + f;
                CharForce(p + f);
            }
        }
        else
        {
            Program.sw.Stop();
            TimeSpan time = sw.Elapsed;
            Console.WriteLine("Password: {0}", attempt);
            Console.WriteLine("Time elapsed: {0}", time.ToString());
            Environment.Exit(0);
        }
    }
}
类程序
{
静态字符串字符“--a-b-c-d-e-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z-a-b-c-d-e-f-g-h-i-j-k-l-m-o-p-q-r-s-t-v-w-x-y-z-a-b-c-d-e-f-g-h-i-j-k-l-m-o-p-q-r-r-s-t-u-w-w-w-w-x-x-y-y-y-y-z-z-z-z-z-z-0-1-;
静态字符串[]c=chars.Split(“-”);
静态字符串密码=”;
静态字符串尝试=”;
静态秒表sw=新秒表();
静态int i_max_length=1;
静态char first=char.Parse(char.ConvertFromUtf32(32));
静态char last=char.Parse(char.ConvertFromUtf32(126));
静态void Main(字符串[]参数)
{
Console.ForegroundColor=ConsoleColor.Pigenta;
编写(“算法:(1/2)”;
字符串算法=Console.ReadLine();
Console.Clear();
Console.ForegroundColor=ConsoleColor.Cyan;
控制台。写入(“输入密码:”);
password=Console.ReadLine();
Console.Clear();
Program.sw.Start();
如果(算法==“1”)
{
开始(“”);
}
else if(算法==“2”)
{
CharForce(“”);
}
}
静态无效开始(上一个字符串)
{
如果(previous.Length>=i_max_Length)
返回;
foreach(Program.c中的字符串ch)
{
尝试=上一次+ch;
//WriteLine(“{0}”,尝试);
如果(尝试==密码)
{
Program.sw.Stop();
TimeSpan时间=经过的软件时间;
WriteLine(“密码:{0}”,尝试);
WriteLine(“经过的时间:{0}”,Time.ToString());
环境。退出(0);
}
}
foreach(Program.c中的字符串ch)
{
启动(上一个+ch);
}
}
静态孔隙压力(管柱p)
{
如果(尝试!=密码)
{
如果(p.Length>=i_max_Length)
返回;

对于(char f=first;f如果您得到无限递归,或者至少是一个如此大的东西,以至于Windows决定“可能无限”——并终止该行,那么您将得到
StackOverflowException

您没有指定异常来自哪一行,但递归包含在以下两部分中:

    foreach (string ch in Program.c)
    {
        Start(previous + ch);
    }



    for (char f = first; f <= last; f++)
    {
        attempt = p + f;
        CharForce(p + f);
    }
foreach(Program.c中的字符串ch)
{
启动(上一个+ch);
}

对于(char f=first;f要获得
StackOverflowException
您不一定需要无限递归-一个深度超过堆栈大小的简单递归足以获得此异常。顺便说一句,Windows对此没有任何决定-当违反堆栈边界时,异常由SEH引发,然后由.NET运行时引发。@DmytroMukalov我感到困惑。我说了完全相同的话:“或者至少是如此之大以至于Windows决定“可能无限”| SEH也是Windows:“Microsoft结构化异常处理是Windows的本机异常处理机制,是向量化异常处理(VEH)的先驱技术。”它的特点是在标准C++异常中不存在最后的机制(但在稍后介绍的大多数命令语言中)。SEH是为每个执行线程单独设置和处理的。“这不一样:<代码> Windows决定“无限地”。
与超出的堆栈边界无关。这一说法至少具有误导性,因为没有可能无限的内部基础设施的概念或定义引发此异常。至于
SEH是Windows
这就像说车轮就是汽车。@DmytroMukalov我实际上是说汽车有车轮。Al所以我认为大多数人被车碾过,而不是被车轮碾过。因此,在你身上做事情的确切部分并不重要。我的主要观点是,这是无限递归,或者至少是一些非常深的东西,它被分解为无限递归。当你没有很强的预测递归深度不会改变时,使用递归是危险的应该避免超过堆栈大小,否则您得到
StackOverflowException
的那一刻只是时间问题。我建议使用循环或蹦床作为递归的安全替代方法。您可以改进的最佳方法是。这是程序员的一项关键技能,如果您的“没有开始”你做错了什么。