-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSteganography.py
66 lines (41 loc) · 2.01 KB
/
Steganography.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
import numpy as np
from PIL import Image
#to perform image steganography using LSB method
class Steganography:
def steganography():
#open the cover image
img1 = Image.open("image1.jpg")
#convert cover image to greyscale image
grey_image1 = np.array(img1.convert('L'))
#open the secret image
img2 = Image.open("image2.jpg")
#convert secret image to greyscale image
grey_image2 = np.array(img2.convert('L'))
#array to store final image after embedding
new = np.zeros(grey_image2.size)
new.shape = (256,256)
#to mask the 4 lsb digits to store the values of secret image
for i in range (256):
for j in range (256):
grey_image1[i][j] = grey_image1[i][j] & 240
#to mask the 4 msb digits of secret image at the end by shifting them right
for i in range (256):
for j in range (256):
if len(np.binary_repr(grey_image2[i][j])) == 7: #there are 7 bit and 8 bit numbers which are handled seperately
grey_image2[i][j] = grey_image2[i][j] >> 3
elif len(np.binary_repr(grey_image2[i][j])) == 8:
grey_image2[i][j] = grey_image2[i][j] >> 4
#merging msb of secret image as lsb of cover image
for i in range (256):
for j in range (256):
new[i][j] = grey_image1[i][j] + grey_image2[i][j]
new = new.astype(int)
return new
def reverse():
final = Steganography.steganography()
#to convert int array from cover image to binary
for i in range (256):
for j in range (256):
final[i][j] = final[i][j] & 15
final[i][j] = final[i][j] << 4
return final