大四网络安全作业,需要用python的simplegui实现简单界面。
1.第一题
代码:
import PySimpleGUI as sg
layout = [[sg.Text('明文'),sg.InputText(key="value")],
[sg.Text('加密'), sg.InputText(key="value1")],
[sg.Text('解密'),sg.InputText(key="value2")],
[sg.Button('加密'),sg.Button('解密'),sg.Button('取消')]]
window = sg.Window('密文转换', layout)
def add(string,k):
s=""
c=list(string)
for i in range(0,len(c)):
s=s+chr((ord(c[i])+k-ord('a'))%26+97)
return s
def debug(string,k):
s=""
c=list(string)
for i in range(0,len(c)):
s=s+chr((ord(c[i])-k+26-ord('a'))%26+97)
return s
while True:
event, values = window.read()
data = add(values['value'], 3)
sdata = debug(data, 3)
if event in (None, '取消'):
break
elif event in ('加密'):
window["value1"].update(data)
else:
window["value2"].update(sdata)
window.close()
效果:
第二题
代码:
import PySimpleGUI as sg
layout = [[sg.Text('明文'),sg.InputText(key="value")],
[sg.Text('加密'), sg.InputText(key="value1")],
[sg.Text('解密'),sg.InputText(key="value2")],
[sg.Button('加密'),sg.Button('解密'),sg.Button('取消')]]
window = sg.Window('密文转换', layout)
def add(string):
s=""
c=list(string)
for i in range(0,len(c)):
s=s+chr(((ord(c[i])-ord('a'))*3+5)%26+97)
return s
def debug(string):
s=""
c=list(string)
for i in range(0,len(c)):
for j in range(0,3):
if ((ord(c[i])-ord('a')-5+26*j)%3)==0:
s=s+chr(int((ord(c[i])-ord('a')-5+26*j)/3+97))
break
return s
while True:
event, values = window.read()
data = add(values['value'])
sdata = debug(data)
if event in (None, '取消'):
break
elif event in ('加密'):
window["value1"].update(data)
else:
window["value2"].update(sdata)
window.close()
效果:
|