立即打印凯撒密码
printing Caesar cipher at once
def en(password,shift):
result = ""
for i in password:
result += chr(ord(i)+ shift)
return result
def de(password,shift):
result = ""
for i in password:
result += chr(ord(i) - shift)
return result
n=input("Input : ")
s=int(input("shift number : "))
e=en(n,s)
print("encoded : "+e)
print("decoded : "+de(e,s))
这是获取凯撒密码的方法
我无法解决。如何使用 'shift number' -30~30 一次打印?
还有三件事你没有处理过:
1) 字母大小写 -- 大写字母和小写字母的按摩方式略有不同。
2) 非字母 -- 非字母应该可以顺利通过。
3) 模数运算——当你在一个字母上加一个移位时,你可能会从字母表的末尾掉下来,所以你需要像时钟一样绕到开头。解码时会发生相反的情况。
在更新代码时考虑这个例子:
% python3 test.py
Input: Veni, vidi, vici
Shift number: 13
encoded: Irav, ivqv, ivpv
decoded: Veni, vidi, vici
%
def en(password,shift):
result = ""
for i in password:
result += chr(ord(i)+ shift)
return result
def de(password,shift):
result = ""
for i in password:
result += chr(ord(i) - shift)
return result
n=input("Input : ")
s=int(input("shift number : "))
e=en(n,s)
print("encoded : "+e)
print("decoded : "+de(e,s))
这是获取凯撒密码的方法
我无法解决。如何使用 'shift number' -30~30 一次打印?
还有三件事你没有处理过:
1) 字母大小写 -- 大写字母和小写字母的按摩方式略有不同。
2) 非字母 -- 非字母应该可以顺利通过。
3) 模数运算——当你在一个字母上加一个移位时,你可能会从字母表的末尾掉下来,所以你需要像时钟一样绕到开头。解码时会发生相反的情况。
在更新代码时考虑这个例子:
% python3 test.py
Input: Veni, vidi, vici
Shift number: 13
encoded: Irav, ivqv, ivpv
decoded: Veni, vidi, vici
%