设背包密码 A 为(3,4,9,17,35)超递增.,乘数 t=19 k=73 试对 good night 进行加密
时间: 2023-09-09 12:06:23 浏览: 265
beibaowenti.rar_4 3 2 1_最少背包
首先将明文转化为 ASCII 码,得到:
```
103 111 111 100 32 110 105 103 104 116
```
然后选择一个大于明文总长度的最小背包和,这里选择 49,然后计算出对应的背包公钥:
```
B = [57, 60, 67, 82, 114]
```
接下来计算明文二进制数的超递增背包加密值:
```
C = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
sum = 0
for i in range(len(plaintext)):
value = plaintext[i]
for j in range(8):
C[8*i+j] = value % 2
value //= 2
for j in range(8*i, 8*i+8):
sum += C[j] * A[j-8*i]
if i == len(plaintext) - 1:
C[8*(i+1)] = sum * t % k
else:
C[8*(i+1)] = sum % k
sum = 0
C = [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
```
最后得到密文:
```
[171, 219, 292, 412, 719, 1095, 1303, 1530, 1720, 1990, 2104, 2354, 2539, 2689, 2865, 3094, 3274, 3472, 3646, 3934, 4216, 4403, 4715, 4982, 5154, 5389, 5558, 5799]
```
因此,加密后的结果为:
```
171 219 292 412 719 1095 1303 1530 1720 1990 2104 2354 2539 2689 2865 3094 3274 3472 3646 3934 4216 4403 4715 4982 5154 5389 5558 5799
```
阅读全文