-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencrypt_gui.py
More file actions
71 lines (56 loc) · 2.4 KB
/
encrypt_gui.py
File metadata and controls
71 lines (56 loc) · 2.4 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
import sys
import cv2
import numpy as np
from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QLabel, QLineEdit, QMessageBox
# Default input and output paths
image_path = r"C:\Users\aisha\OneDrive\Pictures\Saved_Pictures\Allah.jpg"
output_path = r"C:\Users\aisha\OneDrive\Desktop\Stenography-main\encryptedImage.png"
class EncryptGUI(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Image Encryption")
self.setGeometry(100, 100, 400, 300)
layout = QVBoxLayout()
self.label = QLabel("Enter secret message:")
layout.addWidget(self.label)
self.message_input = QLineEdit(self)
layout.addWidget(self.message_input)
self.label2 = QLabel("Enter passcode:")
layout.addWidget(self.label2)
self.password_input = QLineEdit(self)
self.password_input.setEchoMode(QLineEdit.EchoMode.Password)
layout.addWidget(self.password_input)
self.encrypt_button = QPushButton("Encrypt Image", self)
self.encrypt_button.clicked.connect(self.encrypt_image)
layout.addWidget(self.encrypt_button)
self.setLayout(layout)
def encrypt_image(self):
message = self.message_input.text()
password = self.password_input.text()
if not message or not password:
QMessageBox.warning(self, "Error", "Message and password cannot be empty!")
return
img = cv2.imread(image_path)
if img is None:
QMessageBox.warning(self, "Error", "Image not found or cannot be read.")
return
n, m, z = 0, 0, 0
# Store password and message length in the image
img[n, m, z] = np.uint8(len(password))
img[n + 1, m + 1, (z + 1) % 3] = np.uint8(len(message))
n += 2
m += 2
z = (z + 2) % 3
# Encrypt password and message into the image
for char in password + message:
img[n, m, z] = np.uint8(ord(char))
n += 1
m += 1
z = (z + 1) % 3
cv2.imwrite(output_path, img) # Save as PNG to avoid compression
QMessageBox.information(self, "Success", f"Message encrypted successfully!\nSaved at: {output_path}")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = EncryptGUI()
window.show()
sys.exit(app.exec())