①将密文进行转换为一个十进制数值:例如密文242转换的表达式为:2*53+4*5*+2*5*=72 对应的明文字符为大写“H":
②得到的数值就是对应明文的ASCII 字符的十进制编码(提示:空格所对应的ASCII值为十进制32,小写字母“z”所对应的ASCII值为十进制数122);
程序运行界面如下图所示。在文本框Text1中输入密文,单击“解密”按钮,在文本框Text2 中输出解密后的明文密码。实现上述功能的VB代码如下:
Private Sub Convnand1_Click()
Dim st, p, c1, c2, c3 As String
Dim i, d, res As Integer
st = Text1.Text: n = Len(st)
i=1:res=””
Do While i <=n- 2 '提取有效密文,并进行转换
c1 = Mid(st, i, 1): c2 = Mid(st, i + 1, 1): c3= Mid(st, i +2, 1)
If Then ‘①
p = Mid(st, i, 3)
d = conv(p)
If d>=32 And d<=122 Then res= res + Chr(d)
②
Else
i =i+1
End If
Loop
Text2 Text = ③
End Sub
‘以下代码是将有效密文数字转换为十进制数的函数
Function conv(p As String) As Integer
Dim k As Integer, q As String, i As Integer
k=0:q=””
For i =ITo 3
q = Mid(p, i, 1)
④
Next i
conv=k
End Function