英文行吗?我找了一个英文字符串加密程序:参考参考。There are many algorithms available for string encryption and decryption, but often they become complicated due to the need to ensure that the ASCII value of an encrypted character stays within the limits of a single byte (0-255). An elegant approach is to use the XOR function. The simple subroutine below will always give results falling within the 0-255 limit. It also has the advantage that a second call will reverse the encryption automatically.Function Encrypt(sPassWord As String, sText As String) As StringDim I As Integer Dim iPChar As Integer Dim iCChar As Integer Do While Len(sPassWord) < Len(sText) sPassWord = sPassWord & sPassWord Loop For I = 1 To Len(sText) iPChar = Asc(Mid$(sPassWord, I, 1)) Char = Asc(Mid$(sText, I, 1)) d$(sText, I, 1) = Chr$(iPChar Xor iCChar) Next I Encrypt = sTextEnd FunctionOne thing you should be aware of is that the encrypted string may contain Chr$(0) values. While this will not be a problem with Visual Basic strings, other Windows objects treat Chr$(0) as an end-of-string character. Use of the encrypted string with a Text Box or in API calls may produce unexpected results.
哦这个是加密和解密的,不过好象不太合适,你自己参考以下,不好用不要骂我。 'Just put this in a form. And figure out how to 'call them yourself.'This is how encryption is done boys and girls. 'I'm sick of seeing posts of encryption routines 'that add and subtract to the ascii number of a 'character. It's very ineffective. Decryption 'programs can crack simple stuff like that in 'less than a second. Do it right.'Note: Don't make the key repetative in any way!Option ExplicitPrivate Function Decrypt(PlainStr As String, key As String) Dim Char As String, KeyChar As String, NewStr As String Dim Pos As Integer Dim i As Integer, Side1 As String, Side2 As String Pos = 1'This is a little trick to make it slightly harder to crack. 'However, the chances of this operation firing is 50/50 'because the length of the string must be divisable by 2. If Len(PlainStr) Mod 2 = 0 Then Side1 = StrReverse(Left(PlainStr, (Len(PlainStr) / 2))) Side2 = StrReverse(Right(PlainStr, (Len(PlainStr) / 2))) PlainStr = Side1 & Side2 End If'This loop decrypts the data. For i = 1 To Len(PlainStr) Char = Mid(PlainStr, i, 1) KeyChar = Mid(key, Pos, 1) NewStr = NewStr & Chr(Asc(Char) Xor Asc(KeyChar)) If Pos = Len(key) Then Pos = 0 Pos = Pos + 1 Next iDecrypt = NewStr End FunctionPrivate Function Encrypt(PlainStr As String, key As String) Dim Char As String, KeyChar As String, NewStr As String Dim Pos As Integer Dim i As Integer, Side1 As String, Side2 As String Pos = 1'This loop encrypts the data. For i = 1 To Len(PlainStr) Char = Mid(PlainStr, i, 1) KeyChar = Mid(key, Pos, 1) NewStr = NewStr & Chr(Asc(Char) Xor Asc(KeyChar)) If Pos = Len(key) Then Pos = 0 Pos = Pos + 1 Next i'This is a little trick to make it slightly harder to crack. 'However, the chances of this operation firing is 50/50 'because the length of the string must be divisable by 2. If Len(NewStr) Mod 2 = 0 Then Side1 = StrReverse(Left(NewStr, (Len(NewStr) / 2))) Side2 = StrReverse(Right(NewStr, (Len(NewStr) / 2))) NewStr = Side1 & Side2 End IfEncrypt = NewStr End Function
最后一个:'The following should be placed in a module:Public Function Rot13(ByVal j As String) As String Dim c As Byte Dim t As String t = j For i = 1 To Len(j) t = Right(t, Len(j) - i + 1) c = Asc(t) If (c > 64) And (c < 78) Then Rot13 = Rot13 + Chr(c + 13) ElseIf (c > 77) And (c < 91) Then Rot13 = Rot13 + Chr(c - 13) ElseIf (c > 96) And (c < 110) Then Rot13 = Rot13 + Chr(c + 13) ElseIf (c > 109) And (c < 123) Then Rot13 = Rot13 + Chr(c - 13) Else Rot13 = Rot13 + Chr(c) End If Next i End Function 'Example, Rot13("Ruben") will return "Ehora" 'and Rot13("Ehora") will return "Ruben". 'Could be used to scramble contents of created 'text file etc. that you want to be accessed by 'your created program only.'Created by "Ruben" <[email protected]>
英文行吗?我找了一个英文字符串加密程序:参考参考。There are many algorithms available for string encryption and decryption, but often they become complicated due to the need to ensure that the ASCII value of an encrypted character stays within the limits of a single byte (0-255). An elegant approach is to use the XOR function. The simple subroutine below will always give results falling within the 0-255 limit. It also has the advantage that a second call will reverse the encryption automatically.Function Encrypt(sPassWord As String, sText As String) As StringDim I As Integer
Dim iPChar As Integer
Dim iCChar As Integer Do While Len(sPassWord) < Len(sText) sPassWord = sPassWord & sPassWord Loop For I = 1 To Len(sText) iPChar = Asc(Mid$(sPassWord, I, 1)) Char = Asc(Mid$(sText, I, 1)) d$(sText, I, 1) = Chr$(iPChar Xor iCChar) Next I Encrypt = sTextEnd FunctionOne thing you should be aware of is that the encrypted string may contain Chr$(0) values. While this will not be a problem with Visual Basic strings, other Windows objects treat Chr$(0) as an end-of-string character. Use of the encrypted string with a Text Box or in API calls may produce unexpected results.
'Just put this in a form. And figure out how to
'call them yourself.'This is how encryption is done boys and girls.
'I'm sick of seeing posts of encryption routines
'that add and subtract to the ascii number of a
'character. It's very ineffective. Decryption
'programs can crack simple stuff like that in
'less than a second. Do it right.'Note: Don't make the key repetative in any way!Option ExplicitPrivate Function Decrypt(PlainStr As String, key As String)
Dim Char As String, KeyChar As String, NewStr As String
Dim Pos As Integer
Dim i As Integer, Side1 As String, Side2 As String
Pos = 1'This is a little trick to make it slightly harder to crack.
'However, the chances of this operation firing is 50/50
'because the length of the string must be divisable by 2.
If Len(PlainStr) Mod 2 = 0 Then
Side1 = StrReverse(Left(PlainStr, (Len(PlainStr) / 2)))
Side2 = StrReverse(Right(PlainStr, (Len(PlainStr) / 2)))
PlainStr = Side1 & Side2
End If'This loop decrypts the data.
For i = 1 To Len(PlainStr)
Char = Mid(PlainStr, i, 1)
KeyChar = Mid(key, Pos, 1)
NewStr = NewStr & Chr(Asc(Char) Xor Asc(KeyChar))
If Pos = Len(key) Then Pos = 0
Pos = Pos + 1
Next iDecrypt = NewStr
End FunctionPrivate Function Encrypt(PlainStr As String, key As String)
Dim Char As String, KeyChar As String, NewStr As String
Dim Pos As Integer
Dim i As Integer, Side1 As String, Side2 As String
Pos = 1'This loop encrypts the data.
For i = 1 To Len(PlainStr)
Char = Mid(PlainStr, i, 1)
KeyChar = Mid(key, Pos, 1)
NewStr = NewStr & Chr(Asc(Char) Xor Asc(KeyChar))
If Pos = Len(key) Then Pos = 0
Pos = Pos + 1
Next i'This is a little trick to make it slightly harder to crack.
'However, the chances of this operation firing is 50/50
'because the length of the string must be divisable by 2.
If Len(NewStr) Mod 2 = 0 Then
Side1 = StrReverse(Left(NewStr, (Len(NewStr) / 2)))
Side2 = StrReverse(Right(NewStr, (Len(NewStr) / 2)))
NewStr = Side1 & Side2
End IfEncrypt = NewStr
End Function
最后一个:'The following should be placed in a module:Public Function Rot13(ByVal j As String) As String
Dim c As Byte
Dim t As String
t = j
For i = 1 To Len(j)
t = Right(t, Len(j) - i + 1)
c = Asc(t)
If (c > 64) And (c < 78) Then
Rot13 = Rot13 + Chr(c + 13)
ElseIf (c > 77) And (c < 91) Then
Rot13 = Rot13 + Chr(c - 13)
ElseIf (c > 96) And (c < 110) Then
Rot13 = Rot13 + Chr(c + 13)
ElseIf (c > 109) And (c < 123) Then
Rot13 = Rot13 + Chr(c - 13)
Else
Rot13 = Rot13 + Chr(c)
End If
Next i
End Function 'Example, Rot13("Ruben") will return "Ehora"
'and Rot13("Ehora") will return "Ruben".
'Could be used to scramble contents of created
'text file etc. that you want to be accessed by
'your created program only.'Created by "Ruben" <[email protected]>