类型:转载 责任编辑:asp.net 日期:2007/05/23
热门软件下载:
如何对任意字符文本进行加密,包括文本与标点字母大小写等内容符号,还原时再还原为原来内容,
网友回答:
加密字符串算法
作者:junk.Damage.Case
This is an example of REAL encryption. Not that ASCII addition/subtraction junk.Damage.Case http://www.alchemydev.com/
Just put this in a form. And figure out how to
call them yourself.
This is how encryption is done boys and girls.
Im sick of seeing posts of encryption routines
that add and subtract to the ascii number of a
character. Its very ineffective. Decryption
programs can crack simple stuff like that in
less than a second. Do it right.
Note: Dont make the key repetative in any way!
Option Explicit
Private 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 i
Decrypt = NewStr
End Function
Private 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 If
Encrypt = NewStr
End Function