第0关
http://www.pythonchallenge.com/pc/def/0.html
>>>print 2 ** 38 274877906944L
替换网址为http://www.pythonchallenge.com/pc/def/274877906944.html
第1关
http://www.pythonchallenge.com/pc/def/map.html
是个密码,字母往后移动两位,yz 变为 ab
#!/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,
过关密码:
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 .
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
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 .
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:
-->
<!--
%%[email protected]_$^__#)^)&!_+]!*@&^}@[@%]()%+$&[([email protected]%+%$*^@$^!+]!&_#)_*}{}}!}_]$[%}@[{[email protected]#_^{*
@##&{#&{&)*%(]{{([*}@[@&]+
……
-->
#!/usr/bin/env python # coding: utf-8 # author: toddlerya # date: 2015-1-27 # 把那一段注释里的内容 放到rare_char里面 rare_char = """ %%[email protected]_$^__#)^)&!_+]!*@&^}@[@%]()% 省略n行 """ tmp = [] for i in rare_char: if i in tmp: pass else: tmp.append(i) print i, rare_char.count(i)
运行结果如下:
[email protected]:~/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