我正在编写一个 python 代码来查找所有可能的密码与特定规则的组合
- 应包含字母 A-Z a-z
- 应包含数字 0-9
- 应包含特殊符号
- 密码的第一个字符必须是大写字母
from itertools import permutations
pw = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789[@_!#$%^&*()<>?/\|}{~:]"
firstchar = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
c = permutations(pw, 2) #3 is the password length for providing sample output quickly
f=open("password.txt","w+")
f.truncate(0)
for x in firstchar:
for i in c:
current_pw = x + "".join(i)
f.write( "\t" + current_pw + "\n" )
** 输出仅包含从 A 开始的密码,并且停止不针对 B、C 进行迭代... **
回答1
我认为 permutation
在第一个循环后退出。所以你在每个循环中定义 c
。
from itertools import permutations
pw = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789[@_!#$%^&*()<>?/\|}{~:]"
firstchar = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
f=open("password.txt","w+")
f.truncate(0)
for x in firstchar:
c = permutations(pw, 2) # c is defined here
for i in c:
current_pw = x + "".join(i)
f.write( "\t" + current_pw + "\n" )
希望它可以帮助