-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcipher.py
More file actions
75 lines (61 loc) · 2.08 KB
/
Copy pathcipher.py
File metadata and controls
75 lines (61 loc) · 2.08 KB
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
from Tkinter import *
from pyDes import *
class MyGUI:
def __init__(self, master):
self.master = master
self.plainT = StringVar()
self.key = StringVar()
master.title("Cipher")
self.label1 = Label(master, text="Enter plaintext:")
self.label1.pack()
self.plainText = Entry(master, textvariable = self.plainT)
self.plainText.pack()
self.label3 = Label(master, text="Enter appropriate key:")
self.label3.pack()
self.keyLabel = Entry(master, textvariable = self.key)
self.keyLabel.pack()
self.label2 = Label(master, text="Encrypted text:")
self.label2.pack()
self.resultText = Label(master, text = "")
self.resultText.pack()
self.ceaserB = Button(master, text="Ceaser cipher", command=self.ceaserCipher)
self.ceaserB.pack()
self.desB = Button(master, text=" DES ", command=self.des)
self.desB.pack()
self.pfB = Button(master, text =" Playfair ", command=self.pf)
self.pfB.pack()
self.close_button = Button(master, text="Close", command=master.quit)
self.close_button.pack()
def pf():
pass
def ceaserCipher(self):
print 'Ceaser cipher'
plain = self.plainT.get().lower()
ceaserKey = self.key.get()
if ceaserKey.isalpha():
print 'Key needs to be a number!'
return
ceaserKey = int(ceaserKey)
encrypted = []
for char in plain:
newChar = (ord(char) - 97 + ceaserKey) % 26
newChar = newChar + 97
encrypted.append(chr(newChar))
self.resultText['text'] = ''.join(encrypted)
def des(self):
print ("DES encryption")
desKey = self.key.get()
if len(desKey) != 8:
print 'DES key needs to be 8 bytes long!'
return
k = des(desKey)
data = "DES encryption algorithm"
d = k.encrypt(data)
print 'Encrypted:'
print (d)
self.resultText['text'] = unicode(d, 'iso8859-1')
# d = k.decrypt(d)
# print (d)
root = Tk()
my_gui = MyGUI(root)
root.mainloop()