⑴在输入的数字字符串中依次提取有效的密文,有效的密文的特点:
①是一组连续的,都小于5的三位数字串;②每个位置上的数字不能被重复提取;
⑵对有效密文进行解密的过程:
将密文作为一个五进制数转换为对应的十进制数值,根据ASCII字符的十进制编码表,得出对应的明文字符(提示:空格符所对应的ASCII码值为十进制数32,小写字母”z”所对应的ASCII码值为十进制数122)。
例如,密文242转换成十进制数为72,对应的明文字符为大写字母“H”。
程序运行界面如下图所示,在文本框Text1中输入密文,单击“解密”按钮,在文本框Text2中输出解密后的明文密码。
'以下代码是将有效密文数字转换为十进制数的函数
Function conv(p As String) As Integer
Dim k As Integer, q As String, i As Integer
k = 0: g = ""
For i = 1 To 3
q = Mid(p, i, 1)
Next i
conv = k
End Function
Private Sub Command1_Click()
Dim st As String, p As String, res As String
Dim c1 As String, c2 As String, c3 As String
Dim i As Integer, d As Integer, n 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
d=conv(p)
If d >= 32 And d <= 122 Then res = res + Chr(d)
Else
i = i + 1
End If
Loop
Text2.Text = res
End Sub