Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, sys
- import Image
- import binascii
- import optparse
- #hide
- def hide(image, message):
- msg = Image.open(message)
- msg = msg.convert("RGBA")
- data = msg.getdata()
- img = Image.open(image)
- img = img.convert("RGB")
- data2 = img.getdata()
- newData = []
- index = 0
- for item in data:
- if item[0] == 0:
- if (data2[index][0])%2 == 0:
- newData.append((data2[index][0] + 1, data2[index][1], data2[index][2]))
- else:
- newData.append((data2[index][0],data2[index][1], data2[index][2]))
- index = index + 1
- else:
- if (data2[index][0])%2 == 1:
- newData.append((data2[index][0] - 1,data2[index][1], data2[index][2]))
- else:
- newData.append((data2[index][0],data2[index][1], data2[index][2]))
- index = index + 1
- img.putdata(newData)
- img.save("new_"+image, "PNG")
- return "Completed!"
- #extract
- def extract(image):
- img = Image.open(image)
- img = img.convert("RGB")
- data = img.getdata()
- orgData = []
- for item in data:
- if item[0]%2 == 0:
- orgData.append((255,255,255))
- else:
- orgData.append((0,0,0))
- img.putdata(orgData)
- img.save("msg_"+image, "PNG")
- return "Completed!"
- def Main():
- parser = optparse.OptionParser('usage %prog '+\
- '-H/-E <target file>')
- parser.add_option('-H', dest='hide', type='string', \
- help='target picture path to hide another image')
- parser.add_option('-E', dest='extract', type='string', \
- help='target picture path to extract the secret image')
- (options, args) = parser.parse_args()
- if (options.hide != None):
- mesg = raw_input("Enter a message to hide: ")
- print hide(options.hide, mesg)
- elif (options.extract != None):
- print extract(options.extract)
- else:
- print parser.usage
- exit(0)
- if __name__ == '__main__':
- Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement