Advertisement
khbr

hideMessage_graphicstego3.py

Nov 19th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. from PIL import Image
  2. import sys
  3. import os
  4.  
  5. def hide(im, message):
  6.     new_im = Image.new('RGB', im.size)
  7.     idx = 0
  8.     for x in range(im.width):
  9.         for y in range(im.height):
  10.             r, g, b = im.getpixel((x, y))
  11.             if idx < len(message):
  12.                 b = ord(message[idx])
  13.             new_im.putpixel((x, y), (r, g, b))
  14.             idx += 1
  15.     return new_im
  16.        
  17. def main():
  18.     if len(sys.argv) != 4:
  19.         print 'Usage: python %s <input-file> <message> <output-file>' % sys.argv[0]
  20.         exit(1)
  21.        
  22.     input_file   = sys.argv[1]
  23.     message      = sys.argv[2]
  24.     output_file  = sys.argv[3]
  25.        
  26.     if not os.path.exists(input_file):
  27.         print 'File "%s" does not exist' % input_file
  28.         exit(1)
  29.        
  30.     im = Image.open(input_file)
  31.     new_im = hide(im, message)
  32.     new_im.save(output_file)
  33.  
  34.  
  35. if __name__ == '__main__':
  36.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement