-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncrypt_code.py
More file actions
29 lines (26 loc) · 734 Bytes
/
Copy pathEncrypt_code.py
File metadata and controls
29 lines (26 loc) · 734 Bytes
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
# ENCRYPTION OF IMAGE
#To encrypt using pixel model flication
x_enc=x.copy()
#Encrypt and Modify pixel values
n=0 #number of rows
m=0 #number of column
z=0 #colour channel
l=len(text)
kl=0
for i in range(l):
orig_val=x_enc[n,m,z]
new_val=d[text[i]]^d[key[kl]]
x_enc[n,m,z]=new_val
print(f"Embedding '{text[i]}' (ASCII {d[text[i]]} XOR '{key[kl]}' (ASCII {d[key[kl]]})={new_val} at pixel ({n}, {m},{z}) [original={orig_val}]")
n= n+1
m= m+1
z= (z+1) % 3
m= (m+1) % 3
kl= (kl+1) % len(key)
#Saving Encrypted Image
cv2.imwrite("encrypted_img.jpg",x_enc)
#Show the Encrypted Image
plt.imshow(cv2.cvtColor(x_enc,cv2.COLOR_BGR2RGB))
plt.title("Encrypted Image")
plt.axis('off')
plt.show()