-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
47 lines (42 loc) · 1.35 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import tkinter as tk, random, math
from tkinter import *
from PIL import ImageTk, Image
# вы находитесь на ветке lesson_1
# вы находитесь на ветке MASTER
def coder():
k = random.randint(2, 9)
data = text.get("1.0", tk.END)
text.delete("1.0", tk.END)
out = ""
for i in range(len(data)):
out += str((ord(data[i]) * k) * math.factorial(k - 2)) + str(chr(random.randint(65, 90)))
text.insert("1.0", out + str(k))
def decoder():
data = text.get("1.0", tk.END)
k = int(data[len(data) - 2])
data = data[0:len(data) - 2]
text.delete("1.0", tk.END)
i_st = 0
mas = []
for i in range(len(data)):
if not (data[i].isdigit()):
mas.append(data[i_st: i])
i_st = i + 1
out = ""
for i in range(len(mas)):
out += chr(int((int(mas[i]) / math.factorial(k - 2)) / k))
text.insert("0.0", out)
a = 1
print("привет")
window = tk.Tk()
window.title("CODER")
window.geometry('400x250')
window.resizable(width=False, height=False)
window['bg'] = "#3191BB"
text = Text(window, width=38, height=7)
text.place(x=45, y=30)
btn1 = Button(window, text="ЗАКОДИРОВАТЬ", command=coder, font=60)
btn1.place(x=10, y=160)
btn2 = Button(window, text="РАСКОДИРОВАТЬ", command=decoder, font=60)
btn2.place(x=200, y=160)
window.mainloop()