part3/script.py

16 lines
974 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Создаём соответствие номеров букв и самих букв русского алфавита
alphabet = {i + 1: letter for i, letter in enumerate("АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ")}
# Читаем закодированный текст из файла data.txt
with open("data.txt", "r", encoding="utf-8") as file:
numbers = file.read().strip().split(" ") # Разделяем по одиночному пробелу, чтобы сохранить их
# Преобразуем числа в буквы, а пробелы оставляем
decoded_text = "".join(alphabet.get(int(num), " ") if num.isdigit() else " " for num in numbers)
# Записываем результат в output.txt
with open("output.txt", "w", encoding="utf-8") as output_file:
output_file.write(decoded_text)
print("Файл output.txt создан с расшифрованным текстом.")