EC62加密/解密 For ASP(VBS) 占个座位先
7 3月 2010
<!–#include file="class/md5.asp" –>
<%
Class Ec62
Private tmpString
Dim numbase
‘==类初始化及注销时的事件==
Private Sub Class_Initialize
‘On Error Resume Next
numbase="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
numbase=numbase+"abcdefghijklmnopqrstuvwxyz"
‘==62进制表==
End Sub
Private Sub Class_Terminate
End Sub
‘==将10进制数转化成62进制数==
Public Function to62scale(ByVal n)
‘On Error Resume Next
Dim re
re = ""
Do While ( n >= 62 )
re = Mid(numbase,(n Mod 62)+1,1) & re
n = n\62
Loop
re = Mid(numbase,(n Mod 62)+1,1) & re
If Err.Number Then
Response.Write((n Mod 62)+1)
Response.Write(Err.DeScription)
Response.End()
End if
re = Left("000",3-Len(re)) & re
to62scale = re
End Function
‘==将62进制数转化成10进制数==
Public Function to10scale(ByVal word)
Dim re
re = 0
re = re + ((InStr(numbase,Mid(word,1,1))-1)*3844)
re = re + ((InStr(numbase,Mid(word,2,1))-1)*62)
re = re + (InStr(numbase,Mid(word,3,1))-1)*1
to10scale = re
End Function
‘==加密函数==
Public Function EnCode(ByVal str,ByVal password)
‘On Error Resume Next
If str="" or password="" Then
EnCode = False
Exit Function
End If
Dim re,i,a,b
Dim t,tt
re = ""
For i=0 To Len(str)-1
a = AscW(Mid(str,(i+1),1))
‘————
If a<0 Then a = a + 65536
‘————
b = AscW(Mid(password,(i mod Len(password))+1,1))
If b<0 Then b = b + 65536
re = re & to62scale(a + b)
Next
re = LCase(Left(md5(password),6)) + re
EnCode = re
End Function
‘==解密函数==
Public Function DeCode(ByVal str,ByVal password)
‘On Error Resume Next
If str="" or password="" Then
DeCode = False
Exit Function
End If
if LCase(Left(md5(password),6)) <> Left(str,6) Then
DeCode = "密码错误"
Exit Function
End If
Dim re,l,i,a
re = ""
l = Len(password)
For i=6 To Len(str)-3 step 3
a = AscW(Mid(password,(((i+1)\3-2) Mod l)+1,1))
If a>255 Then a = a – 65536
re = re + chrW(to10scale(Mid(str,i+1,3)) – a)
Next
DeCode = re
End Function
Public Function EnUnicode(ByVal str)
Dim st, t, i
For i = 1 To Len(str)
t = Hex(AscW(Mid(str, i, 1)))
If (Len(t) < 4) Then
while (Len(t) < 4)
t = "0" & t
Wend
End If
t = Mid(t, 3) & Left(t, 2)
st = st & t
Next
EnUnicode = st
End Function
Public Function DeUnicode(ByVal str)
Dim st, t, i
For i = 1 To Len(str)/4
t = Mid(str, 4*i-3, 4)
t = Mid(t, 3) & Left(t, 2)
t = ChrW(Hex2Dec(t))
st = st & t
Next
DeUnicode = st
End Function
Public Function Hex2Dec(ByVal str)
Dim i, j, k, result
result = 0
For i = 1 To Len(str)
Select Case Mid(str, i, 1)
Case "F": j = 15
Case "E": j = 14
Case "D": j = 13
Case "C": j = 12
Case "B": j = 11
Case "A": j = 10
Case Else: If Mid(str, i, 1) <= "9" And Mid(str, i, 1) >= "0" Then j = CInt(Mid(str, i, 1))
End Select
For k = 1 To Len(str) – i
j = j * 16
Next
result = result + j
Next
Hex2Dec = result
End Function
End Class
Sub TestClass()
Dim tEc62
Dim PassWord
Dim Content ‘//源文本内容
Dim pwdContent ‘//加密后的内容
Dim repwdContet ‘//解密后的内容
Set tec62 = new ec62
Content = "codes|" ‘//内容
PassWord ="1111aaaaaaaaaaaaaaa" ‘//密码
pwdContent = tec62.EnCode(Content,PassWord) ‘//加密码内容
repwdContet = tec62.DeCode(pwdContent,PassWord)’//解密内容
Response.Write("<br /><br /><b>源文件内容:</b><hr size=""1"" />" & Content)
Response.Write("<br /><br /><b>加密后的内容:</b><hr size=""1"" />" & pwdContent)
Response.Write("<br /><br /><b>解密后的内容:</b><hr size=""1"" />" & repwdContet)
Response.Write "<br>"
End Sub
Call TestClass()
%>
More from my site
- No Comments , 8,379 views Hits
近期评论