none
以下这段代码功能是什么 RRS feed

  • 问题

  • static int _EncodeBase64(const unsigned char* pSrc, char* pDst, int nSrcLen)
    {
    char EnBase64Tab[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    unsigned char c1, c2, c3;
        int nDstLen = 0;
        int nLineLen = 0;
        int nDiv = nSrcLen / 3;/////////////////////这句是什么原理
        int nMod = nSrcLen % 3;//////////////////这句是什么原理
     
        for (int i = 0; i < nDiv; i ++)//////////////////////////////一下这些语句具体什么原理实现什么功能
        {
            c1 = *pSrc++;
            c2 = *pSrc++;
            c3 = *pSrc++;
            *pDst++ = EnBase64Tab[c1 >> 2];
            *pDst++ = EnBase64Tab[((c1 << 4) | (c2 >> 4)) & 0x3f];
            *pDst++ = EnBase64Tab[((c2 << 2) | (c3 >> 6)) & 0x3f];
            *pDst++ = EnBase64Tab[c3 & 0x3f];
            nLineLen += 4;
            nDstLen += 4;
        }
        if (nMod == 1)
        {
            c1 = *pSrc++;
            *pDst++ = EnBase64Tab[(c1 & 0xfc) >> 2];
            *pDst++ = EnBase64Tab[((c1 & 0x03) << 4)];
            *pDst++ = '=';
            *pDst++ = '=';
            nLineLen += 4;
            nDstLen += 4;
        }
        else if (nMod == 2)
        {
            c1 = *pSrc++;
            c2 = *pSrc++;
            *pDst++ = EnBase64Tab[(c1 & 0xfc) >> 2];
            *pDst++ = EnBase64Tab[((c1 & 0x03) << 4) | ((c2 & 0xf0) >> 4)];
            *pDst++ = EnBase64Tab[((c2 & 0x0f) << 2)];
            *pDst++ = '=';
            nDstLen += 4;
        }
        *pDst = '\0';
        return nDstLen;

    }
    2013年3月22日 1:59

答案