-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmsgCipherGUI.py
More file actions
95 lines (68 loc) · 2.5 KB
/
msgCipherGUI.py
File metadata and controls
95 lines (68 loc) · 2.5 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
#! usr/bin/python3
"""
This GUI Program encrypts and decrypts messages
"""
import sys
import pyperclip
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class Window(QWidget):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
form= QFormLayout()
info=QLabel("This Application help\'s you encrypt and decrypt messages")
modeLabel=QLabel("Mode: ")
self.modeEn=QRadioButton("Encrypt")
self.modeDe=QRadioButton("Decrypt")
Hmode=QHBoxLayout()
Hmode.addWidget(self.modeEn)
Hmode.addWidget(self.modeDe)
keyLabel=QLabel("Secret Key: ")
self.keyinput=QLineEdit("0-26")
msgLabel= QLabel("Insert the Message ")
self.msginput=QTextEdit()
self.submitBtn= QPushButton("SUBMIT")
self.submitBtn.clicked.connect(self.Cipher)
form.addRow(info)
form.addRow(modeLabel,Hmode)
form.addRow(keyLabel,self.keyinput)
form.addRow(msgLabel)
form.addRow(self.msginput)
form.addRow(self.submitBtn)
self.setLayout(form)
self.setGeometry(100,100,400,300)
self.setWindowTitle("Cipher Application")
def Cipher(self):
try:
if self.modeEn.isChecked():
mode="encrypt"
elif self.modeDe.isChecked():
mode="decrypt"
message=self.msginput.toPlainText()
key=int(self.keyinput.text())
LETTERS= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
translated=''
message= message.upper()
for symbol in message:
if symbol in LETTERS:
num=LETTERS.find(symbol)
if mode=="encrypt":
num=num+key
elif mode=="decrypt":
num=num-key
if num >= len(LETTERS):
num= num- len(LETTERS)
elif num < 0:
num= num + len(LETTERS)
translated= translated + LETTERS[num]
else:
translated=translated + symbol
QMessageBox.information (self,"The {}ed Message ".format(mode),translated)
pyperclip.copy(translated)
except:
QMessageBox.information(self,"Whoah !!!","Check what you inserted")
if __name__=="__main__":
app=QApplication(sys.argv)
win=Window()
win.show()
sys.exit(app.exec_())