欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python challenge 1 博客分类: python PythonJ# 

程序员文章站 2024-02-04 12:05:28
...
首先解码这段文本:
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的使用。
相关标签: Python J#