Ross Wan's World!

Python, Ajax, PHP and Linux.

The Python Challenge Lv.1

Posted by Ross Wan 于 2011/08/18

Lv.1

根据图片:

K->M

O->Q

E->G

可以猜到规律,就是将字母右移2位进行影射解密.字符影射翻译,Python str本身就提供了这方法: translate.

import string

mess = “””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. “””

translation = mess.translate(str.maketrans(string.ascii_letters, string.ascii_lowercase[2:]+’ab’+string.ascii_uppercase[2:]+’AB’))

print(translation)

得到以下译文:

“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. “

根据译文的提示,对网页的 url 进行上面的字符影射翻译:

map -> ocr

得到下一关地址:

http://www.pythonchallenge.com/pc/def/ocr.html

Python 字符串提供的 translate 是相当方便的,假如不用这内置的方法,也是有很多办法解决的,毕竟这是有规律的字符影射:

for char in mess:
    print(ord(‘a’)<=ord(char)<=ord(‘z’) and chr((ord(char)+2-ord(‘a’))%26+ord(‘a’)) or char, end=”)

:) 这样这可以打印出上面的译文.

Have fun~~

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

 
%d 博主赞过: