-
Notifications
You must be signed in to change notification settings - Fork 0
/
steganography_detection.py
64 lines (43 loc) · 1.28 KB
/
steganography_detection.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
#!usr/bin/env python
import numpy as np
from PIL import Image
from threading import Thread
import sys
def main():
if len(sys.argv)<2:
print("Missing arguments")
sys.exit()
elif len(sys.argv)>2:
print("Too many arguments")
sys.exit()
messageIm=Image.open(sys.argv[1])
secretMessageIm=Image.new('RGB',messageIm.size)
temp1=messageIm.getdata() #####
numThread=4
sectionY=messageIm.size[1]/numThread
threadPool=[]
for i in range(numThread):
if i==0:
startY=1
else:
startY=(sectionY*i)-2
endY=(sectionY*i)+sectionY
if i==(numThread-1) and endY!=messageIm.size[1]:
endY=messageIm.size[1]
thread = Thread(target=findMessage, args=(i,startY,endY,messageIm,secretMessageIm))
thread.start()
threadPool.append(thread)
for t in threadPool:
t.join()
secretMessageIm.save("secretMessage.png")
print("The secret message image is now ready")
def findMessage(threadId,startY,endY,messageIm,secretMessageIm):
for x in range(1,messageIm.size[0]-1):
for y in range(startY,endY-1):
originalMessagePix = messageIm.getpixel((x,y))
if (originalMessagePix[0]%2==0): #black
secretMessageIm.putpixel((x,y),(0,0,0))
else: #white
secretMessageIm.putpixel((x,y),(255,255,255))
if __name__=="__main__":
main()