Предмет: Информатика, автор: kardakovadariasovt

Здравствуйте! Помогите пожалуйста! Нужно написать шифр тритемиуса на питоне с интерфейсом чтобы он зашифровывал набранный текст и расшифровывал набранный на шифре тритемиуса текст.


TemaZpro: С интерфейсом в плане текстовы, чтобы меню было в консоли и если ввести 1, то предложит зашифровать, а если 2, то расшифровать?
TemaZpro: Или графический интерфейс?
kardakovadariasovt: Графический интерфейс

Ответы

Автор ответа: TemaZpro
2

Если захотите, чтобы он шифровал не только английский текст, нужно будет заменить алфавит с английского на русский:

Английский:

alphabet = ['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']
Русский алфавит:
alphabet = ['а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я']

Код на языке Python:

import tkinter as tk

def trithemius_cipher():

   def encrypt_button_clicked():

       encrypt_message = encrypt_text.get("1.0", "end-1c")

       initial_shift_enc = int(shift_entry.get()) if shift_entry.get() else 0

       encrypted_message = encrypt(encrypt_message.lower(), initial_shift_enc)

       result_text.delete("1.0", tk.END)

       result_text.insert(tk.END, encrypted_message)

   def decrypt_button_clicked():

       decrypt_message = decrypt_text.get("1.0", "end-1c")

       initial_shift_dec = int(shift_entry.get())

       decrypted_message = decrypt(decrypt_message.lower(), initial_shift_dec)

       result_text.delete("1.0", tk.END)

       result_text.insert(tk.END, decrypted_message)

   root = tk.Tk()

   root.title("Trithemius Cipher")

   label1 = tk.Label(root, text="Введите текст для шифрования:")

   label1.pack()

   encrypt_text = tk.Text(root, height=5, width=30)

   encrypt_text.pack()

   label2 = tk.Label(root, text="Введите шаг (0 по умолчанию):")

   label2.pack()

   shift_entry = tk.Entry(root)

   shift_entry.pack()

   encrypt_button = tk.Button(root, text="Зашифровать", command=encrypt_button_clicked)

   encrypt_button.pack()

   label3 = tk.Label(root, text="Введите текст для расшифровки:")

   label3.pack()

   decrypt_text = tk.Text(root, height=5, width=30)

   decrypt_text.pack()

   decrypt_button = tk.Button(root, text="Расшифровать", command=decrypt_button_clicked)

   decrypt_button.pack()

   result_label = tk.Label(root, text="Результат:")

   result_label.pack()

   result_text = tk.Text(root, height=5, width=30)

   result_text.pack()

   root.mainloop()

def encrypt(secret_message, shift):

   encrypted_message = ""

   for char in secret_message:

       if char != ' ':

           encrypted_message += alphabet[(alphabet.index(char) + shift) % len(alphabet)]

           shift += 1

       else:

           encrypted_message += char

   return encrypted_message

def decrypt(secret_message, shift):

   decrypted_message = ""

   for char in secret_message:

       if char != ' ':

           decrypted_message += alphabet[(alphabet.index(char) - shift + len(alphabet)) % len(alphabet)]

           shift += 1

       else:

           decrypted_message += char

   return decrypted_message

alphabet = [

   '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'

]

trithemius_cipher()

Код на Python с текстовым меню:
def trithemius_cipher():

   print("Вы хотите Зашифровать или Расшифровать??\n1. Зашифровать\n2. Расшифровать\n")

   option = int(input())

   if option == 1:

       encrypt_message = input("\nВведите текст для зашифровки: ")

       initial_shift_enc = int(input("\nВведите шаг (0 по умолчанию): "))

       encrypted_message = encrypt(encrypt_message.lower(), initial_shift_enc)

       print("\nЗашифрованный текст:", encrypted_message)

   elif option == 2:

       decrypt_message = input("\nВведдите текст для расшифровки: ")

       initial_shift_dec = int(input("\nВведите шаг (0 по умолчанию): "))

       decrypted_message = decrypt(decrypt_message.lower(), initial_shift_dec)

       print("\nРасшифрованный текст:", decrypted_message)

   else:

       print("Введите правильное значение.")

def encrypt(secret_message, shift):

   encrypted_message = ""

   for char in secret_message:

       if char != ' ':

           encrypted_message += alphabet[(alphabet.index(char) + shift) % 26]

           shift += 1

       else:

           encrypted_message += char

   return encrypted_message

def decrypt(secret_message, shift):

   decrypted_message = ""

   for char in secret_message:

       if char != ' ':

           decrypted_message += alphabet[(alphabet.index(char) - shift + 26) % 26]

           shift += 1

       else:

           decrypted_message += char

   return decrypted_message

alphabet = ['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']

trithemius_cipher()

Приложения:
Похожие вопросы
Предмет: Английский язык, автор: karolinachorna04
Предмет: Алгебра, автор: sevaradovbysh
Предмет: Английский язык, автор: nazerkee136
помогите!!!
15. Change the sentence into the Passive voice: I’ve read the magazine.

a) The magazine has been read

b) The magazine is being read

c) The magazine had been read

d) The magazine will be read

e) The magazine has read

16. Where do British coronations and funerals take place?

a) Westminster Abbey b) Buckingham place c) The Tower Of London d) at home e) Trafalgar square

17. Find the alternative question.

a) Is he at home? b) Why are you late? c) Is he at home or at school? d) What is there? e) Who did you do it for?

18. Choose the right variant: If I (fail) the exam, my parents (forgive) me.

a) will, won’t forgive b) fail, would forgive c) failed, would forgive d) fail, won’t have forgiven e) fail, won’t forgive

19. Eliminate the extra word: milk, water, juice, tea, bread

a) juice b) bread c) tea d) water e) milk

20. Choose the word with common meaning:

a) woman b) boy c) person d) baby e) man

21. Choose the verb in Past Perfect Tense. It ... before we came here.

a) happened b) has happened c) had happened d) to happen e) have happened

22. Live the right English equivalent: сақтау

a) matter b) storage c) substance d) store-room e) production

23. Schools and many businesses ... always .. on Thanksgiving. Day the day after.

a) are, closed b) is, closed c) was, closed d) were, closed e) are, close

24. Her fingers touched his forehead and ... there.

a) rest b) all answer are right c) fixed d) rest of e) left

25. This car is fantastic. I wish I ... a similar one.

a) has b) have had c) have d) had e) has had

26. Attempt

a) мүмкін b) мүмкін болғанша c) мүмкіндік d) болу e) дайын

27. What feeling concerns to the next sentence: We are sorry to have remind you ...

a) regret b) gratitude c) pleasure d) remind e) surprise

28. Live the right variant of Participle: Name some places .... by you last year.

a) visit b) are visited c) to visit d) visiting e) visited

29. Choose the correct word to fill in: The ..... between wild animals is very complex.

a) actions b) relations c) interactions d) protections e) influence

30. The synonym of the word : to shiver

a) to ache b) tremble c) to refuse d) to hurt e) to turn