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
# 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")
I_Frame = Frame(root, height=40, width=60)
II_Frame = Frame(root, height=80)
III_Frame = Frame(root, height=40, 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
'''
filename3 = ''
FileNameVar3 = StringVar()
save_file_Enter['textvariable'] = FileNameVar3'''
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()