from tkinter import *
from tkinter import messagebox
from tkinter import ttk
def Encrypt():
try:
text = str(textbox.get())
key = int(keybox.get())
result = ""
alphabet = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"
for i in text:
if i in alphabet:
result += alphabet[(alphabet.index(i) + key) % len(alphabet)]
else:
result += i
messagebox.showinfo("Результат", result)
except ValueError:
messagebox.showerror("Помилка", "Введіть правильні дані")
def Decrypt():
result += alphabet[(alphabet.index(i) - key) % len(alphabet)]
root = Tk()
root.title("Шифр Цезаря")
root.resizable(width=False, height=False)
textbox = ttk.Entry(root, width=30)
textbox.grid(row=0, column=0, columnspan=2, padx=5, pady=5)
keybox = ttk.Entry(root, width=30)
keybox.grid(row=1, column=0, columnspan=2, padx=5, pady=5)
encrypt_button = ttk.Button(root, text="Зашифрувати", command=Encrypt)
encrypt_button.grid(row=2, column=0, padx=5, pady=5)
decrypt_button = ttk.Button(root, text="Розшифрувати", command=Decrypt)
decrypt_button.grid(row=2, column=1, padx=5, pady=5)
root.mainloop()
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
from tkinter import *
from tkinter import messagebox
from tkinter import ttk
def Encrypt():
try:
text = str(textbox.get())
key = int(keybox.get())
result = ""
alphabet = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"
for i in text:
if i in alphabet:
result += alphabet[(alphabet.index(i) + key) % len(alphabet)]
else:
result += i
messagebox.showinfo("Результат", result)
except ValueError:
messagebox.showerror("Помилка", "Введіть правильні дані")
def Decrypt():
try:
text = str(textbox.get())
key = int(keybox.get())
result = ""
alphabet = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"
for i in text:
if i in alphabet:
result += alphabet[(alphabet.index(i) - key) % len(alphabet)]
else:
result += i
messagebox.showinfo("Результат", result)
except ValueError:
messagebox.showerror("Помилка", "Введіть правильні дані")
root = Tk()
root.title("Шифр Цезаря")
root.resizable(width=False, height=False)
textbox = ttk.Entry(root, width=30)
textbox.grid(row=0, column=0, columnspan=2, padx=5, pady=5)
keybox = ttk.Entry(root, width=30)
keybox.grid(row=1, column=0, columnspan=2, padx=5, pady=5)
encrypt_button = ttk.Button(root, text="Зашифрувати", command=Encrypt)
encrypt_button.grid(row=2, column=0, padx=5, pady=5)
decrypt_button = ttk.Button(root, text="Розшифрувати", command=Decrypt)
decrypt_button.grid(row=2, column=1, padx=5, pady=5)
root.mainloop()