m_len = s.Length(); //取得字符串长度
m_s = s.c_str();
m_64code=""; //返回串置空
//处理3的倍数以内的字符
for(i=0;i m_tmp=m_s[i]/4; m_64code+=m_64[m_tmp]; m_tmp=m_s[i]%4*16 + m_s[i+1]/16; m_64code+=m_64[m_tmp]; m_tmp=m_s[i+1]%16*4 + m_s[i+2]/64; m_64code+=m_64[m_tmp]; m_tmp=m_s[i+2]%64; m_64code+=m_64[m_tmp]; } //如果字符串的长度被3除余2 ,不足的位数补0,尾部补“=” if(m_len%3==2){ m_64code+=m_64[m_tmp]; m_tmp=m_s[m_len-2]%4*16+m_s[m_len-1]/16; m_64code+=m_64[m_tmp]; m_tmp=m_s[m_len-1]%16*4; m_64code+=m_64[m_tmp]; m_64code+==; } //如果字符串的长度被3除余1 ,不足的位数补0,尾部补两个“=” if(m_len%3==1){ m_tmp=m_s[m_len-1]/4; m_64code+=m_64[m_tmp]; m_tmp=m_s[m_len-1]%4*16; m_64code+=m_64[m_tmp]; m_64code+="=="; } return m_64code; } 本程序在Windows 2000环境下使用Borland C++ Builder 6.0编写及调试的,分别使用网易和新浪邮箱做实验,都可以顺利完成身份认证以及邮件发送功能。
m_tmp=m_s[m_len-2]/4;
结束语