machine learning, image

W3Challs Chuck Norris Challenge(half)

qkqhxla1 2015. 7. 23. 17:32

들어가면 

이런 사진이 있고 매번 바뀐다. 수식을 잘 인식해서 답을 빨리 보내면 된다. ^는 pow를 뜻하고, mod는 %를 뜻한다. 


풀었는데 요청을 다시 보내라고 나온다. 인식은 맨날 하는 pytesser로 했으며, ^가 '~로 인식되서 '~가 인식됬으면 제대로 인식된걸로 판별하고, 파이썬의 pow인 **로 바꿨다. 인식한걸 파이썬의 유효한 식으로 변경 후, eval로 실행시켰다.

#-*- coding: cp949 -*-
import pytesser, Image
import urllib2, re, threading

session = 'PHPSESSID=9afc7sagp6hnohjh51hrh6oam1'

def download_photo(filename):
    file_path = "%s%s" % ("C:\\Users\\Ko\\Documents\\Visual Studio 2012\\Projects\\PythonApplication37\\", filename)
    downloaded_image = file(file_path, "wb")
   
    req = urllib2.Request('https://w3challs.com/challs/Prog/Ep4/number.png.php?id=0glenm9ev8pesdcn1rbciqqnt3')
    req.add_header('Cookie',session)
    image_on_web = urllib2.urlopen(req)
    while True:
        buf = image_on_web.read()
        if len(buf) == 0:
            break
        downloaded_image.write(buf)
   
    downloaded_image.close()
    image_on_web.close()
    return file_path

def requests():
    req = urllib2.Request('https://w3challs.com/challs/Prog/Ep4/chuck.php','answer='+str(eval(equation)))
    req.add_header('Cookie',session)
    print urllib2.urlopen(req).read()

while True:
    req = urllib2.Request('https://w3challs.com/challs/Prog/Ep4/chuck.php')
    req.add_header('Cookie',session)
    urllib2.urlopen(req).read()

    download_photo('1.png')
    equation = pytesser.image_to_string(Image.open('1.png')).replace('mod','%').replace(' = ?','').strip()
    print equation,
    if equation.find('\'~') == -1:
        continue
    equation = equation.replace('\'~','**')
    print equation
    
    threads = []
    for i in range(1):
        t = threading.Thread(target=requests,args=())
        threads.append(t)
        t.start()

    for th in threads:
        th.join()

제대로 계산해서 보내면

Well done your answer is correct!Oh no... Chuck is angry because he realized that you are better than him! <br/>

 Hurry up to relaunch this page and "change" your IP to escape him! (you will have to send the answer in POST again)

이렇게 chuck가 화났다고 post로 요청을 다시 보내서 ip주소를 바꾸라는데, 아무리 다시 보내도 동일한 메시지가 뜬다. 요청 보내는부분을 쓰레드를 이용해서 3번 보내봤는데, 3번 보내도 저 메시지만 뜬다.


프로그래밍적으로 어떻게 더 구현해야 될지 몰라서 여기서 그냥 포기함.