我想查找长度在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