ログイン
編集不可のページディスカッション情報添付ファイル
ytoku/CTF/Writeup/AdventCalendarCTF2014/2014-12-09

MMA

qrgarden

問題

Read a lot, and the flag begins with "ADCTF_".

qrgarden.png

解法

10000個のQRコードからADCTF_で始まっている物を探しだす問題。

   1 import Image
   2 import sys
   3 from qr import *
   4 
   5 def scan(img, top, left, msize, version):
   6     w = h = version * 4 + 17
   7     qr = []
   8     for y in range(h):
   9         line = []
  10         for x in range(w):
  11             c = img.getpixel((top + msize * x, left + msize * y))
  12             if c == (0, 0, 0):
  13                 x = 1
  14             elif c == (255, 255, 255):
  15                 x = 0
  16             else:
  17                 x = None
  18             line.append(x)
  19         qr.append(line)
  20     return qr
  21 
  22 version = 3
  23 qrcode_size = version * 4 + 17
  24 module_size = 3
  25 
  26 img = Image.open("qrgarden.png")
  27 img = img.convert('RGB')
  28 for y in range(0, 100):
  29     for x in range(100):
  30         qrtxt = scan(img, 29*module_size*x, 29*module_size*y, module_size, version)
  31         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)

ytoku/CTF/Writeup/AdventCalendarCTF2014/2014-12-09 (最終更新日時 2014-12-23 23:42:13 更新者 ytoku)