= qrgarden = == 問題 == Read a lot, and the flag begins with "ADCTF_". [[http://adctf2014.katsudon.org/dat/jowoVadKQnmSGupH/qrgarden.png|qrgarden.png]] == 解法 == 10000個のQRコードからADCTF_で始まっている物を探しだす問題。 {{{#!highlight python import Image import sys from qr import * def scan(img, top, left, msize, version): w = h = version * 4 + 17 qr = [] for y in range(h): line = [] for x in range(w): c = img.getpixel((top + msize * x, left + msize * y)) if c == (0, 0, 0): x = 1 elif c == (255, 255, 255): x = 0 else: x = None line.append(x) qr.append(line) return qr version = 3 qrcode_size = version * 4 + 17 module_size = 3 img = Image.open("qrgarden.png") img = img.convert('RGB') for y in range(0, 100): for x in range(100): qrtxt = scan(img, 29*module_size*x, 29*module_size*y, module_size, version) print read_qr(qrtxt) }}} {{{ % python scanqr.py| grep ADCTF_ ADCTF_re4d1n9_Qrc0de_15_FuN }}} 動作が遅い遅いと思っていたら無駄なファイルIOが時間を食っていた…… {{{ % time python scanqr.py | grep ADCTF_ ADCTF_re4d1n9_Qrc0de_15_FuN python scanqr.py 22.84s user 0.11s system 99% cpu 22.978 total grep ADCTF_ 0.00s user 0.00s system 0% cpu 22.978 total % workon pypy % time python scanqr.py| grep ADCTF_ ADCTF_re4d1n9_Qrc0de_15_FuN python scanqr.py 9.83s user 0.11s system 99% cpu 9.959 total grep ADCTF_ 0.00s user 0.00s system 0% cpu 9.959 total (pypy) }}}