-
Notifications
You must be signed in to change notification settings - Fork 3
/
e.py
81 lines (60 loc) · 2.19 KB
/
e.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from Tkinter import *
def show_entry_field():
print("Enter your massage:%s\n Your encrypted message is:%s\n Enter your message:%s\n Your decrypted message is:%s\n"%(e1.get(),e2.get(),e3.get(),e4.get()))
def __init__(self, master):
self.master = master
master.title("Calculator")
self.total = 0
self.entered_number = 0
self.total_label_text = IntVar()
master=Tk()
Label(master,text="Enter your message:").grid(row=0)
Label(master,text="Your encrypted message is:").grid(row=3)
Label(master,text="Enter your message:").grid(row=5)
Label(master,text="Your decrypted message is:").grid(row=7)
alphabet = "abcdefghijklmnopqrstuvwxyz"
key = 4
var1 = StringVar()
var2 = StringVar()
var3 = StringVar()
var4 = StringVar()
e1=Entry(textvariable=var1)
e2=Entry(textvariable=var2)
e3=Entry(textvariable=var3)
e4=Entry(textvariable=var4)
e1.grid(row=0,column=1)
e2.grid(row=3,column=1)
e3.grid(row=5,column=1)
e4.grid(row=7,column=1)
#vcmd = master.register(self.validate)
#self.entry = Entry(master, validate="key", validatecommand=(vcmd, '%P'))
def encrypt():
newmessage = ''
mystring = var1.get()
for character in mystring:
if character in alphabet:
position = alphabet.find(character)
newposition = (position + int(key)) % 26
newcharacter = alphabet[newposition]
newmessage += newcharacter
else:
newmessage += character
var2.set(newmessage)
return
def decrypt():
newmessage = ''
mystring = var3.get()
for character in mystring:
if character in alphabet:
position = alphabet.find(character)
newposition = (position - int(key)) % 26
newcharacter = alphabet[newposition]
newmessage += newcharacter
else:
newmessage += character
var4.set(newmessage)
return
b1=Button(master,text="Encrypt",command=encrypt).grid(row=1,column=1)
b2=Button(master,text="Decrypt",command=decrypt).grid(row=6,column=1)
Button(master,text="Close",command=master.quit).grid(row=9,column=1)
mainloop()