java生成密码字典

话不多说全是干货

/**
 * 密码字典
 */
public class DictionarySeek  {
    //密码可能会包含的字符集合
    private static char[] fullCharSource = { '1','2','3','4','5','6','7','8','9','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', 'N',  'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
            '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '{', '}', '|', ':', '"', '<', '>', '?', ';', '\'', ',', '.', '/', '-', '=', '`'};
//    //密码可能会包含的字符集合
//    private static char[] fullCharSource = { '1','2','3','4','5','6','7','8','9','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', 'N',  'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
//            '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '{', '}', '|', ':', '"', '<', '>', '?', ';', '\'', ',', '.', '/', '-', '=', '`'};
    //将可能的密码集合长度
    private static int fullCharLength = fullCharSource.length;
    //maxLength:生成的字符串的最大长度
    public static void generate(int maxLength) throws FileNotFoundException, UnsupportedEncodingException {
        //计数器,多线程时可以对其加锁,当然得先转换成Integer类型。
        int counter = 0;
        StringBuilder buider = new StringBuilder();

        PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream("C://密码字典"+maxLength+".txt"), "utf-8"));

        while (buider.toString().length() <= maxLength) {
            buider = new StringBuilder(maxLength*2);
            int _counter = counter;
            //10进制转换成26进制
            while (_counter >= fullCharLength) {
                //获得低位
                buider.insert(0, fullCharSource[_counter % fullCharLength]);
                _counter = _counter / fullCharLength;
                //处理进制体系中只有10没有01的问题,在穷举里面是可以存在01的
                _counter--;
            }
            //最高位
            buider.insert(0,fullCharSource[_counter]);
            counter++;

            pw.write(buider.toString()+"\n");
            System.out.println(buider.toString());
        }
    }
    public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {
        System.out.print("生成的字典位置:D://密码字典.txt"+"\n"+"请输入你需要生成的字典位数:");
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();

        DictionarySeek.generate(x);

    }
}

如果你觉得实用就请我吃个馒头吧!点个赞也行!!!

  • 6
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值