python如何生成密码字典

作者:用余生去守护 时间:2021-12-23 23:08:24 

一、密码字典

所谓密码字典,主要是配合解密使用,一般情况用来暴力破解密码,是由指定字符排列组合组成的文本文件。如果知道密码设置的规律指定性生成密码,会对破解密码有决定性的帮助!!

二、字典生成

1.生成6位数小写字母+数字密码字典

代码如下(示例):

import itertools as its

words = 'abcdefghijklmnopqrstuvwxyz1234567890'  #采用的字符

r = its.product(words, repeat=6)  # repeat 要生成多少位的字典

dic = open("pass.txt", "a")    #保存
for i in r:
    dic.write("".join(i))
    dic.write("".join("\r"))
dic.close()

2.选择模式运行

python dictionary.py default
python dictionary.py numonly
python dictionary.py letteronly

代码如下(示例):

import itertools as its
import argparse
def run_default(length,filename):
    global words
    '''
    words='ha'
    
    if numonly == True:
        words="1234567890"
    else:
        words="1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
    '''
    words="1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
    r =its.product(words,repeat=length)
    dic = open(filename,'a')
    for i in r:
        dic.write("".join(i))
        dic.write("".join("\n"))
    dic.close()

def run_numonly(length,filename):
    global words
    words="1234567890"
    r =its.product(words,repeat=length)
    dic = open(filename,'a')
    for i in r:
        dic.write("".join(i))
        dic.write("".join("\n"))
    dic.close()

def run_letteronly(length,filename):
    global words
    words="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
    r =its.product(words,repeat=length)
    dic = open(filename,'a')
    for i in r:
        dic.write("".join(i))
        dic.write("".join("\n"))
    dic.close()

if __name__ == "__main__":
    choices={"default":run_default,"numonly":run_numonly,"letteronly":run_letteronly}
    parser=argparse.ArgumentParser(description='快速生成密码字典')
    parser.add_argument('model',choices=choices,help='选择哪个模式运行')
    parser.add_argument('--length',metavar='length',type=int,default=3,help="密码字典内密码的长度")
    parser.add_argument('-filename',metavar='filename',type=str,default='password.txt',help="密码字典文件昵称")
    #parser.add_argument('-numonly',metavar='numonly',type=bool,default=False,help="是否只含有数字")
    args=parser.parse_args()
    func=choices[args.model]
    func(args.length,args.filename)

来源:https://blog.csdn.net/qq_45365214/article/details/123274975

标签:python,密码,字典
0
投稿

猜你喜欢

  • 10点优化sql数据库技巧

    2008-06-09 15:00:00
  • Python中Jieba进行词频统计与关键词提取

    2022-02-03 23:08:50
  • 教你利用PyTorch实现sin函数模拟

    2021-06-23 18:17:25
  • mysql: 安装后的目录结构

    2011-03-08 09:46:00
  • Python+django实现简单的文件上传

    2021-08-15 03:11:25
  • SQL语句中的一些特殊参数如何用变量来代替

    2008-03-14 07:44:00
  • Python读取txt内容写入xls格式excel中的方法

    2023-08-31 22:29:17
  • 细品Dreamweaver MX 内建FW技术

    2008-06-04 09:41:00
  • 清除浮动新说

    2009-12-25 18:49:00
  • 24式加速你的Python(小结)

    2023-09-25 10:25:24
  • php mysql procedure实现获取多个结果集的方法【基于thinkPHP】

    2023-11-19 08:27:32
  • Python list列表删除元素的4种方法

    2021-09-11 06:39:09
  • 用python编写一个图片拼接工具

    2023-09-01 18:31:52
  • IE 8 提出“超级标准模式”

    2008-01-24 19:26:00
  • DHTML 打造 Picture Spelling

    2013-08-22 17:01:53
  • Python with用法实例

    2022-09-07 19:34:05
  • 从HTTP状态 301,302,200 来看页面跳转

    2007-09-26 13:46:00
  • Python基于TensorFlow接口实现深度学习神经网络回归

    2022-07-17 22:38:28
  • asp如何在网页打开时显示“正在加载”之类的信息?

    2010-06-22 21:12:00
  • 浅谈ACCESS数据库升迁SQLSERVER注意事项

    2007-08-11 13:44:00
  • asp之家 网络编程 m.aspxhome.com