`
he_lux
  • 浏览: 102995 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

python challenge 1

阅读更多
首先解码这段文本:
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.

关于解码方法,没有任何提示,不过还好比较简单,每个字母的ASCII码加2就行了。解码后的文本是:
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再进行一次解码(同样的使用ASCII码加2,图片中的提示:K->M, O->Q, E->G 是没用的),得到ocr,过关。
import string

if __name__ == '__main__':
    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."
    
    #solution 1 Star
    trans = string.maketrans('abcdefghijklmnopqrstuvwxyz', 'cdefghijklmnopqrstuvwxyzab');
    print(s.translate(trans))
    print('map'.translate(trans))
    #solution 1 End
    
    #solution 2 Start
    o = ''
    for x in s:
        if ord(x) >= ord('a') and ord(x) <= ord('z'):
            o += chr(((ord(x) + 2 - ord('a'))) % 26 + ord('a'))
        else:
            o += x
            
    print(o)
    
    print(''.join(chr(ord(x) + 2) for x in 'map'))
    #solution 2 End
    
    #solution 3 Start
    trans = string.maketrans(string.ascii_lowercase, string.ascii_lowercase[2:] + string.ascii_lowercase[0:2]);
    print(s.translate(trans));
    print('map'.translate(trans))
    #solution 3 End
    


让我学习到了translate, ord, chr, string.ascii_lowercase的使用。
0
0
分享到:
评论
4 楼 hellolaojiang 2011-07-20  
你是怎么猜出要加2的?
3 楼 doylecnn 2009-12-31  
很恶趣味的用lambda和list构造写成了一行
2 楼 doylecnn 2009-12-31  
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."

''.join([''.join([(lambda y: (y not in [z for z in s if (z<'a' or z>'z') and not z == ' ']) and chr((ord(y)+2-ord('a')) % 26 + ord('a')) or y)(j) for j in x])+' ' for x in s.split()])

s="map"

''.join([''.join([(lambda y: (y not in [z for z in s if (z<'a' or z>'z') and not z == ' ']) and chr((ord(y)+2-ord('a')) % 26 + ord('a')) or y)(j) for j in x])+' ' for x in s.split()])
1 楼 doylecnn 2009-12-31  
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."
''.join([''.join([(lambda y: (y not in [z for z in s if (z<'a' or z>'z') and not z == ' ']) and chr((ord(y)+2-ord('a')) % 26 + ord('a')) or y)(j) for j in x])+' ' for x in s.split()])
s="map"
''.join([''.join([(lambda y: (y not in [z for z in s if (z<'a' or z>'z') and not z == ' ']) and chr((ord(y)+2-ord('a')) % 26 + ord('a')) or y)(j) for j in x])+' ' for x in s.split()])

相关推荐

Global site tag (gtag.js) - Google Analytics