📄 例14.frm
字号:
VERSION 5.00
Begin VB.Form frm8_7_8
Caption = "例14:文本加、解密"
ClientHeight = 1725
ClientLeft = 60
ClientTop = 450
ClientWidth = 6165
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
ScaleHeight = 1725
ScaleWidth = 6165
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton CmdRevert
Caption = "解 密"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 615
Left = 3960
TabIndex = 2
Top = 480
Width = 1455
End
Begin VB.CommandButton CmdEncipher
Caption = "加 密"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 615
Left = 2280
TabIndex = 1
Top = 480
Width = 1455
End
Begin VB.CommandButton CmdInText
Caption = "输入原文"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 615
Left = 240
TabIndex = 0
Top = 480
Width = 1815
End
End
Attribute VB_Name = "frm8_7_8"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim everytext As String
'声明窗体级变量,everytext保存原文
Public Function encipher(origtext As String) '加密函数 ,形参origtext对应实参everytext
Dim newtext As String, currchar As String, newchar As String
Dim origlen As Integer
origlen = Len(origtext)
For k = 1 To origlen ' 逐个字符加密
currchar = Mid$(origtext, k, 1): newchar = Chr$(Asc(currchar) + 3)
newtext = newtext & newchar
Next
encipher = newtext
End Function
Public Function revert(origtext As String) As String ' 解密函数
Dim newtext As String, currchar As String, newchar As String, origlen As Integer
origlen = Len(origtext)
For k = 1 To origlen ' 逐个字符还原
currchar = Mid$(origtext, k, 1): newchar = Chr$(Asc(currchar) - 3)
newtext = newtext & newchar
Next
revert = newtext
End Function
Private Sub cmdintext_Click() ' 输入原文事件,对应图8-13中的"输入原文"按钮
everytext = InputBox("请输入需要加密的原文", "未加密")
End Sub
Private Sub Cmdencipher_Click() ' 加密事件,对应图8-13中的"对原文进行加密"按钮
Dim enciphertext As String
enciphertext = encipher(everytext) ' 调用加密函数过程
MsgBox enciphertext, vbExclamation, "加密成功" ' 对话框中显示加密的文本
End Sub
Private Sub Cmdrevert_Click() ' 解密事件,对应图8-13中的"对原文进行解密"按钮
Dim reverttext As String
reverttext = revert(encipher(everytext))
MsgBox reverttext, vbExclamation, "解密成功" ' 对话框中显示解密的文本
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -