#get string and shift from user
string = input('Please enter a string to be ciphered: ')
shift = input('Please enter a shift amount between 0 and 25: ')
#strings are immutable so it must be converted to a list
s=list(string)
#now this will convert each character based on the shift
for i in range(0,len(s)):
s[i]=chr(ord(s[i]) + int(shift))
print ("".join(s))
您所要做的就是检查当前字符是否不是要跳过的字符
但是,您的一个字符有可能被加密到一个空格中,在这种情况下,当反转密码时,该字符将被跳过
同样,像这样的简单密码至少不应该被认为是安全的
在移位之前,应该调用方法str.alpha,以确保所选元素是字母表
不过,你在这里做了很多工作。为什么不使用理解表达
或者如果你够冒险的话
最后你检查了string.makestrans和str.translate来进行转换吗
相关问题 更多 >
编程相关推荐