蛮力不起作用,我找不到密码

时间:2017-03-02 15:51:51

标签: java loops brute-force

当我运行程序时,没有输出,只是运行一段时间什么都不做,我试过输入“!!!!!!”这是char中的ASCII 33。这是我的第四次或第五次代码迭代,我仍然无法使其工作。

这是我的程序,

public class BruteForceTrue {
    public static void main(String[] args) {

        int z = 0;//Variable Declarations
        int i = 0;
        int u = 0;
        int g = 0;
        int d = 0;
        int t = 0;
        int w = 0;
        char rechar1 = 0;
        char rechar2 = 0;
        char rechar3 = 0;
        char rechar4 = 0;
        char rechar5 = 0;
        char rechar6 = 0;
        String passT;
        String passF = " " ;
        StringBuilder sb = new StringBuilder();

        Scanner scanvar = new Scanner(System.in);
        System.out.println("Challenge me to crack your pasword:");//Password Input
        passT= scanvar.next();
        for(i=32;i<=127;i++){//For loop 1
            rechar1 = ((char)i);
            sb.setLength(0);//setting the list to blank
            sb.append(rechar1);// setting the first character in the password
            for (i=32;t<=127;t++){//For loop 2
                rechar2 = ((char)t);
                sb.append(rechar2);
                for(d=32;d<=127;d++){//For loop 3
                    rechar3 = ((char)d);
                    sb.append(rechar3);
                    for(g=32;g<=127;g++){//For loop 4
                        rechar4 = ((char)g);
                        sb.append(rechar4);
                        for(w=32;w<=127;w++){//For loop
                            rechar5 = ((char)w);
                            sb.append(rechar5);
                            for(u=32;u<=127;u++){//For loop
                                rechar6 = ((char)u);
                                sb.append(rechar6);
                                String ans = sb.toString();//turning the list into a string
                                if (ans.equals(passT)) {//asking if the guess is the same as the passcode
                                System.out.println("the password is" + ans);
                                    break;

                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

1 个答案:

答案 0 :(得分:3)

你的第二个循环

for (i=32;t<=127;t++){//For loop 2

应该有t=32,而不是i=32