-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel_01.py
45 lines (33 loc) · 1.04 KB
/
level_01.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/env python
# coding=utf-8
# http://www.pythonchallenge.com/pc/def/274877906944.html
# Decrypt a string.
import re
import requests
PREFIX = "http://www.pythonchallenge.com/pc/def/"
url = PREFIX + 'map.html'
def catch(text, pattern=r'<!--(.*?)-->', cnt=0):
return re.findall(pattern, text, re.DOTALL)[cnt]
def decrypter(str):
"""Trim the string and move each alphabetic character by 2."""
def move2(c):
if re.match(r'[a-z]', c):
return chr(ord('a') + (ord(c) - ord('a') + 2) % 26)
else:
return c
return "".join(map(move2, str.strip()))
def solve(something):
print('Decrypt the hint:')
print(decrypter(something))
print('Decrypt the url:')
result = decrypter('map')
print('map -> ' + result)
print()
return result
if __name__ == "__main__":
r = requests.get(url)
something = catch(r.text, r'<font color="#f000f0">(.*?)<')
answer = solve(something)
# ocr
print(PREFIX + answer + '.html')
# http://www.pythonchallenge.com/pc/def/ocr.html