我正在撰寫一個 python 代碼來查找具有特定規則的所有可能的密碼組合
- 應該包含字母 AZ az
- 應包含數字 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 進行迭代... **
uj5u.com熱心網友回復:
我認為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" )
希望它可以幫助
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/477556.html
標籤:python-3.x for循环 嵌套循环
上一篇:在一個樣本中隨機和非隨機抽樣
