1〜4文字のアルファベットの文字列を探したいと思います。複数の文字リストを順番に繰り返します。
私は、52文字のリストを反復処理することから始め:
letters = string.ascii_letters
私はその後、私は私が探しています文字列を検索するまで、文字列の次の3つの文字に同じリストを繰り返し処理する必要があります。
各_が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