Base64Encode编码函数(另一个)
来源:互联网 发布:财务结算中心知乎 编辑:程序博客网 时间:2024/06/02 07:31
昨天测试程序时发现 我的Base64Encode编码函数对, 返回值只8位,今天有搞了一个,完全正确.
CString CSMTP::Base64encode( CString in_str )
{
const CString _base64_encode_chars=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
CString out_str;
unsigned char c1, c2, c3;
int i = 0;
int len = in_str.GetLength();
while ( i<len )
{
// read the first byte
c1 = in_str[i++];
if ( i==len ) // pad with "="
{
out_str += _base64_encode_chars[ c1>>2 ];
out_str += _base64_encode_chars[ (c1&0x3)<<4 ];
out_str += "==";
break;
}
// read the second byte
c2 = in_str[i++];
if ( i==len ) // pad with "="
{
out_str += _base64_encode_chars[ c1>>2 ];
out_str += _base64_encode_chars[ ((c1&0x3)<<4) | ((c2&0xF0)>>4) ];
out_str += _base64_encode_chars[ (c2&0xF)<<2 ];
out_str += "=";
break;
}
// read the third byte
c3 = in_str[i++];
// convert into four bytes string
out_str += _base64_encode_chars[ c1>>2 ];
out_str += _base64_encode_chars[ ((c1&0x3)<<4) | ((c2&0xF0)>>4) ];
out_str += _base64_encode_chars[ ((c2&0xF)<<2) | ((c3&0xC0)>>6) ];
out_str += _base64_encode_chars[ c3&0x3F ];
}
return out_str;
}
- Base64Encode编码函数(另一个)
- Base64Encode编码函数
- BASE64编码与解码(Base64Encode,Base64Decode)
- javascript下base64Encode编码,支…
- 另一个视角解读计算机编码-补码编码
- 另一个视角解读计算机编码-补码编码
- 另一个视角解读计算机编码-补码编码
- 另一个视角解读计算机编码-补码编码
- 另一个视角解读计算机编码-补码编码
- 另一个视角解读计算机编码-补码编码
- 另一个视角解读计算机编码-补码编码
- 另一个视角解读计算机编码-补码编码
- 另一个视角解读计算机编码-补码编码
- 另一个视角解读计算机编码-补码编码
- 另一个视角解读计算机编码-补码编码
- Base64Encode With 12Bits-CoderTable
- c# 加密与解密 Base64Encode
- js函数作为另一个函数的参数
- 找工作(一)
- 通过串口收发短消息(上)
- 通过串口收发短消息(下)
- 写给WEB2.0的站长 不仅仅是泼冷水(转)
- 多线程概述
- Base64Encode编码函数(另一个)
- 理解SetWindowOrg,SetViewportOrg,SetWindowExt,SetViewportExt
- LPC 2368 Uart printf scanf 实现
- 第三次作业
- Java 网络编程
- Chinese Dragon
- 一些感想
- 子网划分(subnetting)的优点
- Measure-Command 帮助信息