第0關php
http://www.pythonchallenge.com/pc/def/0.html html
>>>print 2 ** 38 274877906944L
替換網址爲http://www.pythonchallenge.com/pc/def/274877906944.htmlpython
第1關網絡
http://www.pythonchallenge.com/pc/def/map.html app
是個密碼,字母日後移動兩位,yz 變爲 abide
#!/usr/bin/env python # coding: utf-8 # author: toddlerya # date: 2015-1-27 alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] goal = """g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.""" alpha_dict = {'a': 0, 'c': 2, 'b': 1, 'e': 4, 'd': 3, 'g': 6, 'f': 5, 'i': 8, 'h': 7, 'k': 10, 'j': 9, 'm': 12, 'l': 11, 'o': 14, 'n': 13, 'q': 16, 'p': 15, 's': 18, 'r': 17, 'u': 20, 't': 19, 'w': 22, 'v': 21, 'y': 24, 'x': 23, 'z': 25} result_dict = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6: 'g', 7: 'h', 8: 'i', 9: 'j', 10: 'k', 11: 'l', 12: 'm', 13: 'n', 14: 'o', 15: 'p', 16: 'q', 17: 'r', 18: 's', 19: 't', 20: 'u', 21: 'v', 22: 'w', 23: 'x', 24: 'y', 25: 'z'} #alpha_dict = dict([ (alpha[i], i) for i in range(0,26)] ) #result_dict = dict([ (i, alpha[i]) for i in range(0,26)] ) result_order = [] result = [] for a in goal: if a in alpha: i = alpha_dict[a] if i < 24: j = i + 2 result_order.append(j) elif 24 == i: j = 0 result_order.append(j) elif 25 == i: j = 1 result_order.append(j) #print result_order for r in result_order: x = result_dict[r] result.append(x) #print result num = 0 for a in goal: if a in alpha_dict: print result[num], num += 1 else: print a,
過關密碼:this
i h o p e y o u d i d n t t r a n s l a t e i t b y h a n d . url
t h a t s w h a t c o m p u t e r s a r e f o r . d o i n g i t i n b y h a n d spa
i s i n e f f i c i e n t a n d t h a t ' s w h y t h i s t e x t i s s o l o n g . code
u s i n g s t r i n g . m a k e t r a n s ( ) i s r e c o m m e n d e d . n o w a p p l y o n t h e u r l .
按照提示改了下,好簡潔。。。本身造輪子寫的真醜。。。
#!/usr/bin/env python # coding: utf-8 # author: toddlerya # date: 2015-1-27 from string import maketrans in_string = "abcdefghijklmnopqrstuvwxyz" out_string = "cdefghijklmnopqrstuvwxyzab" goal = """g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.""" trans_string = maketrans(in_string, out_string) print goal.translate(trans_string)
此次輸出的好看多了:
i hope you didnt translate it by hand.
thats what computers are for. doing it in by hand
is inefficient and that's why this text is so long.
using string.maketrans() is recommended. now apply on the url.
第2關
http://www.pythonchallenge.com/pc/def/ocr.html
從提示可知道,查看源代碼,找到一段註釋
<!--
find rare characters in the mess below:
-->
<!--
%%$@_$^__#)^)&!_+]!*@&^}@[@%]()%+$&[(_@%+%$*^@$^!+]!&_#)_*}{}}!}_]$[%}@[{_@#_^{*
@##&{#&{&)*%(]{{([*}@[@&]+
……
-->
#!/usr/bin/env python # coding: utf-8 # author: toddlerya # date: 2015-1-27 # 把那一段註釋裏的內容 放到rare_char裏面 rare_char = """ %%$@_$^__#)^)&!_+]!*@&^}@[@%]()% 省略n行 """ tmp = [] for i in rare_char: if i in tmp: pass else: tmp.append(i) print i, rare_char.count(i)
運行結果以下:
toddler@HP:~/Desktop$ python 3.py 1220 % 6104 $ 6046 @ 6157 _ 6112 ^ 6030 # 6115 ) 6186 & 6043 ! 6079 + 6066 ] 6152 * 6034 } 6105 [ 6108 ( 6154 { 6046 e 1 q 1 u 1 a 1 l 1 i 1 t 1 y 1
能夠看到最少字符是equality。這就是過關密碼啦。改下url,下一關
第3關
http://www.pythonchallenge.com/pc/def/equality.html
目標要求的格式爲xXXXxXXXx 正則搞定
那段待處理的文字放在src裏
#!/usr/bin/env python # coding: utf-8 # author: toddlerya # date: 2015-1-28 import re src = """ kAewtloYgcFQaJNhHVGxXDiQmz …… """ goal = re.findall("[a-z]{1}[A-Z]{3}[a-z]{1}[A-Z]{3}[a-z]{1}", src) i = 0 for g in goal: print goal[i][4], i += 1
過關密碼:
>>> l i n k e d l i s t
替換equality爲linkedlist
顯示linkedlist.php
替換網址爲linkedlist.php
進入第四關
第4關
http://www.pythonchallenge.com/pc/def/linkedlist.php
點擊圖片跳轉到新的頁面,提示 :and the next nothing is 44827
看下網址:http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345
改下好了:http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=44827
……
改了兩次發現這個應該用Python獲取網絡鏈接,而後改url訪問下一次直到成功。。。
蠢哭了。。。
上Python
#!/usr/bin/env python # coding: utf-8 # author: toddlerya # date: 2015-1-28 import urllib2, re nothing = "12345" url_nothing = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=" url = url_nothing + nothing count = 1 while nothing: try: response = urllib2.urlopen(url, timeout=60) html = response.read() tmp = re.findall("[0-9]+", html) nothing = ''.join(tmp) url = url_nothing + nothing print count, "\n", url count += 1 except: print html
這個網絡也是醉了。。。等了很久。。。
最後結果
85 http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=16044 86 http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=
訪問:http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=16044
提示信息:Yes. Divide by two and keep going.
改下代碼nothing="8022",繼續跑!!!喪心病狂啊
http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=66831
拿到密碼:peak.html
第5關: