-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogistic.py
53 lines (37 loc) · 1.3 KB
/
Logistic.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
import LogisticKey as key
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as img
from PIL import Image
def logisticen(path,x,y):
image = img.imread(path)
height = image.shape[0]
width = image.shape[1]
generatedKey = key.logistic_key(x, y, height*width)
z = 0
encryptedImage = np.zeros(shape=[height, width, 3], dtype=np.uint8)
for i in range(height):
for j in range(width):
encryptedImage[i, j] = image[i, j].astype(int) ^ generatedKey[z]
z += 1
enimg = Image.fromarray(encryptedImage)
enimg.save("encryptedImage.jpg")
def logisticde(path,x,y):
z = 0
encryptedImage = img.imread(path)
height = encryptedImage.shape[0]
width = encryptedImage.shape[1]
generatedKey = key.logistic_key(x, y, height*width)
decryptedImage = np.zeros(shape=[height, width, 3], dtype=np.uint8)
# print(height,width)
for i in range(height):
for j in range(width):
decryptedImage[i, j] = encryptedImage[i, j].astype(int) ^ generatedKey[z]
# print(i,j)
z += 1
deimg = Image.fromarray(decryptedImage)
deimg.save("decryptedImage.jpg")
# orimg= "Original.jpg"
# logisticen(orimg,0.5,3.95)
# enimg="encryptedImage.jpg"
# logisticde(enimg,0.5,3.95)