2017-02-12 7 views
0

私はGadsbyの話を取り、すべての句読点を削除し、 "o"を "0"に置き換えることに基づいて、 。ストーリーの言葉で、私はw1w2w3という形式のPDFを解読して、パスワードが見つかるまでループして上昇(w2w3w4、w3w4w5、w4w5w6など)し続けなければなりません。私の問題ははIndexErrorをIを取得していている:私は最後の2日間、それを見てきたとして次の行の範囲外のリストインデックスエラーの理由を見つける手助け私には意味をなさない "IndexError:list index out of range"を取得する

password = word_list[list_1] + word_list[list_2] + word_list[list_3] 

いただければ幸いです無駄に。私のコードに他のエラーがある場合は、それらも指摘してください。

import re 
import PyPDF2 

# Defining the function called "pdf_cracker" 
def pdf_cracker(): 
    # Import the shuffle 
` from random import shuffle 
    # Open Gadsby story and define it as the variable "string" 
    string = open("gadsby.txt", "r").read() 
    # Uses substitution in the RE module to only include characters from a-z, A-Z and 0-9 
    new_str = re.sub("[^a-zA-Z0-9]", " ",string) 
    open("gadsby_no_punctuation.txt", "w").write(new_str) 
    gadsby_no_punctuation = open("gadsby_no_punctuation.txt", "r").read().split() 

    word_list = [gadsby_no_punctuation] 

    list_1 = 0 
    list_2 = 1 
    list_3 = 2 


for item in word_list:   
    password = word_list[list_1] + word_list[list_2] + word_list[list_3] # ERROR ON THIS LINE 
    password = password.replace("o", "0") 
    password = password.replace("O", "0") 
    print password 

    from PyPDF2 import PdfFileReader, PdfFileWriter 
    pdf_file = ("crack_me.pdf", "rb") 

    if pdf.isEncrypted == False: 
     print "The file you're trying to crack doesn't have a password" 

    if(pdf_file.decrypt(password) == 1): 
     print "O " + password + " is the password!" 
     break 

    else:  
     print "X " + password + " is not the password" 
     list_1 = list_1 + 1 
     list_2 = list_2 + 1 
     list_3 = list_3 + 1 

if __name__ == "__main__": 
    zip_cracker() # Ignore this line - this is another part of the program, not throwing up any errors. 
    pdf_cracker() 
+0

あなたは毎回5を割り当てています。チェックアウト:http://pythontutor.com –

+0

私はそれが起こっていると思います –

+0

私は?どこですか? – Gbrowne757

答えて

0

あなたはギャッツビーのリストを作成している使用して

word_list = [gadsby_no_punctuation] 

コピーギャッツビーリストの

gadsby_no_punctuation = "a b c d e f g".split() # A test string 
>>> gadsby_no_punctuation 
['a', 'b', 'c', 'd', 'e', 'f', 'g'] 
>>> word_list = [gadsby_no_punctuation] 
>>> word_list 
[['a', 'b', 'c', 'd', 'e', 'f', 'g']] # a list inside a list 
>>> len(word_list) 
1 # only 1 item in the list 

代わりに別のリスト内に置く[:]

word_list = gadsby_no_punctuation[:] 

ある限り少なくとも3つの単語は、もはやそのエラーを取得する必要がありません

関連する問題