快速搜索
[登录]
[注册]
迷你相册
论坛
标签
搜索
帮助
迷你论坛
»
技术带动变革
»
手机开发综合
»
C++的Base64编码源代码
技术带动变革
魅族M8交流专版
手机开发综合
Mini开发技术综合区
Android研究学院
Mini软件专区
快乐的旅程
游戏综合区
Mini大嘴巴
议事大厅
大厅综合管理处
小7的大店铺【淘宝店】
游戏引擎剖析-全篇
公积金相关帖子汇总
魅族M8SDK学习系列不断更新中
[C\C++]
C++的Base64编码源代码
[
2070
查看 /
3
回复 ]
返回列表
发送短消息
UID
1
精华
75
5207.com@163.com
89387228
查看公共资料
搜索帖子
5207
组别
皇帝
生日
1983-12-1
帖子
1533
积分
2002
生命值
94
钱
3675.8 M
性别
相册
5207
2009-06-26 20:35
|
只看楼主
发表者
字体大小:
t
T
/************************************************
头文件ZBase64.h
************************************************/
#ifndef _ZBASE64
#define _ZBASE64
#pragma warning(disable:4786)
#include
using namespace std;
class ZBase64
{
private:
//Base64编码解码表
char* m_Base64_Table;
public:
//构造
ZBase64();
//编码
string EncodeBase64(const string strSource);
//解码
string DecodeBase64(const string strSource);
};
#endif
复制代码
/************************************************
实现文件ZBase64.cpp
************************************************/
#include "stdAfx.h"
#include "Base64.h"
ZBase64::ZBase64()
{
//Base64编码表
this->m_Base64_Table="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
}
string ZBase64::EncodeBase64(const string strSource)
{
/*
* 以下是操作二进制数时用到的
* 11111100 0xFC
* 11000000 0x3
* 11110000 0xF0
* 00001111 0xF
* 11000000 0xC0
* 00111111 0x3F
*/
string strEncode;
char cTemp[4];
//行长,MIME规定Base64编码行长为76字节
int LineLength=0;
for(int i=0;i
{
memset(cTemp,0,4);
cTemp[0]=strSource[i];
cTemp[1]=strSource[i+1];
cTemp[2]=strSource[i+2];
int len=strlen(cTemp);
if(len==3)
{
strEncode+=this->m_Base64_Table[((int)cTemp[0] & 0xFC)>>2];
strEncode+=this->m_Base64_Table[((int)cTemp[0] & 0x3)<<4 | ((int)cTemp[1] & 0xF0)>>4];
strEncode+=this->m_Base64_Table[((int)cTemp[1] & 0xF)<<2 | ((int)cTemp[2] & 0xC0)>>6];
strEncode+=this->m_Base64_Table[(int)cTemp[2] & 0x3F];
if(LineLength+=4>=76) strEncode+="\r\n";
}
else if(len==2)
{
strEncode+=this->m_Base64_Table[((int)cTemp[0] & 0xFC)>>2];
strEncode+=this->m_Base64_Table[((int)cTemp[0] & 0x3 )<<4 | ((int)cTemp[1] & 0xF0 )>>4];
strEncode+=this->m_Base64_Table[((int)cTemp[1] & 0x0F)<<2];
if(LineLength+=4>=76) strEncode+="\r\n";
strEncode+="=";
}
else if(len==1)
{
strEncode+=this->m_Base64_Table[((int)cTemp[0] & 0xFC)>>2];
strEncode+=this->m_Base64_Table[((int)cTemp[0] & 0x3 )<<4];
if(LineLength+=4>=76) strEncode+="\r\n";
strEncode+="==";
}
memset(cTemp,0,4);
}
return strEncode;
}
string ZBase64::DecodeBase64(const string strSource)
{
//返回值
string strDecode;
char cTemp[5];
for(int i=0;i
{
memset(cTemp,0,5);
cTemp[0]=strSource[i];
cTemp[1]=strSource[i+1];
cTemp[2]=strSource[i+2];
cTemp[3]=strSource[i+3];
int asc[4];
for(int j=0;j<4;j++)
{
for(int k=0;k<(int)strlen(this->m_Base64_Table);k++)
{
if(cTemp[j]==this->m_Base64_Table[k]) asc[j]=k;
}
}
if('='==cTemp[2] && '='==cTemp[3])
{
strDecode+=(char)(int)(asc[0] << 2 | asc[1] << 2 >> 6);
}
else if('='==cTemp[3])
{
strDecode+=(char)(int)(asc[0] << 2 | asc[1] << 2 >> 6);
strDecode+=(char)(int)(asc[1] << 4 | asc[2] << 2 >> 4);
}
else
{
strDecode+=(char)(int)(asc[0] << 2 | asc[1] << 2 >> 6);
strDecode+=(char)(int)(asc[1] << 4 | asc[2] << 2 >> 4);
strDecode+=(char)(int)(asc[2] << 6 | asc[3] << 2 >> 2);
}
}
return strDecode;
}
复制代码
本主题由
皇帝
5207 于 2009-6-26 20:37:16 执行 设置精华/取消 操作
分享
转发
相信与不相信都是矛盾的. 5207宣!
欢迎您来到
迷你论坛
TOP
120.28.64.*
未注册
游客
2009-11-15 22:43
沙发
字体大小:
t
T
XyLNnAPqgvdZofOJjs
http://microsoftontheissues.com/cs/members/insomnia-and-getting-back-to-sleep-routine.aspx
insomnia and getting back to sleep routine | <a href="http://microsoftontheissues.com/cs/members/insomnia-and-getting-back-to-sleep-routine.aspx"> insomnia and getting back to sleep routine </a>
http://microsoftontheissues.com/cs/members/levitra-masturbation.aspx
levitra masturbation | <a href="http://microsoftontheissues.com/cs/members/levitra-masturbation.aspx"> levitra masturbation </a>
http://microsoftontheissues.com/cs/members/estradiol-vaginal-tablets.aspx
estradiol vaginal tablets | <a href="http://microsoftontheissues.com/cs/members/estradiol-vaginal-tablets.aspx"> estradiol vaginal tablets </a>
http://microsoftontheissues.com/cs/members/levitra-acquisto.aspx
levitra acquisto | <a href="http://microsoftontheissues.com/cs/members/levitra-acquisto.aspx"> levitra acquisto </a>
http://microsoftontheissues.com/cs/members/amoxicillin-alcohol.aspx
amoxicillin alcohol | <a href="http://microsoftontheissues.com/cs/members/amoxicillin-alcohol.aspx"> amoxicillin alcohol </a>
http://microsoftontheissues.com/cs/members/fluoxetine-biopharmaceutic-biowaiver.aspx
fluoxetine biopharmaceutic biowaiver | <a href="http://microsoftontheissues.com/cs/members/fluoxetine-biopharmaceutic-biowaiver.aspx"> fluoxetine biopharmaceutic biowaiver </a>
http://microsoftontheissues.com/cs/members/glucosamine-side-effects-and-rash.aspx
glucosamine side effects and rash | <a href="http://microsoftontheissues.com/cs/members/glucosamine-side-effects-and-rash.aspx"> glucosamine side effects and rash </a>
http://microsoftontheissues.com/cs/members/acetaminophen-ibuprofen.aspx
acetaminophen ibuprofen | <a href="http://microsoftontheissues.com/cs/members/acetaminophen-ibuprofen.aspx"> acetaminophen ibuprofen </a>
http://microsoftontheissues.com/cs/members/erythromycin-antibiotic-without-a-prescription.aspx
erythromycin antibiotic without a prescription | <a href="http://microsoftontheissues.com/cs/members/erythromycin-antibiotic-without-a-prescription.aspx"> erythromycin antibiotic without a prescription </a>
http://microsoftontheissues.com/cs/members/doxycycline-and-weight-gain.aspx
doxycycline and weight gain | <a href="http://microsoftontheissues.com/cs/members/doxycycline-and-weight-gain.aspx"> doxycycline and weight gain </a>
http://microsoftontheissues.com/cs/members/compatibility-for-darvocet-and-motrin.aspx
compatibility for darvocet and motrin | <a href="http://microsoftontheissues.com/cs/members/compatibility-for-darvocet-and-motrin.aspx"> compatibility for darvocet and motrin </a>
http://microsoftontheissues.com/cs/members/insomnia-relief.aspx
insomnia relief | <a href="http://microsoftontheissues.com/cs/members/insomnia-relief.aspx"> insomnia relief </a>
http://microsoftontheissues.com/cs/members/aspirin-for-horses.aspx
aspirin for horses | <a href="http://microsoftontheissues.com/cs/members/aspirin-for-horses.aspx"> aspirin for horses </a>
http://microsoftontheissues.com/cs/members/erythromycin-ointment.aspx
erythromycin ointment | <a href="http://microsoftontheissues.com/cs/members/erythromycin-ointment.aspx"> erythromycin ointment </a>
http://microsoftontheissues.com/cs/members/diflucan-150mg-no-prescription.aspx
diflucan 150mg no prescription | <a href="http://microsoftontheissues.com/cs/members/diflucan-150mg-no-prescription.aspx"> diflucan 150mg no prescription </a>
http://microsoftontheissues.com/cs/members/what-is-hydrocodone-gg-syrup-used-for.aspx
what is hydrocodone gg syrup used for | <a href="http://microsoftontheissues.com/cs/members/what-is-hydrocodone-gg-syrup-used-for.aspx"> what is hydrocodone gg syrup used for </a>
http://microsoftontheissues.com/cs/members/levitra-senza-ricetta.aspx
levitra senza ricetta | <a href="http://microsoftontheissues.com/cs/members/levitra-senza-ricetta.aspx"> levitra senza ricetta </a>
http://microsoftontheissues.com/cs/members/what-is-tramadol.aspx
what is tramadol | <a href="http://microsoftontheissues.com/cs/members/what-is-tramadol.aspx"> what is tramadol </a>
http://microsoftontheissues.com/cs/members/what-is-erythromycin-used-for.aspx
what is erythromycin used for | <a href="http://microsoftontheissues.com/cs/members/what-is-erythromycin-used-for.aspx"> what is erythromycin used for </a>
http://microsoftontheissues.com/cs/members/how-adipex-works.aspx
how adipex works | <a href="http://microsoftontheissues.com/cs/members/how-adipex-works.aspx"> how adipex works </a>
http://microsoftontheissues.com/cs/members/ambien-and-fluoxetine.aspx
ambien and fluoxetine | <a href="http://microsoftontheissues.com/cs/members/ambien-and-fluoxetine.aspx"> ambien and fluoxetine </a>
http://microsoftontheissues.com/cs/members/side-effects-tramadol.aspx
side effects tramadol | <a href="http://microsoftontheissues.com/cs/members/side-effects-tramadol.aspx"> side effects tramadol </a>
http://microsoftontheissues.com/cs/members/adrenal-stress-insomnia.aspx
adrenal stress insomnia | <a href="http://microsoftontheissues.com/cs/members/adrenal-stress-insomnia.aspx"> adrenal stress insomnia </a>
http://microsoftontheissues.com/cs/members/albuterol-dexamethasone-nebulizer.aspx
albuterol dexamethasone nebulizer | <a href="http://microsoftontheissues.com/cs/members/albuterol-dexamethasone-nebulizer.aspx"> albuterol dexamethasone nebulizer </a>
http://microsoftontheissues.com/cs/members/ambien-effectiveness.aspx
ambien effectiveness | <a href="http://microsoftontheissues.com/cs/members/ambien-effectiveness.aspx"> ambien effectiveness </a>
http://microsoftontheissues.com/cs/members/allegra-erika.aspx
allegra erika | <a href="http://microsoftontheissues.com/cs/members/allegra-erika.aspx"> allegra erika </a>
http://microsoftontheissues.com/cs/members/atenolol-mexico.aspx
atenolol mexico | <a href="http://microsoftontheissues.com/cs/members/atenolol-mexico.aspx"> atenolol mexico </a>
http://microsoftontheissues.com/cs/members/atenolol-stage-freight.aspx
atenolol stage freight | <a href="http://microsoftontheissues.com/cs/members/atenolol-stage-freight.aspx"> atenolol stage freight </a>
http://microsoftontheissues.com/cs/members/applying-androgel-cream-to-the-scrotum.aspx
applying androgel cream to the scrotum | <a href="http://microsoftontheissues.com/cs/members/applying-androgel-cream-to-the-scrotum.aspx"> applying androgel cream to the scrotum </a>
http://microsoftontheissues.com/cs/members/buy-ambien-online.aspx
buy ambien online | <a href="http://microsoftontheissues.com/cs/members/buy-ambien-online.aspx"> buy ambien online </a>
TOP
发送短消息
UID
1
精华
75
5207.com@163.com
89387228
查看公共资料
搜索帖子
5207
组别
皇帝
生日
1983-12-1
帖子
1533
积分
2002
生命值
94
钱
3675.8 M
性别
相册
5207
2009-11-15 22:45
|
只看楼主
凳子
字体大小:
t
T
回复 2# 游客 的帖子
发的是什么?
相信与不相信都是矛盾的. 5207宣!
欢迎您来到
迷你论坛
TOP
发送短消息
UID
629
精华
0
查看公共资料
搜索帖子
leipuo123
组别
家里有一头猪
生日
帖子
12
积分
12
生命值
0
钱
7.5 M
性别
相册
leipuo123
2010-03-01 22:09
|
只看该用户
地板
字体大小:
t
T
g广告吧?
TOP
返回列表
上一主题
|
下一主题
发新主题
技术带动变革
魅族M8交流专版
手机开发综合
Mini开发技术综合区
Android研究学院
Mini软件专区
快乐的旅程
游戏综合区
Mini大嘴巴
议事大厅
大厅综合管理处
魅族M8交流专版
游戏综合区
Mini开发技术综合区
帖子标题
相册标题
作者
版块
我的资料
default