⇤ ← 2014-12-22 02:27:21時点のリビジョン1
サイズ: 1401
コメント:
|
← 2014-12-23 23:42:13時点のリビジョン2 ⇥
サイズ: 1672
コメント:
|
削除された箇所はこのように表示されます。 | 追加された箇所はこのように表示されます。 |
行 9: | 行 9: |
下手に自作のQRコードリーダを持っていたせいで時間がかかってしまった。 作ったQRコード調査ライブラリの問題点(動作の遅さ)を気づかせてくれた問題。 |
|
行 30: | 行 27: |
x = -1 | x = None |
行 36: | 行 33: |
qrcode_size = version * 4 + 17 module_size = 3 |
|
行 41: | 行 40: |
qrtxt = scan(img, 29*3*x, 29*3*y, 3, version) | qrtxt = scan(img, 29*module_size*x, 29*module_size*y, module_size, version) |
行 45: | 行 44: |
% python solve.py | grep ADCTF_ | % python scanqr.py| grep ADCTF_ |
行 49: | 行 48: |
とりあえずyの範囲を分けて並列で実行した。pypyで実行したら早くなるだろうか。 | 動作が遅い遅いと思っていたら無駄なファイル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) }}} |
qrgarden
問題
Read a lot, and the flag begins with "ADCTF_".
解法
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)