Skip to content

Instantly share code, notes, and snippets.

@hyunsikjeong
Last active September 2, 2019 09:49
Show Gist options
  • Save hyunsikjeong/b278c9956e085fb9847e278713f4bbd0 to your computer and use it in GitHub Desktop.
Save hyunsikjeong/b278c9956e085fb9847e278713f4bbd0 to your computer and use it in GitHub Desktop.
meow write-up (temp)
from PIL import Image
import os
image = Image.new('RGB', (768, 768), color = 'black')
image.save('base_input.png')
os.system('neko meow.n base_input.png base.png')
conv = dict()
# creating a image object
image = Image.new('RGB', (768, 768), color = 'black')
for i in range(768):
image.putpixel( (i, i), (255, 255, 255) )
image.save('input.png')
os.system('neko meow.n input.png output.png')
base_img = Image.open('base.png').convert('RGB')
img = Image.open('output.png').convert('RGB')
for x in range(768):
for y in range(768):
t1 = base_img.getpixel( (x, y) )
t2 = img.getpixel( (x, y) )
if t1 != t2:
print(x, y)
conv[x] = y
print(conv)
with open('dict', 'w') as f:
f.write(str(conv))
from PIL import Image
with open('dict', 'r') as f:
dic = eval(f.read())
base_img = Image.open('base.png').convert('RGB')
img = Image.open('flag_enc.png').convert('RGB')
orig = Image.new('RGB', (768, 768), color = 'black')
for i in range(768):
for j in range(768):
base_color = base_img.getpixel((i, j))
img_color = img.getpixel((i, j))
color = [0, 0, 0]
for k in range(3):
color[k] = abs(base_color[k] - img_color[k])
orig.putpixel( (dic[i], j), tuple(color))
orig.save('wow.png')

The given binary only accepts the png file with size 768x768.

You can guess this by checking the size of the given converted image.

Let's make an image filled with (0, 0, 0) (black).

If you convert the image, it will give you a image with strange tiles.

Then, draw a one-pixel vertical white line on the image.

If you convert the image, you can see the line in the converted image slightly.

Also, the line is shifted to another column.

To check this column-shifting logic,

I made an image filled with (0, 0, 0) and put (255, 255, 255) on every (i, i)th pixel, and converted it.

This is solver_part1.py

To check how colors are converted, convert the image filled with (0, 0, 0).

Let's say the converted one as the base image.

Next, draw a one-pixel vertical line with color (128, 64, 32) on the image filled with black.

Convert this image and compare the color of each pixel with the same position, between the converted one and the base image.

You can find out that if the color of the pixel is (a, b, c) in the base image,

then the color of the pixel in the converted image is (a±128, b±64, c±32).

So we can know the binary adds or substracts the rgb value.

This is solver_part2.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment