coding utf-8 from Tkinter import from tkFileDialog import import paszi

  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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# coding=utf-8
from Tkinter import *
from tkFileDialog import *
import paszi
import tkMessageBox
import os
'''
root = Tk()
root.title('RSA program')
root.minsize(400, 500)
root.geometry("400x500+450+100")
#=====================Frames=================
I_Frame = Frame(root, height=40, width=60)
II_Frame = Frame(root, height=80)
III_Frame = Frame(root, height=20, width=60)
IV_Frame = Frame(root, height=80, width=60)
V_Frame = Frame(root, height=80, width=60)
VI_Frame = Frame(root, height=80)
I_Frame.pack(side='top', fill='x')
II_Frame.pack(side='top', fill='x')
III_Frame.pack(side='top', fill='x')
IV_Frame.pack(side='top', fill='x')
V_Frame.pack(side='top', fill='x')
VI_Frame.pack(side='top', fill='x')
file_Enter = Entry(II_Frame, font="Arial 16", width=30)
file_Enter.pack(side='top')
I_Label = Label(IV_Frame, text=u"Что вы хотите сделать с файлом?", font="Arial 14")
I_Label.pack(side='top', fill='x')
op_key_Enter = Entry(V_Frame, font="Arial 16", width=30)
sec_key_Enter = Entry(V_Frame, font="Arial 16", width=30)
II_Label = Label(V_Frame, text=u"Введите ключ", font="Arial 12")
filename1 = ''
FileNameVar1 = StringVar()
file_Enter['textvariable'] = FileNameVar1
filename2 = ''
FileNameVar2 = StringVar()
sec_key_Enter['textvariable'] = FileNameVar2
open_key = ''
OpenKeyVar = StringVar()
op_key_Enter['textvariable'] = OpenKeyVar
def openfile_crypt():
global filename1
filename1 = askopenfilename()
FileNameVar1.set(filename1)
def openfile_key():
global filename2
filename2 = askopenfilename()
FileNameVar2.set(filename2)
def openfile_save():
global filename3
filename3 = askopenfilename()
FileNameVar3.set(filename3)
P = 127
Q = 109
F = paszi.gen_f(P, Q)
N = paszi.gen_n(P, Q)
def encrypt_file():
global filename1
try:
if (int(OpenKeyVar.get()) < F) & (int(F) % int(OpenKeyVar.get()) != 0):
if os.path.exists(filename1):
paszi.encrypt(filename1, OpenKeyVar.get(), N)
tkMessageBox.showinfo("Encrypting", "Successful!")
else:
tkMessageBox.showinfo("ERROR", "Wrong file name")
else:
tkMessageBox.showinfo("ERROR", "Wrong open key")
except Exception:
tkMessageBox.showinfo("ERROR", "Something wrong")
def decrypt_file():
global filename1
paszi.decrypt(filename1, 9421, 13843)
#tkMessageBox.showinfo("Decrypt", "It's OK")
def encrypt_place():
get_key_Btn.pack_forget()
sec_key_Enter.pack_forget()
op_key_Enter.pack(side='top')
II_Label.pack(side='top')
get_key_Btn = Button(VI_Frame, text=u'Загрузить ключ', font="Arial 12")
def decrypt_place():
op_key_Enter.pack_forget()
II_Label.pack_forget()
get_key_Btn.pack(side='top')
sec_key_Enter.pack(side='top')
get_key_Btn['command'] = openfile_key
var = IntVar()
enc_button = Radiobutton(IV_Frame, text='Зашифровать', variable=var, value=1, font="Arial 14")
dec_button = Radiobutton(IV_Frame, text='Расшифровать', variable=var, value=2, font="Arial 14")
enc_button.pack(side='top')
dec_button.pack(side='top')
enc_button['command'] = encrypt_place
dec_button['command'] = decrypt_place
loadBtn = Button(II_Frame, text=u'Загрузить файл', font="Arial 12")
loadBtn.pack(side='bottom')
loadBtn['command'] = openfile_crypt
root.mainloop()
'''
class MainWin:
def __init__(self, master):
self.master = master
self.master.title('RSA program')
self.master.geometry("400x500+450+100")
self.master.minsize(400, 500)
self.file_enter = Entry()
self.file_enter.pack()
self.contents = StringVar()
self.file_enter["textvariable"] = self.contents
self.file_button = Button(self.master, text=u'Загрузить файл', command=self.open_file(self.contents))
self.file_button.pack()
self.chose_label = Label(self.master, text=u'Что вы хотите сделать с файлом?')
self.var = IntVar()
self.enc_button = Radiobutton(self.master, text='Зашифровать', variable=self.var, value=1)
self.dec_button = Radiobutton(self.master, text='Расшифровать', variable=self.var, value=2)
self.enc_button.pack()
self.dec_button.pack()
self.enc_button['command'] = self.encrypt_place
self.dec_button['command'] = self.decrypt_place
self.op_key_enter = Entry()
self.sec_key_enter = Entry()
self.key_label = Label(self.master, text=u"Введите ключ")
self.sec_key_btn = Button(self.master, text=u'Загрузить ключ')
self.master.mainloop()
def open_file(self, v):
filename = askopenfilename()
v.set(filename)
if filename == '':
tkMessageBox.showinfo("Oops", "Wrong file name")
def encrypt_place(self):
self.sec_key_btn.pack_forget()
self.sec_key_enter.pack_forget()
self.op_key_enter.pack()
self.key_label.pack()
def decrypt_place(self):
self.op_key_enter.pack_forget()
self.key_label.pack_forget()
self.sec_key_btn.pack(side='top')
self.sec_key_enter.pack(side='top')
cont = StringVar()
self.sec_key_enter["textvariable"] = cont
self.sec_key_btn['command'] = self.open_file(cont)
# создание окна
root = Tk()
# запуск окна
MainWin(root)