Encrypt and Decrypt with Classic ASP
Encrypt and Decrypt with Classic ASP
|
' USE:
sField = Decode(request.querystring(encode("sParm"))) Function Decode(sIn) dim
x, y, abfrom, abto Decode="":
ABFrom = "" For x
= 0 To 25: ABFrom = ABFrom & Chr(65 + x): Next For x
= 0 To 25: ABFrom = ABFrom & Chr(97 + x): Next For x
= 0 To 9: ABFrom = ABFrom & CStr(x): Next abto
= Mid(abfrom, 14, Len(abfrom) - 13) & Left(abfrom, 13) For x=1
to Len(sin): y=InStr(abto, Mid(sin, x, 1)) If y
= 0 then Decode
= Decode & Mid(sin, x, 1) Else Decode
= Decode & Mid(abfrom, y, 1) End If Next End Function ' USE: location.href="nextpage.asp?"
& encode("sParm=" & sData) Function Encode(sIn) dim
x, y, abfrom, abto Encode="":
ABFrom = "" For x
= 0 To 25: ABFrom = ABFrom & Chr(65 + x): Next For x
= 0 To 25: ABFrom = ABFrom & Chr(97 + x): Next For x
= 0 To 9: ABFrom = ABFrom & CStr(x): Next abto
= Mid(abfrom, 14, Len(abfrom) - 13) & Left(abfrom, 13) For x=1
to Len(sin): y = InStr(abfrom, Mid(sin, x, 1)) If y
= 0 Then Encode
= Encode & Mid(sin, x, 1) Else Encode
= Encode & Mid(abto, y, 1) End If Next End Function |
' Encrypt and decrypt functions for
classic ASP (by TFI)
'********* set a random string with
random length ***********
cryptkey =
"GNQ?4i0-*\CldnU+[vrF1j1PcWeJfVv4QGBurFK6}*l[H1S:oY\v@U?i,oD]f/n8oFk6NesH--^PJeCLdp+(t8SVe:ewY(wR9p-CzG<,Q/(U*.pXDiz/KvnXP`BXnkgfeycb)1A4XKAa-2G}74Z8CqZ*A0P8E[S`6RfLwW+Pc}13U}_y0bfscJ<vkA[JC;0mEEuY4Q,([U*XRR}lYTE7A(O8KiF8>W/m1D*YoAlkBK@`3A)trZsO5xv@5@MRRFkt\"
'**** ENCRYPT
FUNCTION *****
'*** Note: bytes 255 and 0 are converted
into the same character, in order to
'*** avoid a char 0 which would
terminate the string
function encrypt(inputstr)
Dim i,x
outputstr=""
cc=0
for i=1 to len(inputstr)
x=asc(mid(inputstr,i,1))
x=x-48
if x<0 then x=x+255
x=x+asc(mid(cryptkey,cc+1,1))
if x>255 then x=x-255
outputstr=outputstr&chr(x)
cc=(cc+1) mod len(cryptkey)
next
encrypt=server.urlencode(replace(outputstr,"%","%25"))
end function
'****** DECRYPT
FUNCTION *******
function decrypt(byval inputstr)
Dim i,x
inputstr=urldecode(inputstr)
outputstr=""
cc=0
for i=1 to len(inputstr)
x=asc(mid(inputstr,i,1))
x=x-asc(mid(cryptkey,cc+1,1))
if x<0 then x=x+255
x=x+48
if x>255 then x=x-255
outputstr=outputstr&chr(x)
cc=(cc+1) mod len(cryptkey)
next
decrypt=outputstr
end function
'******************************************
Function URLDecode(sConvert)
Dim aSplit
Dim sOutput
Dim I
If IsNull(sConvert) Then
URLDecode = ""
Exit Function
End If
'sOutput = REPLACE(sConvert, "+", " ") ' convert all
pluses to spaces
sOutput=sConvert
aSplit = Split(sOutput, "%") ' next convert %hexdigits to the
character
If IsArray(aSplit) Then
sOutput = aSplit(0)
For I = 0 to UBound(aSplit) - 1
sOutput = sOutput &
Chr("&H" & Left(aSplit(i + 1), 2)) &
Right(aSplit(i + 1), Len(aSplit(i + 1)) - 2)
Next
End If
URLDecode = sOutput
End Function
Comments
Post a Comment