古典密码学与密码数学基础
1. Hill 2x2 密码
1.1 密码原理
Hill 2x2 密码是基于线性代数的多表替换密码,由 Lester S. Hill 在 1929 年发明。它使用矩阵和矩阵乘法来混合明文以生成密文。理解该密码需要熟悉数论知识。
1.2 示例
- 密钥:HILL,对应数字 7, 8, 11, 11
- 明文:SECRETMESSAG
- 密文:CIUBYTMUKGWO
1.3 Python 实现
import sys
import numpy as np
def cipher_encryption(plain, key):
# if message length is an odd number, place a zero at the end.
len_chk = 0
if len(plain) % 2 != 0:
plain += "0"
len_chk = 1
# msg to matrices
row = 2
col = int(len(plain)/2)
msg2d = np.zeros((row, col), dtype=int)
itr1 = 0
itr2 = 0
for i in range(len(plain)):
if i%2 == 0:
msg2d[0][itr1]= int(ord(
超级会员免费看
订阅专栏 解锁全文
1024

被折叠的 条评论
为什么被折叠?



