forked from dhodge1/espionage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathespy.pyw
162 lines (147 loc) · 4.23 KB
/
espy.pyw
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
155
156
157
158
159
160
161
162
#!/usr/bin/python
from tkinter import *
from tkinter import filedialog
from sys import argv
root=Tk()
root.geometry("335x160")
#root.geometry("415x205+100+100")
root.title("Basic File Encryption/Decrytion")
encKey = {
'a' : 'b',
'b' : 'c',
'c' : 'd',
'd' : 'e',
'e' : 'f',
'f' : 'g',
'g' : 'h',
'h' : 'i',
'i' : 'j',
'j' : 'k',
'k' : 'l',
'l' : 'm',
'm' : 'n',
'n' : 'o',
'o' : 'p',
'p' : 'q',
'q' : 'r',
'r' : 's',
's' : 't',
't' : 'u',
'u' : 'v',
'v' : 'w',
'w' : 'x',
'x' : 'y',
'y' : 'z',
'z' : 'a',
',' : '.',
' ' : '@',
'.' : ',',
'!' : '?',
'?' : '!',
'@' : ' ',
'"' : '*',
'*' : '"',
'\'' : '$',
'$' : '\'',
'(' : ')',
')' : '(',
'-' : '_',
'_' : '-',
'+' : '=',
'=' : '+',
'%' : '^',
'^' : '%',
'#' : '>',
'>' : '#',
'&' : '[',
'[' : '&',
'1' : '2',
'2' : '3',
'3' : '4',
'4' : '5',
'5' : '6',
'6' : '7',
'7' : '8',
'8' : '9',
'9' : '0',
'0' : '1',
':' : '/',
'/' : ';',
';' : ':'
}
decKey = dict(zip(encKey.values(), encKey.keys()))
def openFile():
global f
filename = filedialog.askopenfilename()
f = open(filename)
#outfile = "encrypted_" + argv[1]
def saveFile():
global fout
outfile = filedialog.asksaveasfilename(defaultextension=".txt")
fout = open(outfile, "w")
def encrypt():
global f
global fout
global encKey
for line in f:
lineL = line.lower()
words = lineL.split()
j = 0
for word in words:
letters = list(word)
i = 0
for letter in letters:
letters[i] = encKey[letter]
i = i + 1
word = ''.join(letters)
words[j] = word
j = j + 1
lineL = ' '.join(words)
fout.write(lineL)
fout.close()
f.close()
def decrypt():
global f
global fout
global decKey
for line in f:
lineL = line.lower()
words = lineL.split()
j = 0
for word in words:
letters = list(word)
i = 0
for letter in letters:
letters[i] = decKey[letter]
i = i + 1
word = ''.join(letters)
words[j] = word
j = j + 1
lineL = ' '.join(words)
fout.write(lineL)
fout.close()
f.close()
menubar = Menu(root)
fileMenu = Menu(menubar)
fileMenu.add_command(label = "Open", command=openFile)
fileMenu.add_command(label = "Save as", command=saveFile)
menubar.add_cascade(label="File", menu=fileMenu)
actionMenu = Menu(menubar)
actionMenu.add_command(label = "Encrypt", command=encrypt)
actionMenu.add_command(label = "Decrypt", command=decrypt)
menubar.add_cascade(label="Actions", menu=actionMenu)
#aLab = Label(root, text="").grid(row=0, column=0, sticky=E)
bLab = Label(root, text="").grid(row=1, column=0, sticky=E)
oLab = Label(root, text=" Step 1) Choose a file to open: ").grid(row=2, column=0, sticky=W)
cLab = Label(root, text="").grid(row=3, column=0, sticky=E)
sLab = Label(root, text=" Step 2) Choose name to save file as: ").grid(row=4, column=0, sticky=W)
dLab = Label(root, text="").grid(row=5, column=0, sticky=E)
runLab = Label(root, text=" Step 3) Run process ").grid(row=6, column=0, sticky=W)
openF = Button(root, text=" Open ", command=openFile).grid(row=2, column=1)
saveF = Button(root, text="Save as", command=saveFile).grid(row=4, column=1)
encr = Button(root, text="Encrypt", command=encrypt).grid(row=6, column=1)
eLab = Label(root, text="").grid(row=6, column=2, sticky=E)
fLab = Label(root, text="").grid(row=6, column=3, sticky=E)
decr = Button(root, text="Decrypt", command=decrypt).grid(row=6, column=4)
root.configure(menu=menubar)
root.mainloop()