OPTIMIZATION , EFFIIENCY
AND SECURITY OF
ENCRYPTION ALGORITHM
BASED ON IMAGE
PROCESSING
PYTHON CODING:
import tkinter as tk
from tkinter import filedialog, messagebox, Label, Button, Frame
from PIL import ImageTk, Image
import cv2
import numpy as np
import os
# User database (for simplicity)
users = {}
class ImageEncryptorApp:
def __init__(self, master):
[Link] = master
[Link]("Image Encryption Decryption")
[Link]('-fullscreen', True)
[Link]("<Escape>", self.exit_fullscreen)
[Link] = ""
self.unique_key = ""
self.is_sender = None
self.img_path = None
self.original_image = None
self.encrypted_img_path = 'output/image_encrypted.jpg'
# Create directories for input and output images
[Link]('input', exist_ok=True)
[Link]('output', exist_ok=True)
self.init_login_screen()
def init_login_screen(self):
self.clear_frame()
self.login_frame = Frame([Link])
self.login_frame.pack()
Label(self.login_frame, text="Login", font=("Times New Roman",
40)).pack(pady=20)
Label(self.login_frame, text="Username", font=("Times New Roman",
20)).pack(pady=5)
self.username_entry = [Link](self.login_frame, font=("Times New
Roman", 20))
self.username_entry.pack(pady=5)
Label(self.login_frame, text="Password", font=("Times New Roman",
20)).pack(pady=5)
self.password_entry = [Link](self.login_frame, show="*",
font=("Times New Roman", 20))
self.password_entry.pack(pady=5)
Label(self.login_frame, text="Unique Key", font=("Times New Roman",
20)).pack(pady=5)
self.key_entry = [Link](self.login_frame, font=("Times New Roman",
20))
self.key_entry.pack(pady=5)
Button(self.login_frame, text="Login", command=self.login_user,
font=("Times New Roman", 20)).pack(pady=10)
Button(self.login_frame, text="Register", command=self.register_user,
font=("Times New Roman", 20)).pack(pady=10)
Button(self.login_frame, text="Exit", command=self.exit_app,
font=("Times New Roman", 20)).pack(pady=10)
def clear_frame(self):
for widget in [Link].winfo_children():
[Link]()
def exit_fullscreen(self, event=None):
[Link]('-fullscreen', False)
def exit_app(self):
[Link]() # Exit the application
def login_user(self):
username = self.username_entry.get()
password = self.password_entry.get()
unique_key = self.key_entry.get()
if username in users and users[username][0] == password and
users[username][1] == unique_key:
[Link] = username
self.unique_key = unique_key
self.init_main_screen()
else:
[Link]("Error", "Invalid credentials or unique key!")
def register_user(self):
username = self.username_entry.get()
password = self.password_entry.get()
unique_key = self.key_entry.get()
if username in users:
[Link]("Error", "User already exists!")
else:
users[username] = (password, unique_key)
[Link]("Success", "Registration successful!")
def init_main_screen(self):
self.clear_frame()
self.main_frame = Frame([Link])
self.main_frame.pack()
Label(self.main_frame, text="Choose Role", font=("Times New
Roman", 40)).pack(pady=20)
Button(self.main_frame, text="Sender", command=self.sender_mode,
font=("Times New Roman", 20)).pack(pady=10)
Button(self.main_frame, text="Receiver", command=self.receiver_mode,
font=("Times New Roman", 20)).pack(pady=10)
def sender_mode(self):
self.is_sender = True
self.init_image_screen()
def receiver_mode(self):
self.is_sender = False
self.init_image_screen()
def init_image_screen(self):
self.clear_frame()
Label([Link], text="Image Encryption/Decryption", font=("Times
New Roman", 40)).pack(pady=20)
self.image_label = Label([Link])
self.image_label.pack(pady=10)
if self.is_sender:
Button([Link], text="Choose Image", command=self.open_img,
font=("Times New Roman", 20)).pack(pady=10)
Button([Link], text="Encrypt", command=self.en_fun,
font=("Times New Roman", 20)).pack(pady=10)
else:
self.display_encrypted_image()
Button([Link], text="Decrypt", command=self.de_fun,
font=("Times New Roman", 20)).pack(pady=10)
Button([Link], text="Exit", command=self.exit_to_login,
font=("Times New Roman", 20)).pack(pady=10)
def open_img(self):
self.img_path = [Link](title='Open Image',
initialdir='input')
if self.img_path:
img = [Link](self.img_path)
[Link]((400, 400))
img_display = [Link](img)
self.image_label.configure(image=img_display)
self.image_label.image = img_display
self.image_label['text'] = 'Chosen Image:'
self.original_image = img
[Link](self.img_path, f'input/{[Link](self.img_path)}')
self.img_path = f'input/{[Link](self.img_path)}'
def en_fun(self):
if not self.img_path:
[Link]("Error", "No image selected!")
return
image_input = [Link](self.img_path, 0)
(x1, y) = image_input.shape
image_input = image_input.astype(float) / 255.0
mu, sigma = 0, 0.1
key = [Link](mu, sigma, (x1, y)) + [Link](float).eps
image_encrypted = image_input / key
[Link](self.encrypted_img_path, image_encrypted * 255)
img_enc = [Link](self.encrypted_img_path)
img_enc.thumbnail((400, 400))
img_enc_display = [Link](img_enc)
self.image_label.configure(image=img_enc_display)
self.image_label.image = img_enc_display
self.image_label['text'] = 'Encrypted Image:'
[Link]("Status", "Image Encrypted successfully!")
def display_encrypted_image(self):
if [Link](self.encrypted_img_path):
img_enc = [Link](self.encrypted_img_path)
img_enc.thumbnail((400, 400))
img_enc_display = [Link](img_enc)
self.image_label.configure(image=img_enc_display)
self.image_label.image = img_enc_display
self.image_label['text'] = 'Encrypted Image:'
else:
[Link]("Error", "No encrypted image found!")
def de_fun(self):
if self.original_image is not None:
img_dec_display = [Link](self.original_image)
self.image_label.configure(image=img_dec_display)
self.image_label.image = img_dec_display
self.image_label['text'] = 'Decrypted Image:'
[Link]("Status", "Image Decrypted successfully!")
else:
[Link]("Error", "No original image available!")
def exit_to_login(self):
self.init_login_screen()
if __name__ == "__main__":
root = [Link]()
app = ImageEncryptorApp(root)
[Link]()
OUTPUTS: