📄 c.frm
字号:
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 3 'Fixed Dialog
Caption = "凯撒加密(密钥k=3)"
ClientHeight = 2205
ClientLeft = 45
ClientTop = 435
ClientWidth = 4005
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2205
ScaleWidth = 4005
ShowInTaskbar = 0 'False
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "开始解密"
Height = 375
Left = 2400
TabIndex = 5
Top = 1560
Width = 975
End
Begin VB.CommandButton Command1
Caption = "开始加密"
Height = 375
Left = 1080
TabIndex = 2
Top = 1560
Width = 975
End
Begin VB.TextBox Text2
Height = 375
Left = 1080
TabIndex = 1
Top = 960
Width = 2535
End
Begin VB.TextBox Text1
Height = 375
Left = 1080
TabIndex = 0
Top = 240
Width = 2535
End
Begin VB.Label Label2
Caption = "密文:"
Height = 255
Left = 240
TabIndex = 4
Top = 960
Width = 615
End
Begin VB.Label Label1
Caption = "明文:"
Height = 255
Left = 240
TabIndex = 3
Top = 240
Width = 735
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Dim mw As String
Dim m As String
Dim k As Integer
Dim n As Integer
Dim i As Long
Dim tmp As String
If Text1.Text = "" Then
MsgBox "请输入明文。"
Text1.SetFocus
Exit Sub
End If
k = 4
n = 26
mw = Text1.Text
For i = 1 To Len(mw)
tmp = Mid(mw, i, 1)
tmp = f(tmp, k, n)
If tmp <> "error" Then
m = m + tmp
Else
MsgBox "字符串中含有非法字符,只能为英文字母!"
Text1.SetFocus
Exit Sub
End If
Next i
Text2.Text = m
End Sub
Private Function f(ByVal a As String, k As Integer, n As Integer) As String
If ((Asc(a) >= 65 And Asc(a) <= 97) Or (Asc(a) >= 97 And Asc(a) <= 122)) And Len(a) = 1 Then
If Asc(a) >= 65 And Asc(a) <= 97 Then f = Chr((Asc(a) - 64 + k) Mod n + 64)
If Asc(a) >= 97 And Asc(a) <= 122 Then f = Chr((Asc(a) - 96 + k) Mod n + 96)
Else
f = "error"
End If
End Function
Private Function j(ByVal a As String, k As Integer, n As Integer) As String
If ((Asc(a) >= 65 And Asc(a) <= 97) Or (Asc(a) >= 97 And Asc(a) <= 122)) And Len(a) = 1 Then
If Asc(a) >= 65 And Asc(a) <= 97 Then j = Chr((Asc(a) - 64 - k) Mod n + 64)
If Asc(a) >= 97 And Asc(a) <= 122 Then j = Chr((Asc(a) - 96 - k) Mod n + 96)
Else
j = "error"
End If
End Function
Private Sub Command2_Click()
Dim mw As String
Dim m As String
Dim k As Integer
Dim n As Integer
Dim i As Long
Dim tmp As String
If Text2.Text = "" Then
MsgBox "请输入密文"
Text2.SetFocus
Exit Sub
End If
k = 4
n = 26
mw = Text2.Text
For i = 1 To Len(mw)
tmp = Mid(mw, i, 1)
tmp = j(tmp, k, n)
If tmp <> "error" Then
m = m + tmp
Else
MsgBox "字符串中含有非法字符,只能为英文字母!"
Text2.SetFocus
Exit Sub
End If
Next i
Text1.Text = m
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -