-
Notifications
You must be signed in to change notification settings - Fork 0
/
stackCode.py
74 lines (58 loc) · 2.28 KB
/
stackCode.py
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
import pyDes #import library pyDes
import base64 #import library base64
import sys
import io
from tkinter import * #import library tkinter for GUI
from tkinter import filedialog
from pyDes import *
root = Tk()
root.geometry("400x400")
root.title("Image Encryption")
ivInt = bytearray("AStringOfIV=", "utf-8") #key1
keyInt = bytearray("aKeyOfSomeKindThat+IWillNotShare", "utf-8") #key2
lst = []
string1 = StringVar()
string2 = StringVar()
def select_image():
imgToEncrypt = filedialog.askopenfile(mode='r', filetypes=[('jpg file', '*.jpg'), ('png file', '*.png')]) #reading image
b = Button(root, text="Select Image", command=select_image)
b.place(x=130, y=60)
def encrypt_image():
with open('image.jpg', 'rb') as f:
jpgdata=f.read()
for f1 in jpgdata:
lst.append(f1)
f.close()
data = jpgdata
k = pyDes.triple_des(base64.b64decode(keyInt), mode=pyDes.CBC, IV=base64.b64decode(ivInt),pad=None, padmode=pyDes.PAD_PKCS5) #encryption
print ("please wait for a moment")
jpgdata = k.encrypt(data)
with open('Encrypted.jpg', 'wb') as f:
f.write(jpgdata)
print("Encryption Complete")
b = Button(root, text="Encrypt", command=encrypt_image)
b.place(x=100, y=210)
def decrypt_image():
with open('Encrypted.jpg', 'rb') as f:
jpgdata=f.read()
for f1 in jpgdata:
lst.append(f1)
f.close()
data = jpgdata
k = pyDes.triple_des(base64.b64decode(keyInt), mode=pyDes.CBC, IV=base64.b64decode(ivInt), padmode=pyDes.PAD_PKCS5) #decryption
print ("please wait for a moment")
jpgdata = k.decrypt(data)
with open('Decrypted.jpg', 'wb') as f:
f.write(jpgdata)
print("Decryption Complete")
b = Button(root, text="Decrypt", command=decrypt_image)
b.place(x=210, y=210)
entry1 = Entry(root, textvariable=string1, width=24)
entry1.place(x=95, y=120)
label1 = Label(root, text="Key 1:").place(x=40, y=120)
label1Result = Label(root)
entry2 = Entry(root, textvariable=string2, width=24)
entry2.place(x=95, y=160)
label2 = Label(root, text="Key 2:").place(x=40, y=160)
label2Result = Label(root)
root.mainloop()