from PySide2.QtWidgets import QApplication, QMessageBox
from PySide2.QtUiTools import QUiLoader
from PySide2.QtCore import QFile
class Stats:
def __init__(self):
# 从文件中加载UI定义
qfile_stats = QFile("main.ui")
qfile_stats.open(QFile.ReadOnly)
qfile_stats.close()
# 从 UI 定义中动态 创建一个相应的窗口对象
# 注意:里面的控件对象也成为窗口对象的属性了
# 比如 self.ui.button , self.ui.textEdit
self.ui = QUiLoader().load('main.ui')
self.ui.pushButton.clicked.connect(self.box_a)
self.ui.pushButton_2.clicked.connect(self.box_z)
def box_a(self):
"""
加密
:param aa: 明文
:param j_n: key =
:return: 加密后的密文
"""
text = self.ui.textEdit.toPlainText()
a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'b', 'w', 'x', 'y', 'z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'b', 'w', 'x', 'y', 'z', ]
list_b = []
list_b.extend(text)
num = 0
for x in list_b:
if x not in a:
pass
else:
list_b[num] = a[a.index(x) + int(6)]
num += 1
b = ''.join(list_b)
self.ui.textBrowser.setPlainText(b)
def box_z(self):
"""
解密
:param aa: 密文
:param j_n: key =
:return: 解密后的明文
"""
text = self.ui.textEdit.toPlainText()
a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'b', 'w', 'x', 'y', 'z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'b', 'w', 'x', 'y', 'z', ]
a.reverse()
list_b = []
list_b.extend(text)
num = 0
for x in list_b:
if x not in a:
pass
else:
list_b[num] = a[a.index(x) + int(6)]
num += 1
b = ''.join(list_b)
self.ui.textBrowser.setPlainText(b)
if __name__ == "__main__":
app = QApplication([])
stats = Stats()
stats.ui.show()
app.exec_()