PythonChallenge-2-2017/7/14

由第一关解得第二关入口:http://www.pythonchallenge.com/pc/def/map.html,页面如下:

 

意思很明显,用本子上的规律解读紫色的字符串。可知规律:所有字母向后移动两位。

#加密字符串
s ='''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.'''
#初始化解密字符串(容器)
m = ''
#偏移量
p = 2
#循环处理字符串中的每个字符
for i in s:
    #对非字母的字符不加处理
    if i not in [' ','(',')','\'','.']:
        #正常偏移范围内的处理
        if ord(i)<=ord('z')-p:
            m = m + chr(ord(i)+p)
        #当偏移出字母的范围时,要从头开始
        else:
            m = m + chr(ord(i)-ord('z') + p + ord('a') - 1)
    else:
        m = m + i
print(m)

之前把偏移2直接代入计算,而且 if ord(i)<=ord(‘z’)- p  之前写的是 if ord(i)<ord(‘y’),    想想有点不太好,如果换了偏移量,就要改许多地方,所以程序还是“抽象”点吧,意味着“不太好看”。

运算结果:“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

                                                    2017.7.14

 

posted @ 2017-07-14 12:39  羽化凡  阅读(68)  评论(0编辑  收藏  举报