【发布时间】:2023-03-09 09:45:02
【问题描述】:
在凯撒密码中,我需要我的大写字符保持大写,非字母字符保持非字母/相同。我可以使用小写字母。
但是,大写字母被转换为小写字母和不同的字母。非字母字符也会转换为小写字母。大写字母必须移动,但仍保持大写。非字母字符必须保持为非字母字符。
p = raw_input(("enter a word"))
n = input(("how many must it shift"))
a = 0
b = 0
c = 0
d = 0
for i in p:
if i.isupper():
a += 1
elif i.islower():
b += 1
elif i.isdigit():
c += 1
else:
d += 1
e = ""
for i in p:
if i == "":
e += i
else:
integerValue = ord(i)
integerValue-= 97
integerValue += n
integerValue %= 26
integerValue += 97
e += chr(integerValue)
print e
【问题讨论】:
标签: python encryption caesar-cipher