首页 > 其他 > 详细

凯撒密码B

时间:2020-09-21 16:38:29      阅读:82      评论:0      收藏:0      [点我收藏+]
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

原文:https://www.cnblogs.com/zfx13660938374/p/13704949.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!