Created
September 1, 2013 06:03
-
-
Save nk0t/6402612 to your computer and use it in GitHub Desktop.
ASIS CTF PPC/Code&Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import socket | |
import Image | |
from qrtools import QR | |
def solve(qrcode): | |
make_qrcode_image(qrcode) | |
code = QR(filename='qrcode.png') | |
if code.decode(): | |
return code.data | |
return 'null' | |
def make_qrcode_image(qrcode_str): | |
img = Image.new('RGB', (30*2, 30*2), (0xff, 0xff, 0xff)) | |
x = 0 | |
y = 0 | |
for l in qrcode_str.rstrip('\n').split('\n'): | |
for c in l.lstrip(' ').split(' '): | |
if c == '-': | |
for kx in range(2): | |
for ky in range(2): | |
img.putpixel((y*2+ky,x*2+kx), (0x00, 0x00, 0x00)) | |
x += 1 | |
y += 1 | |
x = 0 | |
img.save('qrcode.png') | |
s = socket.socket(socket.AF_INET) | |
s.connect(('asis-ctf.ir', 12435)) | |
print s.recv(1024) | |
print s.recv(1024) | |
s.send('\n') | |
for count in range(0,100): | |
print s.recv(1024) | |
qrcode = s.recv(1024) | |
qrcode += s.recv(1024) | |
qrcode += s.recv(1024) | |
print qrcode | |
ans = solve(qrcode) | |
print ans | |
print count | |
s.send(ans + '\n') | |
print s.recv(1024) # flag | |
s.close() | |
# the flag is: ASIS_ebd814d43f558d1b73d077234f65b71b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment