古典恺撒文吉尼亚密码体制VB 第2页
VERSION 5.00
Begin VB.Form Form2
BackColor = &H00808000&
Caption = "恺撒密码体制"
ClientHeight = 3615
ClientLeft = 3060
ClientTop = 3450
ClientWidth = 7170
FillColor = &H00C0C000&
BeginProperty Font
Name = "宋体"
Size = 15.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00C0C000&
LinkTopic = "Form1"
ScaleHeight = 3615
ScaleLeft = 200
ScaleMode = 0 'User
若图片无法显示请联系QQ752018766,古典恺撒文吉尼亚密码体制VB 第2页系统免费,转发请注明源于www.751com.cn
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 3120
MaskColor = &H00FFC0C0&
Style = 1 'Graphical
TabIndex = 10
Top = 2880
UseMaskColor = -1 'True
Width = 855
End
Begin VB.CommandButton Command2
BackColor = &H00FFC0C0&
Caption = "解密"
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 3120
MaskColor = &H00FF8080&
Style = 1 'Graphical
TabIndex = 7
Top = 2280
UseMaskColor = -1 'True
Width = 855
End
Begin VB.CommandButton Command1
BackColor = &H00FFC0C0&
Caption = "加密"
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 3120
MaskColor = &H8000000F&
Style = 1 'Graphical
TabIndex = 6
Top = 1680
Width = 855
End
Begin VB.TextBox Text3
Height = 2055
Left = 4320
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 5
Top = 720
Width = 2415
End
Begin VB.TextBox Text1
Height = 2055
Left = 360
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 4
Top = 720
Width = 2415
End
Begin VB.TextBox Text2
Height = 375
IMEMode = 3 'DISABLE
Left = 3120
PasswordChar = "*"
TabIndex = 3
Top = 840
Width = 855
End
Begin VB.Label Label6
BackColor = &H00808000&
Caption = "(数字)"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 3240
TabIndex = 11
Top = 1320
Width = 735
End
Begin VB.Label Label5
BackColor = &H00808000&
Caption = "(均为字母)"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 4680
TabIndex = 9
Top = 3000
Width = 1335
End
Begin VB.Label Label4
BackColor = &H00808000&
Caption = "(均为字母)"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 720
TabIndex = 8
Top = 3000
Width = 1335
End
Begin VB.Label Label3
BackColor = &H00808000&
BackStyle = 0 'Transparent
Caption = "密 文"
BeginProperty Font
Name = "宋体"
Size = 15
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000080FF&
Height = 300
Left = 5160
TabIndex = 2
Top = 240
Width = 855
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "明 文"
BeginProperty Font
Name = "宋体"
Size = 15
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000080FF&
Height = 300
Left = 1200
TabIndex = 1
Top = 240
Width = 855
End
Begin VB.Label Label2
AutoSize = -1 'True
BackColor = &H00808000&
BackStyle = 0 'Transparent
Caption = "密 钥"
BeginProperty Font
Name = "宋体"
Size = 15
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000080FF&
Height = 300
Left = 3240
TabIndex = 0
Top = 240
Width = 750
End
End
Attribute VB_Name = "Form2"
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
ElseIf IsNumeric(Text2.Text) = 0 Then '判断密钥是否正确
MsgBox "请输入正确的密钥", vbExclamation
Text2.Text = ""
Text2.SetFocus
Else
Dim l%, i%, j%
Dim StrPos1%, Strpos2%
Dim Mystr$, str1$, str2$
Dim Newstr() As String
l = Len(Text1.Text) '获取明文长度
ReDim Newstr(1 To l) '定义一动态数组来存放加密后的数据
j = 0
For i = 1 To l Step 1 '加密过程
Mystr = Mid(Text1.Text, i, 1) '截取明文的数据
StrPos1 = InStr(1, aph, Mystr, 1) '判断明文字母在字母表中的位置
If StrPos1 <> 0 Then '当明文在字母表中执行如下
j = j + 1
Strpos2 = (StrPos1 + Val(Text2.Text)) Mod 26 '加密后所在字母表中的位置
If Strpos2 = 0 Then
Strpos2 = 26
End If
Newstr(i) = Mid(aph, Strpos2, 1) '加密后的数据赋给动态数组
End If
Next i
If j <> l Then '判断明文是否正确即是否都为字母
MsgBox "请输入正确的数据", vbExclamation
Text1.SetFocus
Command3.Enabled = True
Else
str1 = Join(Newstr, "") '把数组转换成字符串
str2 = UCase(str1) '把字符串转换成大写
Text3.Text = str2 '显示加密后的密文
Command3.Enabled = True
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
ElseIf IsNumeric(Text2.Text) = 0 Then '判断密钥是否正确
MsgBox "请输入正确的密钥", vbExclamation
Text2.Text = ""
Text2.SetFocus
Else
Dim l%, i%, j%
Dim StrPos1%, Strpos2%
Dim Mystr$, str1$
Dim Newstr() As String
l = Len(Text3.Text) '获取密文长度
ReDim Newstr(1 To l) '定义一个动态数组暂存解密后的数据
j = 0
For i = 1 To l Step 1 '解密过程
Mystr = Mid(Text3.Text, i, 1) '截取密文数据
StrPos1 = InStr(1, aph, Mystr, 1) '查找密文在字母表中的位置
If StrPos1 <> 0 Then '当密文在字母表中则执行以下代码
j = j + 1
Strpos2 = (StrPos1 - Val(Text2.Text) Mod 26 + 26) Mod 26 '解密后的位置
If Strpos2 = 0 Then
Strpos2 = 26
End If
Newstr(i) = Mid(aph, Strpos2, 1) '把解密后的数据赋给数组
End If
Next i
If j <> l Then '判断密文是否正确
MsgBox "请输入正确的数据", vbExclamation
Text3.SetFocus
Command3.Enabled = True
Else
str1 = Join(Newstr, "") '把数组转换成字符串
Text1.Text = str1 '显示解密后的数据
Command3.Enabled = True
End If
End If
End Sub
Private Sub Command3_Click() '清空
i = MsgBox("你确定要清除所有的内容吗?", vbOKCancel + vbInformation)
If i = 1 Then
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Command3.Enabled = False
Else
End If
End Sub
Private Sub Form_Load()
Command3.Enabled = False
End Sub