Skip to content

Commit dd12311

Browse files
authored
Merge pull request #83 from akash435/idebranch
Added image encryption decryption script
2 parents a2e7969 + 0a97a9d commit dd12311

File tree

14 files changed

+239
-0
lines changed

14 files changed

+239
-0
lines changed
92 KB
Loading
181 KB
Loading
206 KB
Loading
138 KB
Loading
265 KB
Loading
162 KB
Loading
168 KB
Loading
213 KB
Loading
356 KB
Loading
198 KB
Loading
208 KB
Loading

Image Encryption Decryption/README.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## ✔ IMAGE ENCRYPTION DECRYPTION
2+
- An Image Encryption Decryption is an image processing application created in python with tkinter gui and OpenCv library.
3+
- In this application user can select an image and can encrypt that image to gray scale image and can even decrpyt also.
4+
- Also after encrypting and decrypting user can also save the edited image anywhere in the local system.
5+
- Also there is option to reset to the original image.
6+
7+
****
8+
9+
### HOW TO Use it :
10+
- User just need to download the file, and run the image_encryption_decryption.py, on local system.
11+
- After running a GUI window appears, where user needs to choose an image file using CHOOSE button on the top right corner.
12+
- After selecting the image, two images will appear on screen one on left side, which is original and one on write in which Encrypted Decrypted format will be shown.
13+
- Now user can start encryption and decryption using Encrypt and Decrypt button.
14+
- After editing user can also save the edited image to any location in local system using SAVE button.
15+
- Also there is a RESET button, clicking on which resets the edited image to original format.
16+
- Also there is exit button, clicking on which we get a exit dialog box asking the permission to exit.
17+
18+
****
19+
20+
### SCREENSHOTS :
21+
22+
<p align="center">
23+
<img width = 1000 src="Images/1.jpg" /><br>
24+
<img width = 1000 src="Images/2.jpg" /><br>
25+
<img width = 1000 src="Images/3.jpg" /><br>
26+
<img width = 1000 src="Images/4.jpg" /><br>
27+
<img width = 1000 src="Images/5.jpg" /><br>
28+
<img width = 1000 src="Images/6.jpg" /><br>
29+
<img width = 1000 src="Images/7.jpg" /><br>
30+
<img width = 1000 src="Images/8.jpg" /><br>
31+
<img width = 1000 src="Images/9.jpg" /><br>
32+
<img width = 1000 src="Images/10.jpg" /><br>
33+
<img width = 1000 src="Images/11.jpg" /><br>
34+
</p>
35+
36+
****
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
2+
# Image Encryption Decryption
3+
4+
# imported necessary library
5+
import tkinter
6+
from tkinter import *
7+
import tkinter as tk
8+
import tkinter.messagebox as mbox
9+
from tkinter import ttk
10+
from tkinter import filedialog
11+
from PIL import ImageTk, Image
12+
import cv2
13+
import os
14+
import numpy as np
15+
from cv2 import *
16+
import random
17+
18+
#created main window
19+
window = Tk()
20+
window.geometry("1000x700")
21+
window.title("Image Encryption Decryption")
22+
23+
# defined variable
24+
global count, emig
25+
# global bright, con
26+
# global frp, tname # list of paths
27+
frp = []
28+
tname = []
29+
con = 1
30+
bright = 0
31+
panelB = None
32+
panelA = None
33+
34+
# function defined to get the path of the image selected
35+
def getpath(path):
36+
a = path.split(r'/')
37+
# print(a)
38+
fname = a[-1]
39+
l = len(fname)
40+
location = path[:-l]
41+
return location
42+
43+
# function defined to get the folder name from which image is selected
44+
def getfoldername(path):
45+
a = path.split(r'/')
46+
# print(a)
47+
name = a[-1]
48+
return name
49+
50+
# function defined to get the file name of image is selected
51+
def getfilename(path):
52+
a = path.split(r'/')
53+
fname = a[-1]
54+
a = fname.split('.')
55+
a = a[0]
56+
return a
57+
58+
# function defined to open the image file
59+
def openfilename():
60+
filename = filedialog.askopenfilename(title='"pen')
61+
return filename
62+
63+
# function defined to open the selected image
64+
def open_img():
65+
global x, panelA, panelB
66+
global count, eimg, location, filename
67+
count = 0
68+
x = openfilename()
69+
img = Image.open(x)
70+
eimg = img
71+
img = ImageTk.PhotoImage(img)
72+
temp = x
73+
location = getpath(temp)
74+
filename = getfilename(temp)
75+
# print(x)
76+
if panelA is None or panelB is None:
77+
panelA = Label(image=img)
78+
panelA.image = img
79+
panelA.pack(side="left", padx=10, pady=10)
80+
panelB = Label(image=img)
81+
panelB.image = img
82+
panelB.pack(side="right", padx=10, pady=10)
83+
else:
84+
panelA.configure(image=img)
85+
panelB.configure(image=img)
86+
panelA.image = img
87+
panelB.image = img
88+
89+
# function defined for make the sketch of image selected
90+
def en_fun():
91+
global x, image_encrypted, key
92+
# print(x)
93+
image_input = imread(x, IMREAD_GRAYSCALE)# 'C:/Users/aakas/Documents/flower.jpg'
94+
(x1, y) = image_input.shape
95+
image_input = image_input.astype(float) / 255.0
96+
# print(image_input)
97+
98+
mu, sigma = 0, 0.1 # mean and standard deviation
99+
key = np.random.normal(mu, sigma, (x1, y)) + np.finfo(float).eps
100+
# print(key)
101+
image_encrypted = image_input / key
102+
imwrite('image_encrypted.jpg', image_encrypted * 255)
103+
104+
imge = Image.open('image_encrypted.jpg')
105+
imge = ImageTk.PhotoImage(imge)
106+
panelB.configure(image=imge)
107+
panelB.image = imge
108+
mbox.showinfo("Encrypt Status", "Image Encryted successfully.")
109+
110+
# function defined to make the image sharp
111+
def de_fun():
112+
global image_encrypted, key
113+
image_output = image_encrypted * key
114+
image_output *= 255.0
115+
imwrite('image_output.jpg', image_output)
116+
117+
imgd = Image.open('image_output.jpg')
118+
imgd = ImageTk.PhotoImage(imgd)
119+
panelB.configure(image=imgd)
120+
panelB.image = imgd
121+
mbox.showinfo("Decrypt Status", "Image decrypted successfully.")
122+
123+
124+
# function defined to reset the edited image to original one
125+
def reset():
126+
# print(x)
127+
image = cv2.imread(x)[:, :, ::-1]
128+
global count, eimg
129+
count = 6
130+
global o6
131+
o6 = image
132+
image = Image.fromarray(o6)
133+
eimg = image
134+
image = ImageTk.PhotoImage(image)
135+
panelB.configure(image=image)
136+
panelB.image = image
137+
mbox.showinfo("Success", "Image reset to original format!")
138+
139+
# function defined to same the edited image
140+
def save_img():
141+
global location, filename, eimg
142+
print(filename)
143+
# eimg.save(location + filename + r"_edit.png")
144+
filename = filedialog.asksaveasfile(mode='w', defaultextension=".jpg")
145+
if not filename:
146+
return
147+
eimg.save(filename)
148+
mbox.showinfo("Success", "Encrypted Image Saved Successfully!")
149+
150+
151+
152+
# top label
153+
start1 = tk.Label(text = "Image Encryption\nDecryption", font=("Arial", 40), fg="magenta") # same way bg
154+
start1.place(x = 350, y = 10)
155+
156+
# original image label
157+
start1 = tk.Label(text = "Original\nImage", font=("Arial", 40), fg="magenta") # same way bg
158+
start1.place(x = 100, y = 270)
159+
160+
# edited image label
161+
start1 = tk.Label(text = "Encrypted\nDecrypted\nImage", font=("Arial", 40), fg="magenta") # same way bg
162+
start1.place(x = 700, y = 230)
163+
164+
# choose button created
165+
chooseb = Button(window, text="Choose",command=open_img,font=("Arial", 20), bg = "orange", fg = "blue", borderwidth=3, relief="raised")
166+
chooseb.place(x =30 , y =20 )
167+
168+
# save button created
169+
saveb = Button(window, text="Save",command=save_img,font=("Arial", 20), bg = "orange", fg = "blue", borderwidth=3, relief="raised")
170+
saveb.place(x =170 , y =20 )
171+
172+
# Encrypt button created
173+
enb = Button(window, text="Encrypt",command=en_fun,font=("Arial", 20), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
174+
enb.place(x =150 , y =620 )
175+
176+
# decrypt button created
177+
deb = Button(window, text="Decrypt",command=de_fun,font=("Arial", 20), bg = "orange", fg = "blue", borderwidth=3, relief="raised")
178+
deb.place(x =450 , y =620 )
179+
180+
# reset button created
181+
resetb = Button(window, text="Reset",command=reset,font=("Arial", 20), bg = "yellow", fg = "blue", borderwidth=3, relief="raised")
182+
resetb.place(x =800 , y =620 )
183+
184+
# function created for exiting
185+
def exit_win():
186+
if mbox.askokcancel("Exit", "Do you want to exit?"):
187+
window.destroy()
188+
189+
# exit button created
190+
exitb = Button(window, text="EXIT",command=exit_win,font=("Arial", 20), bg = "red", fg = "blue", borderwidth=3, relief="raised")
191+
exitb.place(x =880 , y =20 )
192+
193+
194+
window.protocol("WM_DELETE_WINDOW", exit_win)
195+
window.mainloop()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
libraries used : tkinter
2+
from tkinter import filedialog
3+
import tkinter.messagebox
4+
from PIL import ImageTk, Image
5+
os
6+
cv2
7+
numpy
8+
random

0 commit comments

Comments
 (0)