码迷,mamicode.com
首页 > 其他好文 > 详细

凯撒密码B

时间:2020-03-23 20:16:24      阅读:67      评论:0      收藏:0      [点我收藏+]

标签:text   NPU   turn   end   code   class   plain   supper   bsp   

def encryption(str, n):
    cipher = []
    for i in range(len(str)):
        if str[i].islower():
            if ord(str[i]) < 123-n: #ord(z)=122
                c = chr(ord(str[i]) + n)
                cipher.append(c)
            else:
                c = chr(ord(str[i]) + n - 26)
                cipher.append(c)
        elif str[i].isupper():
            if ord(str[i]) < 91-n: #ord(Z)=90
                c = chr(ord(str[i]) + n)
                cipher.append(c)
            else:
                c = chr(ord(str[i]) + n - 26)
                cipher.append(c)
        else:
            c = str[i]
            cipher.append(c)
    cipherstr = (‘‘).join(cipher)
    return cipherstr

#获得用户输入的明文
plaintext = input()
ciphertext = encryption(plaintext, 3)
print(ciphertext)

 

凯撒密码B

标签:text   NPU   turn   end   code   class   plain   supper   bsp   

原文地址:https://www.cnblogs.com/Mrlee28/p/12554577.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!