brainifii

steganography

Dec 22nd, 2022
631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. from PIL import Image
  2. import stepic
  3.  
  4. def encode(image_path, message):
  5.     # Open the image
  6.     im = Image.open(image_path)
  7.  
  8.     # Encode the message using steganography
  9.     im1 = stepic.encode(im, message)
  10.  
  11.     # Save the modified image
  12.     im1.save('modified_image.png', 'PNG')
  13.  
  14. def decode(image_path):
  15.     # Open the image
  16.     image = Image.open(image_path)
  17.  
  18.     # Decode the message using steganography
  19.     message = stepic.decode(image)
  20.  
  21.     return message
  22.  
  23. if __name__ == '__main__':
  24.     # Encode the message
  25.     image_path = "cover.png"
  26.     message = b'Test Message'
  27.     encode(image_path, message)
  28.     print('Message encoded successfully in the image.')
  29.  
  30.     # Decode the message
  31.     image_path = 'modified_image.png'
  32.     message = decode(image_path)
  33.     print('Decoded message:', message)
Advertisement
Add Comment
Please, Sign In to add comment