0
点赞
收藏
分享

微信扫一扫

实验:穷举法破解账号口令 。

王栩的文字 2022-03-12 阅读 90
java

实验内容:

假设账号口令由六位字符组成,取值范围可以是10个数字(0~9)、26个小写英文字母和8个特殊符号(+、-、*、/、=、&、*、#)。请编写一个程序实现用穷举法破解这六位账号口令,分别用6位数字、6位的数字+小写字母、6位的数字+小写字母+特殊字符的实例进行测试,比较破解时间,分析口令的安全设置策略。

穷举法破解这六位账号口令

     *     枚举法是通过牺牲时间来换取答案的全面性.(运行时间2分钟左右)

1,// gerVerificationCode()方法: 随机生成六位账号口令。

// gerVerificationCode()方法: 随机生成六位账号口令。
    public static String gerVerificationCode(){
/*
        数字(0~9)、26个小写英文字母和7个特殊符号(+、-、/、=、&、*、#)。
*/
        char[]  cha = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'
                , 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
                , '+', '-', '*', '%', '&', '/', '#'};
        String e ="";
        for (int i = 0; i < 6; i++) {
            double x = Math.random()* cha.length;
            int s = (int) Math.floor(x);
            e+=cha[s];
        }

        return e;
}

2,/**
     * gerpwd方法:穷举法破解这六位账号口令
     *     枚举法是通过牺牲时间来换取答案的全面性.
     *    简单的for循环+字符串拼接 +判断字符串相等;
     */

/**
     * gerpwd方法:穷举法破解这六位账号口令
     *     枚举法是通过牺牲时间来换取答案的全面性.
     * @param q
     * @return
     */
    public static String getpwd(String q){
        char[]  cha = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'
                , 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
                , '+', '-', '*', '%', '&', '/', '#'};
        String str ="";
        String a =q;

        for (int i = 0; i <cha.length ; i++) {
            String str1 = "";
            str1+=cha[i];
            for (int j = 0; j < cha.length; j++) {
                String str2 = "";
                str2+=cha[j];
                for (int k = 0; k < cha.length; k++) {
                    String str3 = "";
                    str3+=cha[k];
                    for (int l = 0; l < cha.length; l++) {
                        String str4 = "";
                        str4+=cha[l];
                        for (int m = 0; m < cha.length; m++) {
                            String str5 = "";
                            str5+=cha[m];
                            for (int n = 0; n < cha.length; n++) {
                                String str6 = "";
                                str6+=cha[n];
                                str = str1+str2+str3+str4+str5+str6;
                                //   Thread.sleep(100 );
                                //  System.out.println(str);
                                if (a.equals(str)) {
                                   System.out.println("破解得账号口令为:"+str);
                                    return str;
                                }
                            }
                        }
                    }
                }
            }
        }
        return null;
    }

3,两个调用方式:(放在Main 中)

(1) 调用gerVerificationCode()方法: 随机生成六位账号口令。

(2)手动输入六位账号口令。

 

 ===========================小蓝的学习日记 =================================

举报

相关推荐

0 条评论