- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
long base64::rlong (char * source)
{
long res = 0;
for (int i = 0; i < 4; i++) ((char *) &res)[3 - i] = source[i];
return res;
}
void base64::encode (char * source, char * dest)
{
char base[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int n = 0;
for (int nd = 0; nd < ceil(4*((double)strlen(source))/3); nd++)
dest[n++] = base[rlong(&source[((nd >> 2) << 2)*3 >> 2]) >> (26 - 6*(nd - ((nd >> 2) << 2))) & 0x3F];
for (int i = 0; i < ((int) ceil(((double)n)/4) << 2) - n; i++) dest[n++] = '=';
dest[n] = 0;
}
Ответ преподу по c++. Переводстроки в base64.