网络编程
位置:首页>> 网络编程>> Python编程>> python生成密码字典详解

python生成密码字典详解

作者:Y-shark  发布时间:2021-10-07 20:04:45 

标签:python,密码字典

代码和代码运行的结果:

python生成密码字典详解

python生成密码字典详解

代码:

import itertools as its
words="rot123"
a=its.product(words,repeat=4)
name=open("pass.txt","a")
for i in a:
   name.write("".join(i))
   name.write("".join("\n"))
name.close()

代码解析:

#导入模块
import itertools as its
#设的密码“元素”,就是破解密码的字符
words="rot123"
#its=itertools,repeat是生成密码的个数
a=its.product(words,repeat=4)
#写文件名称,“a”是以追加密模式打开
name=open("pass.txt","a")
#for循环——相当于循环words
for i in a:
#join是将元素以指定的字符连接生成一个新的字符串,“”是以什么连接输出
    name.write("".join(i)) #\n是换行
    name.write("".join("\n")) #输出完之后,close关闭打开的文件
name.close()

效果图:

python生成密码字典详解

来源:https://blog.csdn.net/YZ913/article/details/122526347

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com