2017-03-08 12 views
0

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 
+0

はSO Kyapへようこそ!私たちが助けてくれることは喜ばしいことですが、あなたが最初にやったことを私たちに示す必要があります。 SOは(通常)コード作成サービスではありません。 – AlG

+0

サンプルデータや擬似コードを含めることができますか?あなたの質問を読むのに問題があります –

+0

http://stackoverflow.com/questions/7074051/what-is-the-best-way-to-generate-all-possible-three-letter-stringsを参照してください。 – kennytm

答えて

0

おそらくこのような何か:あなたはこのような何か行うことができます

my_string = "some" 
for letter1 in string.ascii_letters: 
    if letter1 == my_string: 
     print("success") 
    for letter2 in string.ascii_letters: 
     if letter1 + letter2 == my_string: 
      print("success") 
     for letter3 in string.ascii_letters: 
      if letter1 + letter2 + letter3 == my_string: 
       print("success") 
      for letter4 in string.ascii_letters: 
       if letter1 + letter2 + letter3 + letter4 == my_string 
        print("success") 
+0

パーフェクト!とても簡単です。私はこれのための論理を思い付くことができたと思う。 – Kyap

2

 

    import string 
    import itertools 

    data = string.ascii_lowecase 

    for i in itertools.permutations(data, 4): 

     if i == 'your_string': 
      #do something 
     else: 
      pass 

+0

itertools.permutationを使用するとうまくいきません。私は1,2文字と3文字を考慮する必要があります.4文字の順列だけではありません。 – Kyap

+0

アウターループを使用して文字列の長さを維持し、itertools.permutationを使用することができます。 –

関連する問題