-
Notifications
You must be signed in to change notification settings - Fork 0
/
supstitutionFrame.py
83 lines (64 loc) · 2.88 KB
/
supstitutionFrame.py
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
import sys
from strings import supstitution_txt
from PyQt5.QtWidgets import (QWidget, QLabel, QSpinBox, QComboBox, QPlainTextEdit, QLineEdit, QHBoxLayout, QVBoxLayout, QGridLayout,QPushButton, QApplication, QFrame)
from PyQt5 import QtCore
from PyQt5 import QtGui
from frameTemplate import frameTemplate
from ciphers.supstitution import Supstitution
class supstitutionFrame(frameTemplate):
def __init__(self):
super().__init__()
self.sp = Supstitution()
self.initUI()
def initUI(self):
super().initUI()
self.definition.insertPlainText(supstitution_txt)
self.cb_method.addItem("Encrypt")
self.cb_method.addItem("Decrypt")
self.cb_method.addItem("Brute Force")
self.cb_method.currentIndexChanged.connect(self.selectionChange)
regex = QtCore.QRegExp("^[a-zA-Z]+$")
validator = QtGui.QRegExpValidator(regex, self.plaintext)
self.plaintext.setValidator(validator)
self.btn_encrypt.clicked.connect(self.encrypt)
#odabir ključa šifriranja
self.spinbox_key = QSpinBox()
self.spinbox_key.setRange(1,26)
self.spinbox_key.singleStep()
#oznaka za odabir ključa
self.label_key = QLabel()
self.label_key.setText('Ključ:')
self.encryption_v_box.addWidget(self.label_key)
self.encryption_v_box.addWidget(self.spinbox_key)
def selectionChange(self, index):
self.btn_encrypt.clicked.disconnect()
if (self.cb_method.itemText(index) == "Encrypt"):
self.label_plaintext.setText("Plaintext:")
self.label_ciphertext.setText("Ciphertext:")
self.btn_encrypt.clicked.connect(self.encrypt)
self.btn_encrypt.setText("Encrypt")
self.plaintext.clear()
self.ciphertext.clear()
elif(self.cb_method.itemText(index) == "Decrypt"):
self.label_plaintext.setText("Ciphertext:")
self.label_ciphertext.setText("Plaintext:")
self.btn_encrypt.clicked.connect(self.decrypt)
self.btn_encrypt.setText("Decrypt")
self.plaintext.clear()
self.ciphertext.clear()
elif(self.cb_method.itemText(index) == "Brute Force"):
self.label_plaintext.setText("Ciphertext:")
self.label_ciphertext.setText("Plaintext:")
self.btn_encrypt.clicked.connect(self.bruteForce)
self.btn_encrypt.setText("Decrypt")
self.plaintext.clear()
self.ciphertext.clear()
def encrypt(self):
text = self.sp.encrypt(self.plaintext.text(), self.spinbox_key.value())
self.ciphertext.setText(text)
def decrypt(self):
text = self.sp.decrypt(self.plaintext.text(), self.spinbox_key.value())
self.ciphertext.setText(text)
def bruteForce(self):
text = self.sp.bruteForce(self.plaintext.text())
self.ciphertext.setText(text)