-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.py
More file actions
160 lines (124 loc) · 5.35 KB
/
App.py
File metadata and controls
160 lines (124 loc) · 5.35 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
'''GUI Imports'''
import sys
from PyQt5.QtCore import QFile, QUrl
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
'''Other Scripts Imports'''
from Steg import decode, encode
from AudioSteg import audio_decode, audio_encode
'''Cryptography'''
from cryptography.fernet import Fernet
class Window(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle('StegaText')
self.setGeometry(10,10,800,600)
self._createEditor()
def _createEditor(self):
self.editor = QTextEdit()
menu = self.menuBar()
menu.setNativeMenuBar(False)
self.setCentralWidget(self.editor)
#Set up connection for encoding images
encodeImageAction = QAction('&Encode Image', self)
encodeImageAction.setStatusTip('Encode text into a image')
encodeImageAction.triggered.connect(self.encodeImage)
#Set up connection for decoding images
decodeImageAction = QAction('&Decode Image', self)
decodeImageAction.setStatusTip('Decode a image into text')
decodeImageAction.triggered.connect(self.decodeImage)
#Set up connection for encoding audio
encodeAudioAction = QAction('&Encode Audio', self)
encodeAudioAction.setStatusTip('Encode text into an audio file')
encodeAudioAction.triggered.connect(self.encodeAudio)
#Set up connection for decoding audio
decodeAudioAction = QAction('&Decode Audio', self)
decodeAudioAction.setStatusTip('Decode audio into text')
decodeAudioAction.triggered.connect(self.decodeAudio)
#Set up connection for encryption
encryptAction = QAction('&Encrypt Text', self)
encryptAction.setStatusTip('Encrypt the text using symmetric key encryption')
encryptAction.triggered.connect(self.encryptHelper)
#set up connection for decryption
decryptAction = QAction('&Decrypt Text', self)
decryptAction.setStatusTip('Decrypt the text using symmetric key decryption')
decryptAction.triggered.connect(self.decryptHelper)
fileMenu = menu.addMenu('File')
fileMenu.addAction(encodeImageAction)
fileMenu.addAction(decodeImageAction)
fileMenu.addSeparator()
fileMenu.addAction(encodeAudioAction)
fileMenu.addAction(decodeAudioAction)
encryptMenu = menu.addMenu('Encryption')
encryptMenu.addAction(encryptAction)
encryptMenu.addAction(decryptAction)
def encodeImage(self):
file, _ = QFileDialog.getOpenFileName(self, "Select Image File")
print(file)
url = QUrl.fromLocalFile(file)
encode(url.fileName(), self.editor.toPlainText())
def decodeImage(self):
file, _ = QFileDialog.getOpenFileName(self, "Select Encoded Image File")
url = QUrl.fromLocalFile(file)
self.editor.setText(decode(url.fileName()))
def encodeAudio(self):
file, _ = QFileDialog.getOpenFileName(self, "Select Audio File")
url = QUrl.fromLocalFile(file)
audio_encode(url.fileName(), self.editor.toPlainText())
print("done")
def decodeAudio(self):
file, _ = QFileDialog.getOpenFileName(self, "Select Encoded Audio File")
url = QUrl.fromLocalFile(file)
self.editor.setText(audio_decode(url.fileName()))
def encryptHelper(self):
print('encrypt text')
# if theres nothing to encrypt dont bother
if self.editor.toPlainText() != '':
# generate new key using the cryptography package
key = Fernet.generate_key()
print(key)
print(type(key))
# instanciate the fernet class
fernet = Fernet(key)
# get text form the text box
text = self.editor.toPlainText()
# perform the encryption
encryptedText = fernet.encrypt(text.encode())
#output the results
self.editor.clear()
self.editor.setText(encryptedText.decode('utf-8'))
# give the user their key
message = QMessageBox()
message.setText("This is your key for decryption please save this in a safe place.")
message.setInformativeText(key.decode('utf-8'))
message.setWindowTitle("Encrypt")
message.exec_()
else:
message = QMessageBox()
message.setText("No text to encrypt")
message.setWindowTitle("Encryption Error")
message.exec_()
def decryptHelper(self):
print('decrypt text')
if self.editor.toPlainText() != '':
key = QInputDialog.getText(self, 'Decrypt Text', 'Enter your key below')
bytesKey = bytes(key[0], 'utf-8')
fernet = Fernet(bytesKey)
encryptedText = self.editor.toPlainText()
bytesText = bytes(encryptedText, 'utf-8')
decodeText = fernet.decrypt(bytesText).decode()
self.editor.clear()
self.editor.setText(decodeText)
else:
message = QMessageBox()
message.setText("No text to decrypt")
message.setWindowTitle("Decryption Error")
message.exec_()
def main():
app = QApplication(sys.argv)
ex = Window()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()