• Как расшифровать зашифрованный текст?

    @MYMINKA
    У меня получилось как-то так, только здесь это "текст" читается из файла, и в другой файл записывается расшифрованный текст.

    def read_file():
    f = open("Cipher", "r")
    cesar_cipher = f.read()
    f.close()
    return cesar_cipher

    def create_new_string(message):
    LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
    key = 1
    translated = ''
    for symbol in message:
    if symbol in LETTERS:
    num = LETTERS.find(symbol)
    num = num - key
    if num < 0:
    num = num + len(LETTERS)
    translated = translated + LETTERS[num]
    else:
    translated = translated + symbol
    return translated

    def create_strings(string):
    array_of_strings = string.split()
    array_of_words = []
    string = ""
    for word in array_of_strings:
    if not '/' in word:
    string += word + " "
    else:
    string += word
    array_of_words.append(string)
    string = ""
    return array_of_words

    #This function will shuffle the sequence of symbols to the beginning of a word
    def cesar_cipher_decode(array_of_words):
    decoded_strings = []
    shift = -3
    for item in array_of_words:
    decoded_strings.append(decode_string(item, shift))
    shift -= 1
    return decoded_strings

    def decode_string(string, shift):
    separated_string = string.split()
    string = ""
    decoded_string = ""
    for word in separated_string:
    string = word[(len(word) + shift) % len(word):] + word[:(len(word) + shift) % len(word)]
    decoded_string += string + " "
    string = ""
    return decoded_string

    def write_information_to_the_file():
    f = open("Cipher_decode", "w")
    f.write(convert_to_string(cesar_cipher_decode(create_strings(create_new_string((read_file()))))))
    f.close()
    return 0

    def convert_to_string(arr):
    s = ""
    for item in arr:
    s += item + '\n'
    return s

    if __name__ == "__main__":
    write_information_to_the_file()
    Ответ написан
    Комментировать