根据上述加密算法编写解密程序。程序在启动时读取密钥矩阵存入数组a 中,在文本框Text1
中输入密文,点击“解密”按钮,在文本框Text2 中显示明文。运行界面如图c 所示。
Const n = 3
Dim a(1 To n * n) As Integer
Private Sub Command1_Click()
Dim mw(1 To 2*n*n) As Integer
'存储密文数据,奇数位存储加密值,偶数位存储该数据在原文中的位置
Dim yw(1 To n*n) As Integer '存储解密数据
Dim k As Integer
'生成规模为n*n 的密钥矩阵存入数组a中,代码略
For i = 1 To Len(Text1.Text)
c = Mid(Text1.Text, i, 1)
If c <> "," Then
t = t * 10 + Val(c)
Else
mw(k) = Val(t): t = 0
End If
Next i
For i = 1 To k\2 '对密文解密,结果存数组yw
yw(mw(2 * i)) =
Next i
s = ""
For i = 1 To k\2
s = s + Chr((yw(i)) + 64)
Next i
Text2.Text = s
End Sub
Function getmm(x As Integer, n As Integer)
col = (x - 1) Mod n + 1
row = (x - 1) \ n + 1
getmm = a((col - 1) * n + row)
If row Mod 2 = 0 Then getmm =
End Function