| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 787 人关注过本帖
标题:求VC++ unescape
只看楼主 加入收藏
bugtosafe
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-11-29
收藏
 问题点数:0 回复次数:1 
求VC++ unescape
求VC++ unescape 解密
搜索更多相关主题的帖子: unescape 
2010-11-29 00:09
bugtosafe
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-11-29
收藏
得分:0 
//url.h
class   URL   
{
public:
        static   string   escape(const   string&   unes);
        static   string   unEscape(const   string&   esc);
        static   string   unEscape(const   char*   esc);
        static   bool   isAcceptable(unsigned   char   cx);

protected:
        static   const   char   hex[];
        static   const   unsigned   char   acceptMask[];
        static   const   unsigned   int   XALPHAS;

};

//url.cpp

#include   "url.h "
//////////////////////////////////////////////////////////////////////
const   unsigned   int     URL::XALPHAS   =   0x1;
const   char                     URL::hex[]   =   "0123456789ABCDEF ";
const   unsigned   char   URL::acceptMask[]   =
{
        /*   0x0   0x1   0x2   0x3   0x4   0x5   0x6   0x7   0x8   0x9   0xA   0xB   0xC   0xD   0xE   0xF   */
        0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xF,0xE,0x0,0xF,0xF,0xC,
        /*   2x     ! "#$%& '()*+,-./     */
        0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0x8,0x0,0x0,0x0,0x0,0x0,
        /*   3x   0123456789:<=> ?     */
        0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,
        /*   4x   @ABCDEFGHIJKLMNO     */
        0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0x0,0x0,0x0,0x0,0xF,
        /*   5X   PQRSTUVWXYZ[\]^_     */
        0x0,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,
        /*   6x   `abcdefghijklmno     */
        0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0xF,0x0,0x0,0x0,0x0,0x0
            /*   7X   pqrstuvwxyz{\}~DEL   */
};
bool   URL::isAcceptable(unsigned   char   cx)
{
        if   (cx   ==   '/ ')   return   true;
        return   (cx   > =   32)   &&   (cx   <   128)   &&   ((acceptMask[cx   -   32])   &   XALPHAS);
}

string   URL::escape(const   string&   str)
{
        string     result;

        if   (str.empty())   return   result;
        for   (unsigned   int   i   =   0;   i   <   str.size();   i++)
        {
                unsigned   char       a   =   (unsigned   char)   (str[i]);
                if   (!isAcceptable(a))
                {
                        result   +=   "% ";
                        result   +=   hex[a   > >   4];
                        result   +=   hex[a   &   15];
                }
                else
                {
                        result   +=   str[i];
                }
        }

        return   result;
}
string   URL::unEscape(const   char*   lpBuf)
{
int   nLen;
if(!lpBuf) nLen=0;
else nLen=::lstrlen(lpBuf);

string   s;
int   i=0;
while(i <nLen)
{
if(lpBuf[i]== '% ')
{
BYTE   c1=lpBuf[i+1];
BYTE   c2=lpBuf[i+2];
i+=2;
if(c1> = '0 '   &&   c1 <= '9 ') c1=(c1- '0 ')*16;
else   if(c1> = 'A '   &&   c1 <= 'Z ') c1=(c1- 'A '+10)*16;
else   if(c1> = 'a '   &&   c1 <= 'a ')   c1=(c1- 'a '+10)*16;
if(c2> = '0 '   &&   c2 <= '9 ') c2=c2- '0 ';
else   if(c2> = 'A '   &&   c2 <= 'Z ') c2=c2- 'A '+10;
else   if(c2> = 'a '   &&   c2 <= 'z ') c2=c2- 'a '+10;

char   szStr[2]; szStr[0]=c1+c2; szStr[1]=0;
s+=szStr;
}
else   if(lpBuf[i]== '+ ') s+= "   ";
else   s.append(lpBuf   +   i,   1);
i++;
}
return   s;
}
2010-11-29 00:31
快速回复:求VC++ unescape
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015840 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved