ASP Learning: An addendum to the UrlDecode method

Source: Internet
Author: User
Tags exit chr eval

ASP inside there is no urldecode function, as if ASPX have it, I am not clear, but the ASP inside or use a lot. I looked up the UrlDecode function written by someone else on the internet, but the function was wrong, and in some ways it was hard to understand. And there are errors, when there are obscure double-byte text will produce errors, such as "乄" after the Urlencoder "%81w", decoding can not be successful.

In fact, two-byte code here as long as the "W" also into 16 into the ASC code can be.

Knowledge Point: The cookie in the computer is also urlencode encoded, so UrlDecode is also useful for cracking cookies.

The following is the source code:

Function UrlDecode (ENSTR)
Dim destr
Dim c,i,v
Destr= ""
For I=1 to Len (ENSTR)
C=mid (enstr,i,1)
If c= "%" then
V=eval ("&h" +mid (enstr,i+1,2))
If v<128 Then
DESTR=DESTR&AMP;CHR (v)
I=i+2
Else
If Isvalidhex (Mid (enstr,i,3)) Then
If Isvalidhex (Mid (enstr,i+3,3)) Then
V=eval ("&h" +mid (enstr,i+1,2) +mid (enstr,i+4,2))
DESTR=DESTR&AMP;CHR (v)
I=i+5
Else
V=eval ("&h" +mid (enstr,i+1,2) +cstr (Hex (ASC (enstr,i+3,1)))
DESTR=DESTR&AMP;CHR (v)
I=i+3
End If
Else
Destr=destr&c
End If
End If
Else
If c= "+" then
destr=destr& ""
Else
Destr=destr&c
End If
End If
Next
Urldecode=destr
End Function
function Isvalidhex (str)
Isvalidhex=true
Str=ucase (str)
If Len (str) <>3 then Isvalidhex=false:exit function
If left (str,1) <> "%" then Isvalidhex=false:exit function
C=mid (str,2,1)
If not ((c>= "0") and (c<= "9")) or ((c>= "A") and (c<= "Z")) then Isvalidhex=false:exit function
C=mid (str,3,1)
If not ((c>= "0") and (c<= "9")) or ((c>= "A") and (c<= "Z")) then Isvalidhex=false:exit function
End Function

You use this method to decode "%81w" look, it's OK.

Of course, you can also play a little bit, make it a string encryption of their own way.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.