加密解密问题,请问这用的什么算法?是根据什么进行加密和解密的?
Option Explicit
' Encipher the text using the pasword.
'加密
Private Sub Cipher(ByVal password As String, ByVal from_text As String, to_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
' 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
End Sub
' Encipher the text using the pasword.
'解密
Private Sub Decipher(ByVal password As String, ByVal from_text As String, to_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
' 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)
If ch < 0 Then ch = ch + NUM_ASC
ch = ch + MIN_ASC
to_text = to_text & Chr$(ch)
End If
Next i
End Sub
' 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))
value = value Xor (ch * 2 ^ shift1)
value = value Xor (ch * 2 ^ shift2)
' Change the shift offsets.
shift1 = (shift1 + 7) Mod 19
Debug.Print shift1
shift2 = (shift2 + 13) Mod 23
Debug.Print shift2
Next i
NumericPassword = value
End Function
Private Sub cmdCipher_Click()
Dim cipher_text As String
Cipher txtPassword.Text, txtPlain.Text, cipher_text
txtCipher.Text = cipher_text
txtPlain.Text = ""
End Sub
Private Sub cmdDecipher_Click()
Dim plain_text As String
Dim cipher_text As String
Decipher txtPassword.Text, txtCipher.Text, plain_text
txtPlain.Text = plain_text
txtCipher.Text = ""
End Sub
Private Sub Form_Load()
txtPassword.Text = Asc("c")
End Sub
Private Sub txtPassword_Change()
If Len(txtPassword.Text) > 0 Then
cmdCipher.Enabled = True
cmdDecipher.Enabled = True
Else
cmdCipher.Enabled = False
cmdDecipher.Enabled = False
End If
End Sub
' Encipher the text using the pasword.
'加密
Private Sub Cipher(ByVal password As String, ByVal from_text As String, to_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
' 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
End Sub
' Encipher the text using the pasword.
'解密
Private Sub Decipher(ByVal password As String, ByVal from_text As String, to_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
' 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)
If ch < 0 Then ch = ch + NUM_ASC
ch = ch + MIN_ASC
to_text = to_text & Chr$(ch)
End If
Next i
End Sub
' 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))
value = value Xor (ch * 2 ^ shift1)
value = value Xor (ch * 2 ^ shift2)
' Change the shift offsets.
shift1 = (shift1 + 7) Mod 19
Debug.Print shift1
shift2 = (shift2 + 13) Mod 23
Debug.Print shift2
Next i
NumericPassword = value
End Function
Private Sub cmdCipher_Click()
Dim cipher_text As String
Cipher txtPassword.Text, txtPlain.Text, cipher_text
txtCipher.Text = cipher_text
txtPlain.Text = ""
End Sub
Private Sub cmdDecipher_Click()
Dim plain_text As String
Dim cipher_text As String
Decipher txtPassword.Text, txtCipher.Text, plain_text
txtPlain.Text = plain_text
txtCipher.Text = ""
End Sub
Private Sub Form_Load()
txtPassword.Text = Asc("c")
End Sub
Private Sub txtPassword_Change()
If Len(txtPassword.Text) > 0 Then
cmdCipher.Enabled = True
cmdDecipher.Enabled = True
Else
cmdCipher.Enabled = False
cmdDecipher.Enabled = False
End If
End Sub
...全文
相关推荐
凯撒加密解密系统
同时,通过阅读和修改代码,可以进一步提升编程技巧和问题解决能力。在学习过程中,可以尝试扩展此系统,增加对数字和其他特殊字符的支持,或者实现更复杂的加密算法,以加深对信息安全的理解。
支持中文的php加密解密类代码
"\n";```#### 五、注意事项- 该加密解密类虽然支持中文,但在实际应用中还需考虑字符编码问题,确保数据的一致性和完整性。
一个C语言编程的加密解密
该程序使用了XOR运算作为加密解密算法,能够根据用户提供的文件路径和密码字符串,对文件进行加密或解密操作。尽管其实现相对简单,但在实际应用中需要注意其安全性问题。
Golang加密解密之RSA(附带php)
### Golang加密解密之RSA(附带php)#### RSA加密算法简史RSA加密算法是一种非对称加密算法,由罗纳德·李维斯特(Ron Rivest)、阿迪·萨莫尔(Adi Shamir)和伦纳德
3DES加密解密工具
总的来说,3DES加密解密工具是一种实用的软件,它利用3DES算法提供强加密功能,适用于保护敏感信息。无论是企业还是个人,都可以利用这样的工具来增加数据的安全性,防止未经授权的访问和窃取。


VB基础类
