Advertisement
Guest User

Untitled

a guest
May 24th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. from PIL import Image
  2.  
  3. im = Image.open('out.png').convert('RGB')
  4. # import pdb
  5. # pdb.set_trace()
  6.  
  7. def xor_decrypt(source, key):
  8.     result = []
  9.     for i, x in enumerate(source):
  10.         to_append = x
  11.         for y in key:
  12.             to_append = to_append ^ y
  13.         result.append(to_append)
  14.         print("Round {}".format(i))
  15.     return result
  16.  
  17. def join(bin_list):
  18.     return ''.join(str(x) for x in bin_list)
  19.  
  20.  
  21. def get_bin(im, width, height, start_h=0, start_width=0):
  22.     result = []
  23.     for x in range(start_h, height):
  24.         for y in range(start_width, width):
  25.             # print(y, x)
  26.             r, g, b = im.getpixel((y, x))
  27.             if r > 30:
  28.                 result.append(1)
  29.             else:
  30.                 result.append(0)
  31.     return result
  32.  
  33. left = get_bin(im, 256, 256)
  34. right = get_bin(im, 512, 256, start_width=256)
  35.  
  36. # print(join(xor_decrypt(left, right)))
  37.  
  38. # print(len(left), len(right))
  39.  
  40. xored = join([x ^ y for x, y in zip(left, right)])
  41.  
  42. govno = iter(xored)
  43. out = Image.new("RGB", (256, 256))
  44. pix = out.load()
  45. for x in range(256):
  46.     for y in range(256):
  47.         current_pixel = next(govno)
  48.         pix[y, x] = (255,255,255) if current_pixel is '1' else (0, 0, 0)
  49.  
  50. out.save("decrypted.png", "PNG")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement