Progress
This commit is contained in:
parent
d63b8c7736
commit
1b071a46e8
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
55
Teaser/_ZOoxjUSe1OVB7OPoVrsX.pdf.extracted/39A25/dec17.py
Executable file
55
Teaser/_ZOoxjUSe1OVB7OPoVrsX.pdf.extracted/39A25/dec17.py
Executable file
@ -0,0 +1,55 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
from PIL import Image
|
||||||
|
from qrtools import QR
|
||||||
|
import itertools
|
||||||
|
|
||||||
|
img = Image.open('QR3C.png')
|
||||||
|
pixels_orig = img.load()
|
||||||
|
(w,h)=img.size
|
||||||
|
|
||||||
|
outimg = Image.new( 'RGB', (23,23), "white")
|
||||||
|
pixels_out = outimg.load()
|
||||||
|
|
||||||
|
for i in range(0,h,6):
|
||||||
|
for j in range(0,w,6):
|
||||||
|
(r,g,b) = pixels_orig[j,i]
|
||||||
|
if((r,g,b)==(255,255,255)):
|
||||||
|
pixels_out[j/13,i/13]=(255,255,255)
|
||||||
|
|
||||||
|
elif((r,g,b)==(0,0,0) or r>0 ):
|
||||||
|
pixels_out[j/13,i/13]=(0,0,0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# bruteforce missing section until readable
|
||||||
|
count=0
|
||||||
|
for i in itertools.product('01', repeat=60):
|
||||||
|
count+=1
|
||||||
|
if count%1000 ==0:
|
||||||
|
print count
|
||||||
|
|
||||||
|
for x in range(1,12):
|
||||||
|
for y in range (10,14):
|
||||||
|
if( i[((y-10)%4)*11 + x] == '0' ):
|
||||||
|
pixels_out[x,y]=(0,0,0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
outimg=outimg.resize((300,300))
|
||||||
|
outimg.save("dec17_out.png","png")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# read qr code
|
||||||
|
nugget=''
|
||||||
|
|
||||||
|
myCode = QR(filename="dec17_out.png")
|
||||||
|
if myCode.decode():
|
||||||
|
nugget=myCode.data_to_string()
|
||||||
|
print nugget
|
||||||
|
break
|
||||||
|
#else:
|
||||||
|
# print "could not decode"
|
||||||
|
#break
|
91
Teaser/_ZOoxjUSe1OVB7OPoVrsX.pdf.extracted/39A25/decode_qr.py
Executable file
91
Teaser/_ZOoxjUSe1OVB7OPoVrsX.pdf.extracted/39A25/decode_qr.py
Executable file
@ -0,0 +1,91 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
def invert(value):
|
||||||
|
return ''.join(["1" if x == "0" else "0" for x in value])
|
||||||
|
|
||||||
|
|
||||||
|
# Load Image
|
||||||
|
im = Image.open('QR3C_cropped.png')
|
||||||
|
# im.crop((33, 34, 264, 265)).save("QR3C_cropped.png")
|
||||||
|
|
||||||
|
|
||||||
|
pix = im.load()
|
||||||
|
|
||||||
|
tiles = 21
|
||||||
|
tileSize = im.size[0] // tiles
|
||||||
|
version = (tiles - 17) // 4
|
||||||
|
|
||||||
|
data = [[0 for x in range(tiles)] for y in range(tiles)]
|
||||||
|
print("tiles=%d tileSize=%d version=%d" % (tiles, tileSize, version))
|
||||||
|
for x in range(tiles):
|
||||||
|
for y in range(tiles):
|
||||||
|
x_mid = x * tileSize + 0.5 * tileSize
|
||||||
|
y_mid = y * tileSize + 0.5 * tileSize
|
||||||
|
color = pix[x_mid, y_mid]
|
||||||
|
# print(x, y, x_mid, y_mid, color)
|
||||||
|
data[x][y] = invert("%d%d%d" % ( color[0] // 255, color[1] // 255, color[2] // 255 ))
|
||||||
|
|
||||||
|
# print(data)
|
||||||
|
|
||||||
|
def blackWhiteValue(string):
|
||||||
|
new_value = ""
|
||||||
|
if len(string) % 3 != 0:
|
||||||
|
print("Cannot return black white value of", string)
|
||||||
|
return new_value
|
||||||
|
|
||||||
|
for i in range(len(string) // 3):
|
||||||
|
new_value += string[i * 3]
|
||||||
|
|
||||||
|
return new_value
|
||||||
|
|
||||||
|
mask1 = [data[8][18], data[8][17], data[8][16]]
|
||||||
|
mask2 = [data[2][8], data[3][8], data[4][8]]
|
||||||
|
if mask1 != mask2:
|
||||||
|
print("masks do not match")
|
||||||
|
exit()
|
||||||
|
|
||||||
|
# mask = [mask1[0][0] + mask1[1][0] + mask[2][0],]
|
||||||
|
mask = [''.join(mask1[i][j] for i in range(3)) for j in range(3)]
|
||||||
|
print("Mask:", mask)
|
||||||
|
|
||||||
|
def apply_mask(x, y, bit, mask):
|
||||||
|
doInvert = False
|
||||||
|
if mask == "111":
|
||||||
|
doInvert = x % 3 == 0
|
||||||
|
elif mask == "110":
|
||||||
|
doInvert = (x + y) % 3 == 0
|
||||||
|
elif mask == "101":
|
||||||
|
doInvert = (x + y) % 2 == 0
|
||||||
|
elif mask == "100":
|
||||||
|
doInvert = y % 2 == 0
|
||||||
|
elif mask == "000":
|
||||||
|
doInvert = ((x*y) % 2) + ((x + y) % 3) == 0
|
||||||
|
|
||||||
|
return invert(bit) if doInvert else bit
|
||||||
|
|
||||||
|
def get_masked_value(x, y):
|
||||||
|
return ''.join([apply_mask(x, y, data[x][y][i], mask[i]) for i in range(3)])
|
||||||
|
|
||||||
|
def read_block(x, y, orientation):
|
||||||
|
indizes = []
|
||||||
|
if orientation == "UP":
|
||||||
|
indizes = [[0,0], [-1,0], [0,-1], [-1,-1], [0,-2], [-1,-2], [0, -3], [-1, -3]]
|
||||||
|
elif orientation == "LEFT":
|
||||||
|
indizes = [[0,0], [-1,0], [0,-1], [-1,-1], [-2,-1], [-3,-1], [-2, 0], [-3, 0]]
|
||||||
|
|
||||||
|
return ''.join([get_masked_value(x + offset[0], y + offset[1]) for offset in reversed(indizes)])
|
||||||
|
|
||||||
|
|
||||||
|
encoding = blackWhiteValue(data[20][20] + data[19][20] + data[20][19] + data[19][19])
|
||||||
|
print("Encoding:", encoding)
|
||||||
|
# Alphanumeric? 11 bits per 2 character
|
||||||
|
|
||||||
|
# for y in range(tiles):
|
||||||
|
# print(''.join(data[y]))
|
||||||
|
|
||||||
|
block1 = read_block(20, 14, "UP")
|
||||||
|
block2 = read_block(20, 10, "LEFT")
|
||||||
|
print(block1, len(block1))
|
||||||
|
print(block2, len(block2))
|
Loading…
Reference in New Issue
Block a user