首页 电脑 电脑学堂 查看内容

urldecode 方法补遗

2004-11-4 13:25 589 0

摘要: asp 里面没有urldecode函数,好象aspx里有吧,我不太清楚,但asp里面还是用得很多。在网上查找了有别人写的urldecode函数,但是这个函数有错误,而且在一些方面写得比较难理解。而...
关键词: urldecode isvalidhex 函数 enStr 里面 错误 太清 字节 false Function

asp 里面没有urldecode函数,好象aspx里有吧,我不太清楚,但asp里面还是用得很多。在网上查找了有别人写的urldecode函数,但是这个函数有错误,而且在一些方面写得比较难理解。而且有错误,当里面有生僻双字节文字时就会产生错误,如"乄"经urlencoder后为"%81W",解码就不能成功。 其实双字节编码在这里只要把"W"也编成16进制ASC码就可以。 知识点:计算机里的cookie也是经过urlencode编码的,所以urldecode对破解cookie也很有用呵。 下面是源代码: Function URLDecode(enStr)dim deStrdim c,i,vdeStr=""for i=1 to len(enStr)c=Mid(enStr,i,1)if c="%" thenv=eval("&h"+Mid(enStr,i+1,2))if v<128 thendeStr=deStr&chr(v)i=i+2else  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&chr(v)        i=i+5      else        v=eval("&h"+Mid(enStr,i+1,2)+cstr(hex(asc(Mid(enStr,i+3,1)))))        deStr=deStr&chr(v)        i=i+3       end if    else    destr=destr&c  end ifend ifelseif c="+" thendeStr=deStr&" "elsedeStr=deStr&cend ifend ifnextURLDecode=deStrend function function isvalidhex(str)isvalidhex=truestr=ucase(str)if len(str)<>3 then isvalidhex=false:exit functionif left(str,1)<>"%" then isvalidhex=false:exit functionc=mid(str,2,1)if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit functionc=mid(str,3,1)if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit functionend function 你用此方法解码"%81W"看看,可以了。 当然,你还可以玩点小段,使之成为自己的一种字符串加密方式。  
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部