#对ASCLL码表中95个可视化字符的支持
def enChar(x,key):
# 加密
xid = ord(x)-first_ascll # 明文编号
yid = (xid+key) % n # 密文编号
y = chr(first_ascll+yid) # 求出密文字符
return y
first_ascll = ord(' ') # 起始字符
n = 95 # 字符总数
def Caesar(text,key):
result = ''
for x in text:
# 字符范围
if ' '<=x<='~':
x = enChar(x, key)
result = result + x
return result
text = 'Attack Tonight!'
key = 2
print(Caesar(text, -key))
相关文章
- 11-22对ASCLL码表中95个可视化字符的支持