📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "维吉尼亚密码"
ClientHeight = 3360
ClientLeft = 60
ClientTop = 345
ClientWidth = 5325
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 3360
ScaleWidth = 5325
StartUpPosition = 2 'CenterScreen
Begin VB.TextBox txtKey
Height = 375
Left = 840
MultiLine = -1 'True
TabIndex = 7
Top = 1200
Width = 3855
End
Begin VB.CommandButton cmdDecryption
Caption = "解密"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 3000
TabIndex = 3
Top = 2640
Width = 1095
End
Begin VB.CommandButton cmdEncrtption
Caption = "加密"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 1200
TabIndex = 2
Top = 2640
Width = 1095
End
Begin VB.TextBox txtCiphertext
Height = 855
Left = 840
MultiLine = -1 'True
TabIndex = 1
Top = 1680
Width = 3855
End
Begin VB.TextBox txtPlaintext
Height = 855
Left = 840
MultiLine = -1 'True
TabIndex = 0
Top = 240
Width = 3855
End
Begin VB.Label Label3
Caption = "密文:"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 120
TabIndex = 6
Top = 1800
Width = 615
End
Begin VB.Label Label2
Caption = "密钥:"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 120
TabIndex = 5
Top = 1200
Width = 615
End
Begin VB.Label Label1
Caption = "明文:"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 120
TabIndex = 4
Top = 480
Width = 855
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub cmdDecryption_Click() '解密功能
Dim Cipher
Dim Key, iLenKey
Key = Trim(Me.txtKey.Text)
Cipher = Trim(Me.txtCiphertext.Text)
If Len(Cipher) = 0 Then MsgBox "密文不能为空!", vbOKOnly + vbQuestion, "警告": Exit Sub
If Len(Key) = 0 Then MsgBox "密钥不能为空!", vbOKOnly + vbQuestion, "警告": Exit Sub
Call DecryptionAlgorithm(Cipher, Key)
End Sub
Private Sub cmdEncrtption_Click() '加密功能
Dim Plain
Dim Key, iLenKey
Key = Trim(Me.txtKey.Text)
Plain = Trim(Me.txtPlaintext.Text)
If Len(Plain) = 0 Then MsgBox "明文不能为空!", vbOKOnly + vbQuestion, "警告": Exit Sub
If Len(Key) = 0 Then MsgBox "密钥不能为空!", vbOKOnly + vbQuestion, "警告": Exit Sub
Call EncryptionAlgorithm(Plain, Key)
End Sub
Public Sub EncryptionAlgorithm(Plaintext, Key) '加密算法
Dim i, j, iStart, iKey
Dim c, k, s
If Len(Plaintext) = 0 Then MsgBox "明文不能为空!", vbOKOnly + vbQuestion, "警告": Exit Sub
If Len(Key) = 0 Then MsgBox "密钥不能为空!", vbOKOnly + vbQuestion, "警告": Exit Sub
j = 1
For i = 1 To Len(Plaintext)
c = Mid(Plaintext, i, 1)
If (Asc(c) >= Asc("a") And Asc(c) <= Asc("z")) Then iKey = 1
If (Asc(c) >= Asc("A") And Asc(c) <= Asc("Z")) Then iKey = 2
If j > Len(Key) Then
iStart = 1: j = 1
Else
iStart = j
End If
j = j + 1
k = Mid(LCase(Trim(Key)), iStart, 1)
s = s & IIf(iKey = 1, LCase(Chr(Asc(c) + (Asc(k) - Asc("a")))), UCase(Chr(Asc(c) + _
(Asc(k) - Asc("a")))))
Next i
Me.txtCiphertext.Text = s
End Sub
Public Sub DecryptionAlgorithm(Ciphertext, Key) '解密算法
Dim i, j, iStart, iKey
Dim c, k, s
If Len(Ciphertext) = 0 Then MsgBox "密文不能为空!", vbOKOnly + vbQuestion, "警告": Exit Sub
If Len(Key) = 0 Then MsgBox "密钥不能为空!", vbOKOnly + vbQuestion, "警告": Exit Sub
j = 1
For i = 1 To Len(Ciphertext)
c = Mid(Ciphertext, i, 1)
If (Asc(c) >= Asc("a") And Asc(c) <= Asc("z")) Then iKey = 1
If (Asc(c) >= Asc("A") And Asc(c) <= Asc("Z")) Then iKey = 2
If j > Len(Key) Then
iStart = 1: j = 1
Else
iStart = j
End If
j = j + 1
k = Mid(LCase(Trim(Key)), iStart, 1)
s = s & IIf(iKey = 1, LCase(Chr(Asc(c) - (Asc(k) - Asc("a")))), UCase(Chr(Asc(c) - _
(Asc(k) - Asc("a")))))
Next i
Me.txtPlaintext.Text = s
End Sub
Private Sub txtCiphertext_Change()
Dim Cipher
Cipher = Trim(Me.txtCiphertext.Text)
If Len(Cipher) = 0 Then Exit Sub
If Not (Asc(Right(Cipher, 1)) >= Asc("a") And Asc(Right(Cipher, 1)) <= Asc("z")) And Not _
(Asc(Right(Cipher, 1)) >= Asc("A") And Asc(Right(Cipher, 1)) <= Asc("Z")) Then
MsgBox "输入大小写英文字符!", vbCritical, "警告"
Me.txtCiphertext.SelStart = Len(Cipher) - 1
Me.txtCiphertext.SelLength = 1
End If
End Sub
Private Sub txtKey_Change()
Dim Key
Key = Trim(Me.txtKey.Text)
If Len(Key) = 0 Then Exit Sub
If Not (Asc(Right(Key, 1)) >= Asc("a") And Asc(Right(Key, 1)) <= Asc("z")) And Not _
(Asc(Right(Key, 1)) >= Asc("A") And Asc(Right(Key, 1)) <= Asc("Z")) Then
MsgBox "输入大小写英文字符!", vbCritical, "警告"
Me.txtKey.SelStart = Len(Key) - 1
Me.txtKey.SelLength = 1
End If
End Sub
Private Sub txtPlaintext_Change()
Dim Plain
Plain = Trim(Me.txtPlaintext.Text)
If Len(Plain) = 0 Then Exit Sub
If Not (Asc(Right(Plain, 1)) >= Asc("a") And Asc(Right(Plain, 1)) <= Asc("z")) And Not _
(Asc(Right(Plain, 1)) >= Asc("A") And Asc(Right(Plain, 1)) <= Asc("Z")) Then
MsgBox "输入大小写英文字符!", vbCritical, "警告"
Me.txtPlaintext.SelStart = Len(Plain) - 1
Me.txtPlaintext.SelLength = 1
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -