我想查找長度在1-4個字符之間的字母字符串。按順序遍歷多個字符列表
我開始通過52個字母列表迭代:
letters = string.ascii_letters
我則需要通過同一個目錄遍歷該字符串的接下來的三個字符,直到我發現我要找的字符串。
如果每個_代表的52個字母列表,我需要基本上做到這一點,而在每次迭代檢查匹配:
_
_ _
_ _ _
_ _ _ _
如何將我最好的結構系列迴路做到這一點?
如果問題的前提看起來很混亂,這是針對暴力破解設置的問題。我簡單地提取了我正在努力解決的部分問題。
編輯:這是我到目前爲止的地方。
#we know the salt is the 2-digit '50'
#we know the key is limited to 4 alphabetical letters
#cycle through all possibilities of the key till we match the hash
letters = string.ascii_letters
lcounter = 0
i = 0
j = 0
k = 0
l = 0
tryhash = "a"
word = [letters[i]]
while(tryhash != hash):
for c in letters:
word = [letters[i]] #this does not work as the additional letters need to be appended to word after the first lcounter loop
tryword = ''.join(word)
tryhash = crypt.crypt(tryword, "50")
if (tryhash == hash):
print(word)
break
i += 1
if (lcounter > 0) and (i == 52):
i = 0
if (lcounter == 1) and (j == 0):
word.insert(lcounter, letters[j])
j += 1
if (lcounter > 1) and (k == 52):
j = 0
if (lcounter == 2) and (k == 0):
word.insert(lcounter, letters[k])
k += 1
if (lcounter > 2) and (k == 52):
k = 0
if (lcounter == 3) and (l == 0):
word.insert(lcounter, letters[l])
l += 1
lcounter += 1
歡迎SO Kyap!儘管我們非常樂意提供幫助,但您必須先向我們展示您首先完成的工作。 SO通常不是代碼寫入服務。 – AlG
您能否包含一些示例數據或僞代碼?我在閱讀您的問題時遇到問題 –
請參閱http://stackoverflow.com/questions/7074051/what-is-the-best-way-to-generate-all-possible-three-letter-strings。 – kennytm