首页 > 解决方案 > 对,我有这段代码,系统命令不断出现错误

问题描述

我正在尝试使用蛮力

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
        int i;
        while (i <= 999999 ) {
                system("./lock", i); 
                i++;
        }
        printf("Error. Unable to crack file.\n");
        return 0;
}

我试图将值“i”放入系统命令中,这样当我对我的文件运行它时,它就会得到 pin。但我不断收到系统命令错误,我希望它在 Linux 终端中运行。

像这样

./lock 1
./lock 2
./lock 3
etc.

但是,如果您知道一种检测它是否已被破解的方法,请同时添加。如果你可以的话。

标签: c

解决方案


#include <string.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i = 0;
    while (i <= 999999 )
    {
        char cmd[100];
        sprintf(cmd, "./lock %d", i);
        if (system(cmd) == 0)
        {
            printf("Success with i = %d\n", i);
            exit(0);
        }
        ++i;
    }
    return !printf("Error. Unable to crack file.\n");
}

推荐阅读