-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgray.py
55 lines (41 loc) · 1.32 KB
/
gray.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
# Importing all the necessary libraries
import matplotlib.image as img
import matplotlib.pyplot as plt
import numpy as np
import lorenzKey as key
from PIL import Image
def greyen(path,x,y,z):
image = img.imread(path)
height = image.shape[0]
width = image.shape[1]
keyx = float(x)
keyy = float(y)
keyz = float(z)
x, y, keys = key.lorenz_key(keyx, keyy, keyz, height*width)
l = 0
encrypted = np.zeros(shape=[height, width, 3], dtype=np.uint8)
# print(keys)
for i in range(height):
for j in range(width):
zk = (int((keys[l]*pow(10, 5))%256))
encrypted[i, j] = image[i, j]^zk
l += 1
enimg=Image.fromarray(encrypted)
enimg.save("encrypted.jpg")
def greyde(path,x,y,z):
encrypted = img.imread(path)
height = encrypted.shape[0]
width = encrypted.shape[1]
keyx = float(x)
keyy = float(y)
keyz = float(z)
x, y, keys = key.lorenz_key(keyx, keyy, keyz, height*width)
decrypted = np.zeros(shape=[height, width, 3], dtype=np.uint8)
l = 0
for i in range(height):
for j in range(width):
zk = (int((keys[l]*pow(10, 5))%256))
decrypted[i, j] = encrypted[i, j]^zk
l += 1
deimg=Image.fromarray(decrypted)
deimg.save("decrypted.jpg")