-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainProgram.py
More file actions
131 lines (117 loc) · 5.31 KB
/
mainProgram.py
File metadata and controls
131 lines (117 loc) · 5.31 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
#!usr/bin/python3
# import Important modules
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.uic import loadUiType
from stegano import lsb
from AES_FILE import PrpCrypt
from os import path
import sys , time , os
# import UI file
FORM_CLASS,_ = loadUiType(path.join(path.dirname(__file__),'mainProgram.ui'))
class mainApp1(QMainWindow, FORM_CLASS):
def __init__(self, parent=None):
super(mainApp1,self).__init__(parent)
QMainWindow.__init__(self)
self.setupUi(self)
self.handle_ui()
self.handle_button()
def handle_ui(self):
self.setFixedSize(1083,834)
self.setWindowIcon(QIcon('photos/lock.png'))
def handle_button(self):
self.pushButton.clicked.connect(self.select_image)
self.pushButton_2.clicked.connect(self.select_operation_hide)
self.pushButton_3.clicked.connect(self.select_operation_show)
self.pushButton_11.clicked.connect(self.setOutput)
self.pushButton_8.clicked.connect(self.process)
# Get image Information
def select_image(self):
try:
url_dir = QFileDialog.getOpenFileName(self, 'Select image', '', 'Image Files (*.png)')
Directory = url_dir[0]
base = path.basename(Directory)
name = path.splitext(base)[0]
extension = path.splitext(base)[1]
size = path.getsize(Directory)
self.lineEdit.setText(Directory)
self.lineEdit_2.setText(name)
self.lineEdit_5.setText(extension[1:])
if size < 1000:
self.lineEdit_3.setText(str(size) + ' Bytes')
else:
size /= 1000
self.lineEdit_3.setText(str(size) + ' KB')
except:
pass
def select_operation_show(self):
self.label_21.setText('SHOW')
def select_operation_hide(self):
self.label_21.setText('HIDE')
def setOutput(self):
url_output = QFileDialog.getSaveFileName(self, 'Save As', '', 'Image Files (*.png);; Text Files (*.txt)')
Directory_output = url_output[0]
self.lineEdit_4.setText(Directory_output)
def process(self):
key_key = self.plainTextEdit.toPlainText()
message = self.plainTextEdit_2.toPlainText()
image = self.lineEdit.text()
pathSave = self.lineEdit_4.text()
choice = self.label_21.text()
if choice == 'HIDE':
if (key_key != '') and (message != '') and (image != '') and (pathSave != ''):
try:
#QMessageBox.about(self,' wait', 'waiting ...!')
encrypted_message = PrpCrypt(key_key).encrypt(message)
encrypted_message_str = encrypted_message.decode() # convert byte to str
secret = lsb.hide(image, encrypted_message_str, auto_convert_rgb=True)
secret.save(pathSave)
#time.sleep(1)
QMessageBox.about(self, 'terminate', 'DONE!')
self.plainTextEdit.setPlainText('')
self.plainTextEdit_2.setPlainText('')
self.lineEdit_2.setText('')
self.lineEdit.setText('')
self.lineEdit_3.setText('')
self.lineEdit_5.setText('')
self.lineEdit_4.setText('')
except:
QMessageBox.about(self, 'Error', '<font color=White>Failed operation, Try again !')
else:
QMessageBox.about(self, 'Error', '<font color=White>Please Enter all fields to continue ..')
elif choice == 'SHOW':
if (key_key != '') and (image != ''):
try:
# QMessageBox.about(self,' wait', 'waiting ...!')
clear_message = lsb.reveal(image)
clear_message_bytes = str.encode(clear_message) # convert str to bytes
decrypted_text = PrpCrypt(key_key).decrypt(clear_message_bytes)
op = True
if op == True:
file_secure_output = self.lineEdit_4.text()
open_open = open(file_secure_output, "w")
open_open.writelines(decrypted_text)
open_open.close()
#time.sleep(1)
QMessageBox.about(self, 'Success', '<font color=White>Done! Your message was stored in:\n{}'.format(file_secure_output))
self.plainTextEdit.setPlainText('')
self.plainTextEdit_2.setPlainText('')
self.lineEdit_2.setText('')
self.lineEdit.setText('')
self.lineEdit_3.setText('')
self.lineEdit_5.setText('')
self.lineEdit_4.setText('')
except:
QMessageBox.about(self, 'Error', '<font color=White>Wrong key !')
else:
QMessageBox.about(self, 'Error', '<font color=White>Wrong key or your image not found !')
else:
QMessageBox.about(self, 'Error', '<font color=White>Please select an operation (hide or show) to continue ...')
def main():
app = QApplication(sys.argv)
window = mainApp1()
window.show()
app.exec_()
if __name__ == "__main__":
main()