有谁对BASE64编码有很好的了解或者这方面的资料。
谢谢各位朋友了。
谢谢各位朋友了。
解决方案 »
- 第一段文字读取文件和显示字符正常,加了第二段后显示乱码是怎么了
- 请教COM内存管理和一些资源释放的问题
- VS2005没有了ClassWizard,我该怎样从TypeLibrary中从创建一个类?
- 关于多线程编程的问题
- 如何在打印和打印预览中加入页边距的设置??(在线等待)
- 编了怎么多年程,的出的经验:不管什么语言,主要的是核心的算法。(讨论)
- 如何设置小数点的精度,即保留几位小数?
- 关于切分窗口
- sorry,"find()库函数的问题"一文加漏分,请lanfengjiyue(一心想做程序员的歪脚鸭)接分
- 频繁调用CAsyncSocket引发的错误
- 一个api函数的用法请教?
- 如何让MSDN在VC中可用?
Public Base64 conversion tables
*/
unsigned char B64[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
unsigned char b64[256];
/*
void initb64();
Initializes the base64->base16 conversion tab.
Call this function once when your program starts
and always after your B64 table has been changed.
*/
void initb64(){
unsigned int i;
for (i=0; i<256; i++) b64[i]=0x00;
for (i=0; i<64; i++) b64[(B64[i])]=i;
}/*
int b64toh(lpBase64String, lpDestinationBuffer);
Converts base64 string b to hexnumber d.
Returns size of hexnumber in bytes.
*/
int b64toh(char *b, char *d){
int i,k,l;
l=strlen(b);
if (l<2) return 0;
for (i=l-1;i>-1;i--){
if (b64[(b[i])]==0) l--;
else break;
}
if (l<2) return 0;
i=0,k=0;
while (1) {
i++;
if (k+1<l) d[i-1]=((b64[(b[k])])<<2);
else break;
k++;
if (k<l) d[i-1]|=((b64[(b[k])])>>4);
else break;
i++;
if (k+1<l) d[i-1]=((b64[(b[k])])<<4);
else break;
k++;
if (k<l) d[i-1]|=((b64[(b[k])])>>2);
else break;
i++;
if (k+1<l) d[i-1]=((b64[(b[k])])<<6);
else break;
k++;
if (k<l) d[i-1]|=(b64[(b[k])]);
else break;
k++;
}
return i-1;
}/*
int htob64(lpHexNumber, lpDestinationBuffer);
Converts hexnumber h (with length l bytes) to base64 string d.
Returns length of base64 string.
*/
int htob64(char *h, char *d, unsigned int l){
unsigned int i,j,k;
unsigned char m,t; if (!l) return 0;
l<<=3; // no. bits
m=0x80;
for (i=0,j=0,k=0,t=0; i<l; i++){
if (h[(i>>3)]&m) t|=1;
j++;
if (!(m>>=1)) m=0x80;
if (!(j%6)) {
d[k]=B64[t];
t&=0;
k++;
}
t<<=1;
}
m=5-(j%6);
t<<=m;
if (m) {
d[k]=B64[t];
k++;
}
d[k]&=0;
return strlen(d);
}