古典恺撒文吉尼亚密码体制VB 第3页
VERSION 5.00
Begin VB.Form Form3
BackColor = &H00808000&
Caption = "文吉尼亚密码体制"
ClientHeight = 3675
ClientLeft = 3060
ClientTop = 3450
ClientWidth = 7170
LinkTopic = "Form1"
ScaleHeight = 3675
ScaleLeft = 200
ScaleMode = 0 'User
ScaleTop = 200
ScaleWidth = 7215.284
Begin VB.CommandButton Command3
BackColor = &H00FFC0C0&
Caption = "清空"
Height = 375
Left = 5280
Style = 1 'Graphical
TabIndex = 8
Top = 3000
Width = 975
End
Begin VB.CommandButton Command2
BackColor = &H00FFC0C0&
Caption = "解密"
Height = 375
Left = 3120
Style = 1 'Graphical
TabIndex = 7
Top = 3000
Width = 975
End
Begin VB.CommandButton Command1
BackColor = &H00FFC0C0&
Caption = "加密"
Height = 375
Left = 720
Style = 1 'Graphical
TabIndex = 6
Top = 3000
Width = 975
End
Begin VB.TextBox Text3
BeginProperty Font
Name = "宋体"
Size = 15
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 1935
Left = 4800
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 5
Top = 720
Width = 1815
End
Begin VB.TextBox Text2
BeginProperty Font
Name = "宋体"
Size = 15
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 1935
IMEMode = 3 'DISABLE
Left = 2640
MultiLine = -1 'True
PasswordChar = "*"
ScrollBars = 2 'Vertical
TabIndex = 4
Top = 720
Width = 1815
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "宋体"
Size = 15
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 1935
Left = 360
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 3
Top = 720
Width = 1815
End
Begin VB.Label Label3
BackColor = &H00808000&
Caption = "密 文"
BeginProperty Font
Name = "宋体"
Size = 15.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000080FF&
Height = 375
Left = 5280
TabIndex = 2
Top = 240
Width = 855
End
Begin VB.Label Label2
BackColor = &H00808000&
Caption = "密 钥"
BeginProperty Font
Name = "宋体"
Size = 15.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000080FF&
Height = 375
Left = 3120
TabIndex = 1
Top = 240
Width = 855
End
Begin VB.Label Label1
BackColor = &H00808000&
Caption = "明 文"
BeginProperty Font
Name = "宋体"
Size = 15.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000080FF&
Height = 375
Left = 960
TabIndex = 0
Top = 240
Width = 855
End
End
Attribute VB_Name = "Form3"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Const aph = "abcdefghijklmnopqrstuvwxyz" '定义字母表
Private Sub Command1_Click() '加密
If Text1.Text = "" Then '判断明文是否为空
MsgBox "请输入您要加密的明文", vbInformation
Text1.SetFocus
ElseIf Text2.Text = "" Then '判断密钥是否为空
MsgBox "请输入密钥", vbInformation
Text2.SetFocus
Else
Dim l1%, l2%, i%, j%
Dim StrPos1%, Strpos2%, Ms%
Dim Mystr$, Mystr2$, mingwen$
l2 = Len(Text2.Text) '获取密钥长度
j = 0
For i = 1 To l2 '判断密钥是否均为字母
Mystr2 = Mid(Text2.Text, i, 1)
Strpos2 = InStr(1, aph, Mystr2, 1)
If Strpos2 <> 0 Then
j = j + 1
End If
Next
If j <> l2 Then '判断密钥是否正确
MsgBox "请输入正确的密钥", vbExclamation
Text2.Text = ""
Text2.SetFocus
Else
mingwen = Text1.Text '获取原明文
l1 = Len(Text1.Text) '获取明文长度
j = 0
For i = 1 To l1 Step 1 '加密过程
Mystr = Mid(Text1.Text, i, 1)
If i Mod l2 = 0 Then
Mystr2 = Mid(Text2.Text, l2, 1)
Else
Mystr2 = Mid(Text2.Text, i Mod l2, 1)
End If
StrPos1 = InStr(1, aph, Mystr, 1) '查找原文字母在字母表中的位置
Ms = InStr(1, aph, Mystr2, 1) '查找密钥字母在字母表中的位置
If StrPos1 <> 0 Then
j = j + 1
Strpos2 = (StrPos1 + Ms - 1) Mod 26 '加密
If Strpos2 = 0 Then
Strpos2 = 26
End If
Mid$(mingwen, i, 1) = Mid$(aph, Strpos2, 1)
End If
Next i
If j <> l1 Then '判断明文是否正确即明文是否均为字母
MsgBox "请输入正确的加密数据", vbExclamation
Text1.SetFocus
Command3.Enabled = True
Else
mingwen = UCase(mingwen) '把加密后的数据转换成大写
Text3.Text = mingwen '显示加密后的数据
Command3.Enabled = True
End If
End If
End If
End Sub
Private Sub Command2_Click() '解密
If Text3.Text = "" Then '判断密文是否为空
MsgBox "请输入您要解密的密文", vbInformation
Text3.SetFocus
ElseIf Text2.Text = "" Then '判断密钥是否为空
MsgBox "请输入密钥", vbInformation
Text2.SetFocus
Else
Dim l1%, l2%, i%, j%
Dim StrPos1%, Strpos2%, Ms%
Dim Mystr$, Mystr2$, miwen$
l2 = Len(Text2.Text) '获取密钥长度
j = 0
For i = 1 To l2 '判断密钥是否均为字母
Mystr2 = Mid(Text2.Text, i, 1)
Strpos2 = InStr(1, aph, Mystr2, 1)
If Strpos2 <> 0 Then
j = j + 1
End If
Next
If j <> l2 Then '判断密钥是否正确
MsgBox "请输入正确的密钥", vbExclamation
Text2.Text = ""
Text2.SetFocus
Else
miwen = Text3.Text '获取密文
l1 = Len(Text3.Text) '获取密文长度
j = 0
For i = 1 To l1 Step 1 '解密过程
Mystr = Mid(Text3.Text, i, 1)
If i Mod l2 = 0 Then
Mystr2 = Mid(Text2.Text, l2, 1)
Else
Mystr2 = Mid(Text2.Text, i Mod l2, 1)
End If
StrPos1 = InStr(1, aph, Mystr, 1) '获取密文在字母表中的位置
Ms = InStr(1, aph, Mystr2, 1) '获取密钥在字母表中的位置
If StrPos1 <> 0 Then
j = j + 1
Strpos2 = (StrPos1 - Ms + 1 + 26) Mod 26 '解密
If Strpos2 = 0 Then
Strpos2 = 26
End If
Mid$(miwen, i, 1) = Mid$(aph, Strpos2, 1)
End If
Next i
If j <> l1 Then '判断密文是否正确即密文是否均为字母
MsgBox "请输入正确的解密数据", vbExclamation
Text3.SetFocus
Command3.Enabled = True
Else
Text1.Text = miwen '显示解密后的数据
Command3.Enabled = True
End If
End If
End If
End Sub
若图片无法显示请联系QQ752018766,古典恺撒文吉尼亚密码体制VB 第3页系统免费,转发请注明源于www.751com.cn
Command3.Enabled = False
End Sub