python中的凯撒密码解码器

python中的凯撒密码解码器,python,range,caesar-cipher,decoder,Python,Range,Caesar Cipher,Decoder,我的任务是创建一个程序来解码凯撒密码。 我已经完成了这方面的大部分工作,它可以很好地通过每一个可能的关键点,并找到新的单词 当我试图检查创建的单词时,问题出现了 #--------------------------------- #this is a program that should brute force a ceaser cypher #--------------------------------- #list of possible letters x=['a','b','c'

我的任务是创建一个程序来解码凯撒密码。 我已经完成了这方面的大部分工作,它可以很好地通过每一个可能的关键点,并找到新的单词

当我试图检查创建的单词时,问题出现了

#---------------------------------
#this is a program that should brute force a ceaser cypher
#---------------------------------
#list of possible letters
x=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
y=input("Please input the string you want to decode:   ").lower()
new_string=''
#creates a list to check weather the unjumbled word is valid
AllowedWords = []
WordsFile = open("aqawords.txt", "r")
for Word in WordsFile:
  AllowedWords.append(Word.strip().lower())
WordsFile.close()
#does this 26 times to test all possible keys
for f in range (1,27):
    #does each letter individually
    for i in range(len(y)):
        #finds the numerical value for each leter
        y1=(x.index((y[i:(i+1)])))+1
        #adds the key to the letter's number
        y2=y1+f
        #makes sure it does not go out of range
        y2=y2%26
        #adds new letter to string
        new_string=new_string+str(x[y2-1])
        #this should check every different combination of letters
        for q in range(1,(len(new_string))+1):
            for q1 in range(1,(len(new_string))+1):
                #here is the problem-----------
                #checks what type the variables are
                print(type(q))
                print(type(q1))
                #attempts to create a new string to store these new words
                new_string_1=new_string[q,q1]
                #says "TypeError: string indices must be integers"
                #but i checked and above it says that they are ints
                if new_string_1 in AllowedWords:
                    print(new_string_1)
                #------------------------------
                #print(new_string_1)
        new_string_1=''
    #print(new_string)
    new_string=''
这就是我得到的结果:

RESTART: D:\!!computer science!!\!homework!\miss jackson's homework\cyphers\Ceasar cypher.py 
Please input the string you want to decode:   abc
<class 'int'>
<class 'int'>
Traceback (most recent call last):
  File "D:\!!computer science!!\!homework!\miss jackson's homework\cyphers\Ceasar cypher.py", line 35, in <module>
    new_string_1=new_string[q,q1]
TypeError: string indices must be integers
>>> 
 RESTART: D:\!!computer science!!\!homework!\miss jackson's homework\cyphers\Ceasar cypher.py 
Please input the string you want to decode:   a
<class 'int'>
<class 'int'>
Traceback (most recent call last):
  File "D:\!!computer science!!\!homework!\miss jackson's homework\cyphers\Ceasar cypher.py", line 35, in <module>
    new_string_1=new_string[q,q1]
TypeError: string indices must be integers
重新启动:D:\!!计算机科学!!\!作业\杰克逊小姐的家庭作业\cypher\Ceasar cypher.py
请输入要解码的字符串:abc
回溯(最近一次呼叫最后一次):
文件“D:\!!计算机科学!!\!家庭作业!\jackson小姐的家庭作业\cypher\ceaar cypher.py”,第35行,在
新字符串\u 1=新字符串[q,q1]
TypeError:字符串索引必须是整数
>>> 
重新启动:D:\!!计算机科学!!\!作业\杰克逊小姐的家庭作业\cypher\Ceasar cypher.py
请输入要解码的字符串:a
回溯(最近一次呼叫最后一次):
文件“D:\!!计算机科学!!\!家庭作业!\jackson小姐的家庭作业\cypher\ceaar cypher.py”,第35行,在
新字符串\u 1=新字符串[q,q1]
TypeError:字符串索引必须是整数

有人能找到我哪里出错了吗?

新字符串[q,q1]应该怎么做?例如,
“hello”[q,q1]
应该给你什么?我想你想在
q
q1
之间加一个冒号,而不是逗号。谢谢你的回答,它修复了我得到的打字错误,但我仍然不知道如何检查这些单词是否被解码。我可以检查它们是否在允许的单词列表中,但对句子不起作用,我如何检查每个可能形成的单词以创建正确的句子?@aidan这是一个完全不同的问题,如果你这样问,然后试图重新打开这个问题,你会更幸运。