Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- im = Image.open('out.png').convert('RGB')
- # import pdb
- # pdb.set_trace()
- def xor_decrypt(source, key):
- result = []
- for i, x in enumerate(source):
- to_append = x
- for y in key:
- to_append = to_append ^ y
- result.append(to_append)
- print("Round {}".format(i))
- return result
- def join(bin_list):
- return ''.join(str(x) for x in bin_list)
- def get_bin(im, width, height, start_h=0, start_width=0):
- result = []
- for x in range(start_h, height):
- for y in range(start_width, width):
- # print(y, x)
- r, g, b = im.getpixel((y, x))
- if r > 30:
- result.append(1)
- else:
- result.append(0)
- return result
- left = get_bin(im, 256, 256)
- right = get_bin(im, 512, 256, start_width=256)
- # print(join(xor_decrypt(left, right)))
- # print(len(left), len(right))
- xored = join([x ^ y for x, y in zip(left, right)])
- govno = iter(xored)
- out = Image.new("RGB", (256, 256))
- pix = out.load()
- for x in range(256):
- for y in range(256):
- current_pixel = next(govno)
- pix[y, x] = (255,255,255) if current_pixel is '1' else (0, 0, 0)
- out.save("decrypted.png", "PNG")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement