import random def crypto(message, alphabet, offset): result = '' for sym in message: if sym in alphabet: index = alphabet.find(sym) result += alphabet[(index + offset) % len(alphabet)] else: result += sym return result def decrypto(message, alphabet, offset): result = '' for sym in message: if sym in alphabet: index = alphabet.find(sym) result += alphabet[(index - offset) % len(alphabet)] else: result += sym return result ab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ' alphabet = ab + ab.lower() offset = int(random.uniform(0, 9)) message = input('введите текст: ') crypto = crypto(message, alphabet, offset) print(crypto) decrypto = decrypto(crypto, alphabet, offset) print(decrypto)
вот форма
[code python]
import tkinter as tk
from typing import List
win = tk.Tk()
win.title('Алгоритм шифрования подстановкой')
win.geometry('800x800+200+200')
win.resizable(False, False)
label1 = tk.Label(win,text='Текст для шифрования')
label2 = tk.Label(win,text='Ключ')
text = tk.Entry(win)
key = tk.Entry(win)
rslt1 = tk.Entry(win)
rslt2 = tk.Entry(win)
def dlt():
text1.delete(0, tk.END)
key.delete(0, tk.END)
rslt1.delete(0, tk.END)
rslt2.delete(0, tk.END)
btn1 = tk.Button(win,text='Зашифровать')
btn3 = tk.Button(win,text='Создать рандомный ключ')
btn4 = tk.Button(win,text='Очистить', command=dlt)
btn5 = tk.Button(win,text='Расшифровать')
label1.grid(row=0,column=0,stick='wens')
label2.grid(row=0,column=1,stick='wens')
text.grid(row=1,column=0,stick='wens')
key.grid(row=1,column=1,stick='wens')
btn1.grid(row=2,column=0,columnspan=2,stick='wens')
btn3.grid(row=3,column=0,columnspan=2,stick='wens')
btn4.grid(row=4,column=0,columnspan=2,stick='wens')
btn5.grid(row=5,column=0,columnspan=2,stick='wens')
rslt1.grid(row=6,column=0,stick='wens')
rslt2.grid(row=6,column=1,stick='wens')
win.grid_columnconfigure(0,minsize=400)
win.grid_columnconfigure(1,minsize=400)
win.grid_rowconfigure(0,minsize=40)
win.grid_rowconfigure(1,minsize=40)
win.grid_rowconfigure(2,minsize=40)
win.grid_rowconfigure(3,minsize=40)
win.grid_rowconfigure(4,minsize=40)
win.grid_rowconfigure(5,minsize=40)
win.grid_rowconfigure(6,minsize=40)
win.mainloop()
[/code]