-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecrypt_ui.py
More file actions
128 lines (99 loc) · 3.65 KB
/
decrypt_ui.py
File metadata and controls
128 lines (99 loc) · 3.65 KB
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
#!/usr/bin/env python
from decryptorator5000 import read_text, print_list, solve, text_to_list, read_plain_text
import random
import sys
import types
import PyQt5
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QWidget, QLabel, QApplication, QVBoxLayout, QHBoxLayout, QLayout, QPushButton, QMainWindow, QFileDialog, QTextEdit
# !!! Im using an old pyqt5 file i used to learn qt5 !!!
#####
# base class for a qtApp
class app(QApplication):
def __init__(self, args):
QApplication.__init__(self, args)
print("Arguments-> ", args)
# widgetClass for Window which contains a layout
class window(QWidget):
__layout = QVBoxLayout()
def __init__(self, widget: QWidget = None):
QWidget.__init__(self)
if(not widget is None):
self.__layout.addWidget(widget)
self.setLayout(self.__layout)
def getLayout():
return __layout
# just a general custom widget....actually contains the layout for everything....pass one of these to a window
class wid(QWidget):
__widgets = []
__layout = QVBoxLayout()
def __init__(self, widgets: [] = None, layout: QLayout = None):
QWidget.__init__(self)
if(not widgets is None):
self.__widgets = widgets
if(not layout is None):
self.__layout = layout
for i in self.__widgets:
self.__layout.addWidget(i)
print(i)
self.setLayout(layout)
def getLayout():
return __layout
# def _setLayout(layout: QLayout):
# self.__layout = layout
# QWidget.setLayout(layout)
def getWidgets():
return __widgets
def pushWidget(widget: QWidget):
__widgets.append(widget)
#####
cipher: list = None
plaintext: list = None
letter_map: dict = None
# when filedialogue file is chosen
def open_file(dia: QFileDialog, cipher_text: QTextEdit, plaintext_text: QTextEdit):
file = dia.getOpenFileName()
cipher = read_text(file[0])
cipher_text.setText(read_plain_text(file[0]))
temp = solve(text_to_list(cipher_text.toPlainText()))
plaintext = temp[0].copy()
letter_map = temp[1].copy()
plaintext_text.setText(str(plaintext))
# when solve button is hit
def solve_cipher(cipher_text: QTextEdit, plaintext_text: QTextEdit):
if cipher_text.toPlainText() is "":
print("No Text in Cipher object")
sys.exit(1)
return
# if(not (plaintext_text.toPlainText() is "")):
# cipher_text.setText(list_to_string(plaintext_text.toPlainText()))
temp = solve(text_to_list(cipher_text.toPlainText()))
plaintext = temp[0].copy()
letter_map = temp[1].copy()
plaintext_text.setText(str(plaintext))
return plaintext
# ui driver for this script
if __name__ == "__main__":
# get commandline args and create new app
m_app = app(sys.argv)
# make new label and button for file selection
m_button = QPushButton("Choose File")
m_label = QLabel("Select File: ")
m_cipher_text = QTextEdit("")
# m_cipher_text.setDisabled(True)
m_cipher_label = QLabel("Cipher: ")
m_plain_text = QTextEdit("")
m_plain_text.setDisabled(True)
m_plaintext_label = QLabel("Plain Text: ")
m_solve_btn = QPushButton("Solve")
m_solve_btn.clicked.connect(lambda: solve_cipher(m_cipher_text, m_plain_text))
# new layout widget
m_widget = wid([m_label, m_button, m_cipher_label, m_cipher_text, m_plaintext_label, m_plain_text, m_solve_btn], QVBoxLayout())
# new file chooser
m_file_chooser = QFileDialog(m_widget, "Choose File", ".", "")
m_button.clicked.connect(lambda: open_file(m_file_chooser, m_cipher_text, m_plain_text))
# new window
m_window = window(m_widget)
m_window.show()
# main loop till exit
sys.exit(m_app.exec_())