Я работаю над расшифровкой грубой силы для зашифрованных сообщений Caesar Cipher с использованием атаки по словарю, однако при сканировании слов в моем файле словаря он напечатает слово, но затем вернет ошибку «IndexError: String index out of range». Это также происходит при использовании более одного слова. Спасибо
import csv
global alphabet, space, punctuation, msg, OFFSET, isSolved
alphabet = ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")
space = (" ")
punctuation = (".,!?':+-=£")
OFFSET = 0
isSolved = False
def crack():
global alphabet, space, punctuation, msg, OFFSET, isSolved
while not isSolved:
toScan = str()
for letter in list(msg):
for punc in punctuation:
if letter == punc:
toScan += punc
if letter == space:
toScan += space
for alpha in range(26):
if letter.lower() in alphabet[alpha]:
toScan += str(alphabet.upper()[alpha-int(OFFSET)])
dictionary = open("dict.csv", "r")
reader = csv.reader(dictionary)
for row in dictionary:
if toScan.lower() in str(row.lower()):
print(toScan.upper())
else:
OFFSET += 1
while True:
print("[Xiphos Bruteforce.py]")
print("1) Decrypt a message")
print("2) Add word to the dictionary")
print("3) Exit")
r = input()
if r == "1":
msg = input("Please enter the message to crack\n")
crack()
if r == "2":
None
if r == "3":
exit()