计算机等级考试二级VB常用算法(10):字符处理
1、算法说明
1) 加密解密
最简单的加密方法是:将每个字母加一序数,例如5,这时:
“A”→”F”,”a” →”f”,”B” →”G”,”b” →”g”……”Y” →”D”, ”y” →”d”,”Z” →”E”, ”z” →”e”
解密是加密的逆操作。
界面如下:
代码如下:
Option Explicit
Private Sub Command1_Click()
Dim strInput$, Code$, Record$, c As String * 1
Dim i%, length%, iAsc%
strInput = Text1.Text
length = Len(Trim(strInput))
Code = ""
For i = 1 To length
c = mid(strInput, i, 1)
Select Case c
Case "A" To "Z"
iAsc = Asc(c) + 5
If iAsc > Asc("Z") Then iAsc = iAsc - 26
Code = Code & Chr(iAsc)
Case "a" To "z"
iAsc = Asc(c) + 5
If iAsc > Asc("z") Then iAsc = iAsc - 26
Code = Code & Chr(iAsc)
Case Else
Code = Code & c
End Select
Next i
Text2.Text = Code
End Sub
Private Sub Command3_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text1.SetFocus
End Sub 首页 1 2 3 尾页