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)