python2.7.5实现ROT13编解码

来源:互联网 发布:java set 取值 编辑:程序博客网 时间:2024/05/23 12:30
#! /usr/bin/python
"""This function need two input:the string and the moving number."""


def rot13(st,t):
    n=''
    l=len(st)
    for i in range(l):
        if ord(st[i])>ord('Z'):
            if (ord(st[i])+t)>ord('z'):
                n=n+chr(ord(st[i])+t-26)

            elif (ord(st[i])+t)<ord('a'):
                n=n+chr(ord(st[i])+t+26)

            else:
                n=n+chr(ord(st[i])+t)
        elif (ord(st[i])+t)>ord('Z'):
            n=n+chr(ord(st[i])+t-26)

        elif (ord(st[i])+t)<ord('A'):
            n=n+chr(ord(st[i])+t+26)
        else:
            n=n+chr(ord(st[i])+t)
    return n
s=raw_input("input s:")
t=int(raw_input("input t:"))
print rot13(s,t)
0 0