-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
154 lines (131 loc) · 5.18 KB
/
Copy pathMain.py
File metadata and controls
154 lines (131 loc) · 5.18 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import cypher
import tkinter as tk
import string
def encryptcompat():
global eTextGlobal
eTextGlobal = ""
str1 = cypher.encrypt(textEntry.get(), rotEntry.get())
n = 95
chunks = [str1[i:i + n] for i in range(0, len(str1), n)]
encryptedText.set('\n'.join(chunks))
eTextGlobal = '\n'.join(chunks)
print("\n" + eTextGlobal)
def decrypt():
global dTextGlobal
global dcheck
global symbols
dcheck = ""
dTextGlobal = ""
if decryptInput.get() != "" and len(decryptInput.get()) <= 92:
text = []
for i in range(1, 27):
text.append(str(i) + " = " + cypher.encrypt(decryptInput.get(), i))
dcheck = dcheck + cypher.encrypt(decryptInput.get(), i) + " "
decryptedText.set('\n'.join(text))
for char in symbols:
dcheck = dcheck.replace(char, "")
dTextGlobal = '\n'.join(text)
print("\n" + dTextGlobal)
elif len(decryptInput.get()) > 92:
decryptedText.set("Too many characters... :(")
dTextGlobal = "Too many characters... :("
print("\n" + dTextGlobal)
else:
decryptedText.set("Invalid Input... :(")
dTextGlobal = "Invalid Input... :("
print("\n" + dTextGlobal)
def dTextWrite():
global dTextGlobal
dText = open("Decrypted.txt", "a")
dText.write("\n" + dTextGlobal + "\n")
dText.close()
def eTextWrite():
global eTextGlobal
eText = open("Encrypted.txt", "a")
eText.write(eTextGlobal + "\n")
eText.close()
def dTextWrite2():
global dTextGlobal
dText = open("Decrypted.txt", "w")
dText.write(dTextGlobal)
dText.close()
def eTextWrite2():
global eTextGlobal
eText = open("Encrypted.txt", "w")
eText.write(eTextGlobal + "\n")
eText.close()
def close():
global master
global Dict
Dict.close()
master.destroy()
def DictionnaryFunc():
global Dict2
global dcheck
global dictText
print(dcheck.split())
text = ""
for i in dcheck.split():
if i in Dict2:
text = text + i + ", "
dictText.set(text)
print(text)
dcheck = ""
dTextGlobal = ""
eTextGlobal = ""
symbols = [char for char in string.punctuation]
master = tk.Tk()
encryptedText = tk.StringVar()
decryptedText = tk.StringVar()
dictText = tk.StringVar()
master.title("Cipher")
master.configure(bg="#00bae9")
master.geometry("1355x650")
Dict = open("Dictionnary.txt", "r")
Dict2 = Dict.read()
Dict2 = Dict2.splitlines()
# Widgets
Title = tk.Label(master, text="This is the caesar cipher encryptor:\n", bg="#00bae9", font=("Courier", 10))
cryptText = tk.Label(master, text="Input text to encrypt here:", bg="#00bae9")
textEntry = tk.Entry(master, width=100)
cryptNum = tk.Label(master, text="Input rotation number here:", bg="#00bae9")
rotEntry = tk.Entry(master, width=100)
menubuttone = tk.Menubutton(master, text="Save text to file", width=35)
menubuttond = tk.Menubutton(master, text="Save text to file", width=35)
runButton = tk.Button(master, text="Run Encryptor", command=encryptcompat)
encryptOutput = tk.Label(master, textvariable=encryptedText, bg="#f5f2d0", width=96, height=26, font=("Courier", 9))
Title2 = tk.Label(master, text="This is the caesar cipher decryptor:\n", bg="#00bae9", font=("Courier", 10))
decryptText = tk.Label(master, text="Input text to decrypt here: (92 characters maximum)", bg="#00bae9")
drunButton = tk.Button(master, text="Run Decryptor", command=decrypt)
decryptInput = tk.Entry(master, width=100)
decryptOutput = tk.Label(master, textvariable=decryptedText, bg="#f5f2d0", width=96, height=26, font=("Courier", 9))
closeButton = tk.Button(master, text="Close program", command=close)
dictButton = tk.Button(master, text="Compare to dictionnay", command=DictionnaryFunc)
DictText = tk.Label(master, textvariable=dictText, bg="#f5f2d0", width=96, font=("Courier", 9))
# Grid
Title.grid(row=1, column=0, sticky="W")
cryptText.grid(row=2, column=0, sticky="W")
textEntry.grid(row=3, column=0, sticky="W")
cryptNum.grid(row=4, column=0, sticky="W")
rotEntry.grid(row=5, column=0, sticky="W")
runButton.grid(row=6, column=0, sticky="W")
encryptOutput.grid(row=7, column=0, sticky="W")
Title2.grid(row=1, column=3, sticky="W")
decryptText.grid(row=2, column=3, sticky="W")
decryptInput.grid(row=4, column=3, sticky="W")
drunButton.grid(row=6, column=3, sticky="W")
decryptOutput.grid(row=7, column=3, sticky="W")
menubuttone.grid(row=8, sticky="")
menubuttond.grid(row=8, column=3, sticky="")
closeButton.grid(row=9, sticky="W")
dictButton.grid(row=9, column=3, sticky="E")
DictText.grid(row=10, column=3, columnspan=3)
menubuttone.menu = tk.Menu(menubuttone)
menubuttone["menu"] = menubuttone.menu
menubuttone.menu.add_cascade(label="Write to text file", command=eTextWrite)
menubuttone.menu.add_cascade(label="Write to text file (override previous)", command=eTextWrite2)
menubuttond.menu = tk.Menu(menubuttond)
menubuttond["menu"] = menubuttond.menu
menubuttond.menu.add_cascade(label="Write to text file", command=dTextWrite)
menubuttond.menu.add_cascade(label="Write to text file (override previous)", command=dTextWrite2)
master.mainloop()