У меня есть следующий код, который расшифровывает зашифрованные тексты:
letter = 'abcdefghijklmnopqrstuvwxyz'
path = 'Cipher Assignment/ciphertext*.txt'
ciphers = glob.glob("Cipher Assignment/ciphertext*.txt")
keys = glob.glob("Cipher Assignment/key*.txt")
arrayCipher = []
arrayKey = []
# Function that opens files and saves them into an array:
def savingFiles(inputFiles, sourceFiles):
for sourceFile in sourceFiles:
with open(sourceFile) as ins:
for line in ins:
inputFiles.append(line)
return inputFiles
arrayCiphers = savingFiles(arrayCipher, ciphers)
arrayKeys = savingFiles(arrayKey, keys)
Как мне ввести 2 моих массива (arrayCiphers, arrayKeys) для декодирования в функции декодирования?
# Decoding function that decyphers the text:
def decode(ciphertext, key, letter):
indexKey = dict(zip(key, letter))
return ''.join(indexKey.get(c.lower(), c) for c in ciphertext)
# for i in range(len(arrayKeys)):
# decoded = decode(arrayCiphers, arrayKeys[i], letter)
# print(decoded)
for index, key in enumerate(arrayKey):
decoded = decode(arrayCiphers[index], key, letter)
print(decoded)
Спасибо!