生成密码字典的方法

26 篇文章 0 订阅
26 篇文章 0 订阅

生成密码字典

import android.content.Context
import android.util.Log
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import java.io.OutputStreamWriter

class Password() {
    // 密码最短长度
    var min = 8

    // 密码最长长度
    var max = 14

    // 常用密码组合
    var MOST_USE = arrayOf(
        "11111111", "00000000", "11223344", "0123456789", "000000", "0123456789", "101010", "111111", "111222", "112233",
        "11223344", "121212", "12121212", "12344321456", "1234567", "12345678", "123456789", "1234567890", "1234gwer", "1qaz2wsx",
        "2222415926", "555555", "7758521", "7758258", "77777777", "8888888", "99999999", "99999999", "abcdefg", "admin", "love",
        "qwertyuiop", "1314", "7788", "8899", "123", "1234")

    // 常用年份组合
    var YEAR = arrayOf(
        "1970", "1971", "1972", "1973", "1974", "1975", "1976", "1977", "1978", "1979", "1980", "1981", "1982", "1983", "1984",
        "1985", "1986", "1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999",
        "2000,2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014",
        "2015", "2016", "2017", "2018", "2019", "2020", "2021", "2022", "2023", "2024"
    )

    // 常用月份组合
    var MONTH = arrayOf("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "1", "2", "3", "4", "5", "6", "7", "8", "9")

    // 常用日期组合
    var DAY = arrayOf("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "1", "2", "3", "4", "5", "6", "7", "8", "9")

    // 常用首字母
    var FLETTER = arrayOf(
        "b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "s", "t", "w",
        "x", "y", "z")

    // 常用姓氏组合
    var LASTNAME = arrayOf("li", "ma", "wu", "xu", "hu", "yu", "he", "liu", "sun", "gao", "luo", "cai", "guo", "zhu", "wang", "zhao",
        "yang", "zhou", "song", "meng", "deng", "zhang", "huang", "liang", "qian", "zheng", "feng", "chen", "hu", "shen", "han", "kong")

    // 常用名字拼音组合
    var FIRSTNAME = arrayOf("bo", "bi", "bai", "bei", "bao", "ban", "ben", "bin", "bang", "bing", "biao", "ci", "cai", "can", "cen", "cun", "ceng", "cong", "cao", "chi", "chu",
        "chui", "chan", "chen", "cheng", "chang", "chong", "chuan", "chuang", "chao", "che", "cha", "chai", "de", "di", "du", "dai", "dao", "dan", "deng", "ding", "dang", "dong",
        "fa", "fu", "fei", "fan", "fen", " fang", "feng", "fou", "gu", "gui", "gao", "gai", "gan", "gen", "guo", "gang", "geng", "guan", "guang", "hu", "hui", "hao", "han", "hen",
        "huo", "hang", "heng", "huan", "huang", "hun", "ji", "ju", "jiu", "jie", "jin", "jun", "jue", "jing", "ji", "jia", "jiao", "jian", "juan", "jiang", "kai", "kui", "kan", "ken",
        "kun", "kuo", "kang", "keng", "kong", "kuan", "kuang", "le", "li", "lai", "lu", "lei", "lie", "lan", "lin", "lun", "lang", "ling", "long", "liao", "lian", "luan", "mi", "mu",
        "mai", "man", "mei", "mao", "miu", "min", "mang", "meng", "ming", "miao", "mian", "na", "ni", "nu", "niu", "nan", "nuo", "neng", "ning", "nv", "pa", "pi", "pu", "pai", "pen",
        "pin", "pan", "pao", "peng", "ping", "pang", "pian", "qi", "qu", "qiu", "qing", "qin", "quan", "qian", "qiao", "que", "ri", "re", "ruo", "rou", "ran", "ren", "rui", "rang", "reng",
        "sa", "si", "se", "su", "sai", "sun", "suo", "song", "sang", "san", "suan", "shi", "shu", "shui", "shan", "shen", "sheng", "shang", "shuan", "shuang", "shao", "she", "sha", "shai",
        "ta", "te", "tan", "tei", "ti", "tu", "tang", "tai", "tao", "tuo", "teng", "ting", "tun", "tong", "tian", "tou", "wa", "wu", "wai", "wei", "wang", "wan", "xi", "xu", "xiu", "xian",
        "xu", "xie", "xun", "xin", "xing", "xiang", "xiong", "xia", "xuan", "xue", "ya", "ye", "yi", "yu", "yao", "you", "yan", "yun", "yue", "yin", "ying", " yuan", "yang", "yong", "zu", "zao",
        "zui", "ze", "zi", "zou", "zuo", "zeng", "zuan", "zong", "zun", "zan", "zai")

    fun createFile(root: String, name: String): File {
        val file = File(root, "$name.txt")
        if (file.exists()) {
            file.delete()
        }
        try {
            file.createNewFile()
            return file
        } catch (e: IOException) {
            e.printStackTrace()
        }
        Log.i("hy55", "createFile file=$file")
        return file
    }

    // 常用特殊符号
    var MOST_SIN = arrayOf("!", "@", "#", "_", "~", "*", "$", ",", ".", ",")
    @Throws(IOException::class)
    fun create(root: String, name: String, temp: Array<String>) {
        val f = createFile(root, name)
        val fop = FileOutputStream(f, true)
        val writer = OutputStreamWriter(fop, "UTF-8")
        for (i in temp) {
            val str = """
                $i
                
                """.trimIndent()
            if (str.length in (min + 1) until max) writer.append(str)
        }
        writer.close()
        fop.close()
        println("密码生成结束:$name")
    }

    @Throws(IOException::class)
    fun create(root: String, name: String, temp: Array<String>, temp1: Array<String>) {
        val f = createFile(root, name)
        val fop = FileOutputStream(f, true)
        val writer = OutputStreamWriter(fop, "UTF-8")
        for (i in temp) {
            for (j in temp1) {
                val str = """
                    $i$j
                    
                    """.trimIndent()
                if (str.length in (min + 1) until max) writer.append(str)
            }
        }
        writer.close()
        fop.close()
        println("密码生成结束:$name")
    }

    @Throws(IOException::class)
    fun create(root: String, name: String, temp: Array<String>, temp1: Array<String>, temp2: Array<String>) {
        val f = createFile(root, name)
        val fop = FileOutputStream(f, true)
        val writer = OutputStreamWriter(fop, "UTF-8")
        for (x in temp) {
            for (y in temp1) {
                for (z in temp2) {
                    val str = """
                        $x$y$z
                        
                        """.trimIndent()
                    if (str.length in (min + 1) until max) writer.append(str)
                }
            }
        }
        writer.close()
        fop.close()
        println("密码生成结束:$name")
    }

    @Throws(IOException::class)
    fun create(
        root: String,
        name: String,
        temp: Array<String>,
        temp1: Array<String>,
        temp2: Array<String>,
        temp3: Array<String>
    ) {
        val f = createFile(root, name)
        val fop = FileOutputStream(f, true)
        val writer = OutputStreamWriter(fop, "UTF-8")
        for (a in temp) {
            for (b in temp1) {
                for (c in temp2) {
                    for (d in temp3) {
                        val str = """
                            $a$b$c$d
                            
                            """.trimIndent()
                        if (str.length in (min + 1) until max) writer.append(str)
                    }
                }
            }
        }
        writer.close()
        fop.close()
        println("密码生成结束:$name")
    }

    @Throws(IOException::class)
    fun create(
        root: String,
        name: String,
        temp: Array<String>,
        temp1: Array<String>,
        temp2: Array<String>,
        temp3: Array<String>,
        temp4: Array<String>
    ) {
        val f = createFile(root, name)
        val fop = FileOutputStream(f, true)
        val writer = OutputStreamWriter(fop, "UTF-8")
        for (a in temp) {
            for (b in temp1) {
                for (c in temp2) {
                    for (d in temp3) {
                        for (e in temp4) {
                            val str = """
                                $a$b$c$d$e
                                
                                """.trimIndent()
                            if (str.length in (min + 1) until max) writer.append(str)
                        }
                    }
                }
            }
        }
        writer.close()
        fop.close()
        println("密码生成结束:$name")
    }

    @Throws(IOException::class)
    fun create(
        root: String,
        name: String,
        temp: Array<String>,
        temp1: Array<String>,
        temp2: Array<String>,
        temp3: Array<String>,
        temp4: Array<String>,
        temp5: Array<String>
    ) {
        val f = createFile(root, name)
        val fop = FileOutputStream(f, true)
        val writer = OutputStreamWriter(fop, "UTF-8")
        for (a in temp) {
            for (b in temp1) {
                for (c in temp2) {
                    for (d in temp3) {
                        for (e in temp4) {
                            for (z in temp5) {
                                val str = """
                                    $a$b$c$d$e$z
                                    
                                    """.trimIndent()
                                if (str.length in (min + 1) until max) writer.append(str)
                            }
                        }
                    }
                }
            }
        }
        writer.close()
        fop.close()
        println("密码生成结束:$name")
    }

    /**
     * 遍历所有密码集合
     */
    fun createSuperDic(root: String, name: String,) {
        val list = listOf("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")

        //完整字符:"~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+", "{", "}", "|", ":", """, "<", ">", "?", ";", "\'", ",", ".", "/", "-", "=", "`"
        val finalList = arrayListOf<String>("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",
            "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+", "{", "}", "|", ":", "<", ">", "?", ";", ",", ".", "/", "-", "=")
        println("正在生成:-------------------超级密码字典-------------------")
        //...循环8次,获取所有的8位密码
        val f = createFile(root, "8位超级密码字典")
        val fop = FileOutputStream(f, true)
        val writer = OutputStreamWriter(fop, "UTF-8")
        for (i in list) {
            for (j in list) {
                for (k in list) {
                    for (m in list) {
                        for (n in list) {
                            for (p in list) {
                                for (q in list) {
                                    for (z in list) {
                                        val str = """
                                            $i$j$k$m$n$p$q$z
                                
                                            """.trimIndent()
                                        writer.append(str)
                                    }
                                }
                            }
                        }
                    }

                }
            }
        }
        writer.close()
        fop.close()
        println("密码生成结束:获得8位超级密码字典")
    }

    /**
     * 穷举打印输出,可以将打印输出的文件形成字典
     * @param maxLength:生成的字符串的最大长度
     */
    fun generate(maxLength: Int, root: String) {
        //可能的密码集合
        val charSource = charArrayOf('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')

        val fullCharSource = charArrayOf('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',
            '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '{', '}', '|', ':', '"', '<', '>', '?', ';', '\'', ',', '.', '/', '-', '=', '`')

        //写入密码
        val f = createFile(root, "8-14位超级密码字典")
        val fop = FileOutputStream(f, true)
        val writer = OutputStreamWriter(fop, "UTF-8")

        //可能的密码长度
        val fullCharLength = charSource.size
        //计数器,多线程时可以对其加锁,当然得先转换成Integer类型。
        //初始数字:3579345993194,起始就是8位密码,创建8-14位密码
        //初始估计为200T的txt文件
        var counter = 3579345993194
        var buider = StringBuilder()

        while (buider.toString().length <= maxLength) {
            buider = StringBuilder(maxLength * 2)
            var _counter = counter
            //10进制转换成26进制
            while (_counter >= fullCharLength) {
                //获得低位
                println("密码生成----->>>>>1:${charSource[(_counter % fullCharLength).toInt()]}")
                buider.insert(0, charSource[(_counter % fullCharLength).toInt()])
                _counter /= fullCharLength
                //精髓所在,处理进制体系中只有10没有01的问题,在穷举里面是可以存在01的
                _counter--
            }
            //最高位
            buider.insert(0, charSource[_counter.toInt()])
            counter++
            println("密码生成----->>>>>2:$buider")
            val str = "$buider\r\n"
            writer.append(str)
        }
        writer.close()
        fop.close()
        println("密码生成结束:获得8-14位超级密码字典")
    }


    companion object {
        @Throws(IOException::class)
        @JvmStatic
        fun create1(context: Context) {
            val root = context.getExternalFilesDir(null)?.absolutePath.toString()
            val createdict = Password()
            println("正在生成:姓+年+常用符号")
            createdict.create(root, "姓+年+常用符号", createdict.LASTNAME, createdict.YEAR, createdict.MOST_SIN)
            println("正在生成:姓+常用数字")
            createdict.create(root, "姓+常用数字", createdict.LASTNAME, createdict.MOST_USE)
            println("正在生成:姓+常用数字+常用符号")
            createdict.create(root, "姓+常用数字+常用符号", createdict.LASTNAME, createdict.MOST_USE, createdict.MOST_SIN)
            println("正在生成:姓+年+月+日")
            createdict.create(root, "姓+年+月+日", createdict.LASTNAME, createdict.YEAR, createdict.MONTH, createdict.DAY)
        }

        @Throws(IOException::class)
        @JvmStatic
        fun create2(context: Context) {
            val root = context.getExternalFilesDir(null)?.absolutePath.toString()
            val createdict = Password()
//            println("正在生成:姓+月+日+常用符号")
//            createdict.create(root,"姓+月+日+常用符号", createdict.LASTNAME, createdict.MONTH, createdict.DAY, createdict.MOST_USE)
//            println("正在生成:姓+名+年")
//            createdict.create(root,"姓+名+年", createdict.LASTNAME, createdict.FIRSTNAME, createdict.YEAR)
//            println("正在生成:姓+名+月+日")
//            createdict.create(root,"姓+名+月+日", createdict.LASTNAME, createdict.FIRSTNAME, createdict.MONTH, createdict.DAY)
            println("正在生成:姓+名+年+月+日")
            createdict.create(root, "姓+名+年+月+日", createdict.LASTNAME, createdict.FIRSTNAME, createdict.YEAR, createdict.MONTH, createdict.DAY)
        }

        @Throws(IOException::class)
        @JvmStatic
        fun create3(context: Context) {
            val root = context.getExternalFilesDir(null)?.absolutePath.toString()
            val createdict = Password()
            println("正在生成:姓+名+名+年")
            createdict.create(root, "姓+名+名+年", createdict.LASTNAME, createdict.FIRSTNAME, createdict.FIRSTNAME, createdict.YEAR)
            println("正在生成:姓+名+名+月+日")
            createdict.create(root, "姓+名+名+月+日", createdict.LASTNAME, createdict.FIRSTNAME, createdict.FIRSTNAME, createdict.MONTH, createdict.DAY)
            println("正在生成:姓+名+名+年+月+日")
            createdict.create(root, "姓+名+名+年+月+日", createdict.LASTNAME, createdict.FIRSTNAME, createdict.FIRSTNAME, createdict.YEAR, createdict.MONTH, createdict.DAY)
            println("正在生成:2字首字母+常用数字")
            createdict.create(root, "2字首字母+常用数字", createdict.FLETTER, createdict.FLETTER, createdict.MOST_USE)
        }

        @Throws(IOException::class)
        @JvmStatic
        fun create4(context: Context) {
            val root = context.getExternalFilesDir(null)?.absolutePath.toString()
            val createdict = Password()
            println("正在生成:2字首字母+常用符号")
            createdict.create(root, "2字首字母+常用符号", createdict.FLETTER, createdict.FLETTER, createdict.MOST_SIN)
            println("正在生成:2字首字母+年")
            createdict.create(root, "2字首字母+年", createdict.FLETTER, createdict.FLETTER, createdict.YEAR)
            println("正在生成:2字首字母+年+常用符号")
            createdict.create(root, "2字首字母+年+常用符号", createdict.FLETTER, createdict.FLETTER, createdict.YEAR, createdict.MOST_SIN)
            println("正在生成:2字首字母+月+日")
            createdict.create(root, "2字首字母+月+日", createdict.FLETTER, createdict.FLETTER, createdict.MONTH, createdict.DAY)
        }

        @Throws(IOException::class)
        @JvmStatic
        fun create5(context: Context) {
            val root = context.getExternalFilesDir(null)?.absolutePath.toString()
            val createdict = Password()
            println("正在生成:2字首字母+月+日+常用符号")
            createdict.create(root, "2字首字母+月+日+常用符号", createdict.FLETTER, createdict.FLETTER, createdict.MONTH, createdict.DAY, createdict.MOST_SIN)
            println("正在生成:2字首字母+年+月+日")
            createdict.create(root, "2字首字母+年+月+日", createdict.FLETTER, createdict.FLETTER, createdict.YEAR, createdict.MONTH, createdict.DAY)
            println("正在生成:3字首字母+常用数字")
            createdict.create(root, "3字首字母+常用数字", createdict.FLETTER, createdict.FLETTER, createdict.FLETTER, createdict.MOST_USE)
            println("正在生成:3字首字母+常用符号")
            createdict.create(root, "3字首字母+常用符号", createdict.FLETTER, createdict.FLETTER, createdict.FLETTER, createdict.MOST_SIN)
        }

        @Throws(IOException::class)
        @JvmStatic
        fun create6(context: Context) {
            val root = context.getExternalFilesDir(null)?.absolutePath.toString()
            val createdict = Password()
            println("正在生成:3字首字母+年")
            createdict.create(root, "3字首字母+年", createdict.FLETTER, createdict.FLETTER, createdict.FLETTER, createdict.YEAR)
            println("正在生成:3字首字母+年+常用符号")
            createdict.create(root, "3字首字母+年+常用符号", createdict.FLETTER, createdict.FLETTER, createdict.FLETTER, createdict.YEAR, createdict.MOST_SIN)
            println("正在生成:3字首字母+月+日")
            createdict.create(root, "3字首字母+月+日", createdict.FLETTER, createdict.FLETTER, createdict.FLETTER, createdict.MONTH, createdict.DAY)
            println("正在生成:3字首字母+月+日+常用符号")
            createdict.create(root, "3字首字母+月+日+常用符号", createdict.FLETTER, createdict.FLETTER, createdict.FLETTER, createdict.MONTH, createdict.DAY, createdict.MOST_SIN)
            println("正在生成:3字首字母+年+月+日")
            createdict.create(root, "3字首字母+年+月+日", createdict.FLETTER, createdict.FLETTER, createdict.FLETTER, createdict.YEAR, createdict.MONTH, createdict.DAY)
        }

        /**
         * 全遍历所有的可能字符
         */
        fun create7(context: Context) {
            val root = context.getExternalFilesDir(null)?.absolutePath.toString()
            val createdict = Password()
            createdict.createSuperDic(root, "8位密码超级字典")
        }


        /**
         * 穷举法
         */
        fun create8(context: Context) {
            println("正在生成:8-14位超级密码字典")
            val createdict = Password()
            val beginMillis = System.currentTimeMillis()
            println(beginMillis) //开始时间
            val root = context.getExternalFilesDir(null)?.absolutePath.toString()
            createdict.generate(maxLength = 8, root)
            val endMillis = System.currentTimeMillis()
            println(endMillis) //结束时间
            println(endMillis - beginMillis) //总耗时,毫秒
        }

    }
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值