-
自定义数字和字符串加密工具的VB源代码
资源介绍
VB源码--自定义数字&字符串加密工具
--VB源码 加密 解密 字符串 源码
*************以下为窗口及控件代码************
Private Sub Command1_Click()
Label3.Caption = cipher(Text1.Text, Text2.Text)
Label8.Caption = "加密完成!"
End Sub
Private Sub Command2_Click()
Label4.Caption = Decipher(Text4.Text, Text3.Text)
Label9.Caption = "解密完成!"
End Sub
Private Sub Label3_Click()
Text3.Text = Label3.Caption
End Sub
Private Sub Label3_DblClick()
Clipboard.SetText Label3.Caption
Label8.Caption = "复制成功!"
End Sub
Private Sub Label4_DblClick()
Clipboard.SetText Label4.Caption
Label9.Caption = "复制成功!"
End Sub
************以下为模块代码***************
' Encipher the text using the pasword.加密
Public Function cipher(ByVal password As String, ByVal from_text As String)
Const MIN_ASC = 32 ' Space.
Const MAX_ASC = 126 ' ~.
Const NUM_ASC = MAX_ASC - MIN_ASC + 1
Dim offset As Long
Dim str_len As Integer
Dim i As Integer
Dim ch As Integer
Dim to_text As String
' Initialize the random number generator.
offset = NumericPassword(password)
Rnd -1
Randomize offset
' Encipher the string.
str_len = Len(from_text)
For i = 1 To str_len
ch = Asc(Mid$(from_text, i, 1))
If ch >= MIN_ASC And ch <= MAX_ASC Then
ch = ch - MIN_ASC
offset = Int((NUM_ASC + 1) * Rnd)
ch = ((ch + offset) Mod NUM_ASC)
ch = ch + MIN_ASC
to_text = to_text & Chr$(ch)
End If
Next i
cipher = to_text
End Function
' Encipher the text using the pasword.解密
Public Function Decipher(ByVal password As String, ByVal from_text As String)
Const MIN_ASC = 32 ' Space.
Const MAX_ASC = 126 ' ~.
Const NUM_ASC = MAX_ASC - MIN_ASC + 1
Dim offset As Long
Dim str_len As Integer
Dim i As Integer
Dim ch As Integer
Dim to_text As String
' Initialize the random number generator.
offset = NumericPassword(password)
Rnd -1
Randomize offset
' Encipher the string.
str_len = Len(from_text)
For i = 1 To str_len
*****************
省略部分代码(内详)
*****************
If ch < 0 Then ch = ch + NUM_ASC
ch = ch + MIN_ASC
to_text = to_text & Chr$(ch)
End If
Next i
Decipher = to_text
End Function
' Translate a password into an offset value.
Private Function NumericPassword(ByVal password As String) As Long
Dim value As Long
Dim ch As Long
Dim shift1 As Long
Dim shift2 As Long
Dim i As Integer
Dim str_len As Integer
str_len = Len(password)
For i = 1 To str_len
' Add the next letter.
ch = Asc(Mid$(password, i, 1))
*****************
省略部分代码(内详)
*****************
Next i
NumericPassword = value
End Function