实现凯撒加密,输入明文和一个数字,输出密文

动态 未结 0 64
小小草
小小草 LV1 2023年9月23日 23:40 发表
plain_text = input('请输入明文:') shift = int(input('请输入数字:')) cipher_text = '' for char in plain_text: if char.isalpha(): # 将字符转换为ASCII码,加上偏移量,再将结果转换为字符 new_char_code = ord(char) + shift if char.islower() and new_char_code > ord('z'): new_char_code -= 26 elif char.isupper() and new_char_code > ord('Z'): new_char_code -= 26 cipher_text += chr(new_char_code) else: cipher_text += char print('密文为:', cipher_text)
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复