Advertisement
Guest User

Steamgifts Steganography Extract.Py

a guest
Jul 24th, 2019
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. from PIL import Image, ImageFilter
  2.  
  3. def get_num_bits_secret():
  4.     return 1
  5.  
  6. # im is the image you get when you combine the host image and the hidden image. (In this case, this was the image posted in the steamgifts thread).
  7. im = Image.open( 'combined.png' )
  8. num_bits_secret = get_num_bits_secret()
  9.  
  10. def extract(im):
  11.  
  12.     width, height = im.size
  13.     # iterate through the pixels
  14.     for i in range(width):
  15.         for j in range(height):
  16.             pixel = list( im.getpixel((i,j)) )
  17.  
  18.             # for each color component
  19.             for c in range(3):
  20.                 val = pixel[c]
  21.  
  22.                 # "%" is the modulus operator. x % y gives you the remainder of dividing x by y.
  23.                 # "<<" and ">>" are bit shifting operators. They make a number lose binary digits at the right side, or add zeros at the right side.
  24.                 # e.g.: x >> 2, makes x lose two bits from the end (it's like dividing by 2^2 and taking only the quotient)
  25.                 # e.g.: x << 2, adds two 0 bits to the right of x (it's like multiplying by 2^2)
  26.  
  27.                 # get the last num_bits_secret bits in that number
  28.                 val = (val % (1 << num_bits_secret))
  29.                 # move the number back to the left by placing zeros at the end.
  30.                 val = (val << (8 - num_bits_secret))
  31.  
  32.                 pixel[c] = val
  33.  
  34.             # place the modified pixel back in the image.
  35.             im.putpixel((i,j), tuple(pixel))
  36.  
  37.     return im
  38.  
  39. ex = extract(im)
  40. ex.save('extracted.png')
  41. ex.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement