2012年1月19日星期四

pythonchallenge 通关秘籍 Level 2

url: http://www.pythonchallenge.com/pc/def/map.html
题目图片上写着:
K ---> M
O ---> Q
E ----> G
实际上是对每一个字母的ascii编码 + 2
In [6]: str_list=['K','M','O','Q','E','G']

In [7]: for x in str_list:
   ...:     print 'ascii code:',ord(x),'chr:',x
   ...:    
   ...:    
ascii code: 75 chr: K
ascii code: 77 chr: M
ascii code: 79 chr: O
ascii code: 81 chr: Q
ascii code: 69 chr: E
ascii code: 71 chr: G

代码:
import string
str = "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."
table=string.maketrans('abcdefghijklmnopqrstuvwxyz','cdefghijklmnopqrstuvwxyzab')
print str.translate(table)
执行结果:
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.

map转换为ocr
然后进入第二关:http://www.pythonchallenge.com/pc/def/ocr.html




没有评论:

发表评论