1
,我現在有將列出所有可能的組合蠻力黑客概念在Python 3
from itertools import product
password = "hr"
chars = 'abcdefghijklmnopqrstuvwxyz' #characters to look for, can have letters added
for length in range(1, 3): #only do lengths of 1 + 2 - namely from aa - zz not onto aaa
to_attempt = product(chars, repeat=length)
for attempt in to_attempt:
print(''.join(attempt))
我需要做的就是把每嘗試嘗試,它與變量「密碼」比較的代碼,如果它匹配突圍for循環其他進行,任何想法?
你的第5行不正確,它應該讀取'if''.join(attempt)== password:'按照原始代碼。 – phantom 2014-11-01 20:44:10
@phantom你能稍微解釋一下嗎?對於任何字符串,==''.join(a)。你爲什麼要這樣做,而不是嘗試==密碼? – furkle 2014-11-01 20:46:17
因爲變量'attempt'不是兩個字符的密碼,所以它是單個字符。 – phantom 2014-11-01 20:52:27