[python]rot13练习

[python]rot13练习
code:

def rot13(s):
    intab=''
    outtab=''
    for a in range(ord('A'),ord('Z')+1):
        intab+=chr(a)
    for a in range(ord('a'),ord('z')+1):
        intab+=chr(a)
    for b in range(ord('N'),ord('Z')+1):
        outtab+=chr(b)
    for b in range(ord('A'),ord('N')):
        outtab+=chr(b)
    for b in range(ord('n'),ord('z')+1):
        outtab+=chr(b)
    for b in range(ord('a'),ord('n')):
        outtab+=chr(b)
    trantab=str.maketrans(intab,outtab)
    return s.translate(trantab)




if __name__ == '__main__':
    s1='Yvsr vf cngurgvp, yrg\'f clgubavp!'
    r1=rot13(s1)
    print(r1)
    print(s1==rot13(r1))

    s2='Jvgu terng cbjre,pbzrf terng erfobafvovyvgl!'
    r2=rot13(s2)
    print(r2)
    print(s2==rot13(r2))

结果:
[python]rot13练习
end

上一篇:南邮 起名字真难


下一篇:2020年G2电站锅炉司炉考试资料及G2电站锅炉司炉试题及答案