data =open('data.txt').read().strip().split()binary =''.join(bin(int(num))[2:].zfill(29) for num in data)
Now, we can use PIL (the Python Imaging Library) to create an image from the binary data. I made a new image and then looped through the binary data, setting each pixel to black or white based on the value of the binary digit.
index =0for x inrange(size):for y inrange(size):if index <len(binary): pixels[x, y]=int(binary[index]) index +=1
large = img.resize((10* size, 10* size))large.show()
This generates an image that gives us the flag when we scan it.
Full Solution
solve.py
from PIL import Imagedata =open('data.txt').read().strip().split()binary =''.join(bin(int(num))[2:].zfill(29) for num in data)size =int(len(binary) **0.5)img = Image.new('1', (size, size))pixels = img.load()index =0for x inrange(size):for y inrange(size):if index <len(binary): pixels[x, y]=int(binary[index]) index +=1large = img.resize((10* size, 10* size))large.show()
Last updated
Based on the challenge title, I knew I wanted to use the data to visualize a QR code, where 1 is black and 0 is white. There were some initial issues with this approach:
We can fix this by converting the data to binary and then padding the lines until they are all the same length. It turns out the longest line is 29 binary digits long so we can pad to this length.
To ensure my phone could scan the image, I resized it to be 10 times the original size.