例题1.1 移位密码加密解密
1.1.使用穷尽密钥搜索法破译如下利用移位密码加密的密文:
ESPESTCOPIPCNTDPYPPODACZRCLXXTYR.
1.1答案:
K=11,明文序列为: the third exercise needs programming.
python 代码实现
版本一:
# 移位编码解码
def encode():
list_s = []
r_move = int(input('请输入加密移位参数(右移): '))
s = input('请输入需要加密的字符: ')
for i in s:
list_s.append(ord(i))
for i in list_s:
# 处理空格
if i == 32:
print(' ', end='')
# 对大写字母进行处理
elif 65 <= i <= 90:
i += r_move
while i > 90:
i -= 26
# 对小写字母进行处理
elif 97 <= i <= 122:
i += r_move
while i > 122:
i -= 26
print(chr(i), end='')
# # 左移解码
# def decode():
# l_m