Python/2.7 simple coding(+ c++)

hack this site Programming missions : Reverse Ascii Shift

qkqhxla1 2015. 1. 20. 17:00

Generated String: 60/59/56/67/24/38/48/45/39/


Shift: -11


와 같은 형식으로 랜덤으로 string이 매번 생성되는데, 구분자가 매번 달라진다. 예시로는 /를 썼지만 $가 나올수도있고, "이나 .도 나오는걸 봐서 구분자도 랜덤이다. Shift한 string이 위의 만들어진 string이므로 Shift값을 뺀 연산의 결과값을 출력하면 된다.



# -*- encoding: cp949 -*-
import urllib2,re
req = urllib2.Request('https://www.hackthissite.org/missions/prog/11/index.php')
req.add_header('cookie','PHPSESSID=쿠키')
req.add_header('referer','https://www.hackthissite.org/missions/prog/11/')
page = urllib2.urlopen(req).read()
#print page.split('algorithm.')[1][:500]
num = re.findall("String:\s+(.*?)<br />",page)[0] #숫자 부분 전체 다 가져옴.
shift = int(re.findall('Shift:\s+(.*?)<br />',page)[0]) #shift가 몇인지 가져옴 정수로.
s = re.findall('([^\d])',num)[0] #구분자가 뭔지 가져옴. 구분자는 숫자가 아닌걸로 판별.
answer = urllib2.quote(''.join(map(chr,map(lambda x:x!='' and int(x)-shift,num.split(s)))))[:-3] #연산을 함. 마지막의 :-3을 해주는건 맨 마지막에 인코딩된 널문자 %00이 붙기 때문. 붙는 이유는 모르겠음.
print answer

req = urllib2.Request('https://www.hackthissite.org/missions/prog/11/index.php','solution='+answer)
req.add_header('cookie','PHPSESSID=쿠키')
req.add_header('referer','https://www.hackthissite.org/missions/prog/11/')
print urllib2.urlopen(req).read()