Created
July 12, 2016 07:18
-
-
Save CreateRemoteThread/1ab75e6475c1c89f9df415277c25d292 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from PIL import Image | |
import sys | |
from re import sub | |
import base64 | |
if len(sys.argv) != 3: | |
print "usage: ./e.py [in_img] [in_data] saves to out.png" | |
sys.exit(0) | |
f = open(sys.argv[2]) | |
d_clear = f.read().rstrip() | |
f.close() | |
def encode(text): | |
return sub(r'(.)\1*', lambda m: str(len(m.group(0))) + m.group(1),text) | |
print " eat my balls -> %s " % encode("eat my balls") | |
print " aaaaabbbbb -> %s" % encode("aaaaabbbbb") | |
sys.exit(0) | |
d = encode(d_clear) | |
o = "" | |
for c in d: | |
o += bin(ord(c))[2:].rjust(8,'0') | |
o_a = [o[n:n+2] for n in range(0,len(o),2)] | |
in_img = Image.open(sys.argv[1]) | |
in_pixels = in_img.convert("RGB") | |
in_l = in_img.load() | |
width, height = in_img.size | |
if len(o_a) > width * height: | |
print "error: not enough canvas to paint with" | |
sys.exit(0) | |
for i in range(0,len(o_a)): | |
temp_x = i % width | |
temp_y = i / width | |
(r,g,b) = in_pixels.getpixel((temp_x,temp_y)) | |
new_r = int(bin(r)[2:8] + o_a[i],2) | |
in_l[temp_x,temp_y] = (new_r,g,b) | |
print "finish: wrote %d times" % len(o_a) | |
in_img.save("out.png") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment