- #include <stdio.h>
- #include <string.h>
-
- const char alfa[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- const unsigned char dloc[] = {0x54, 0x31, 0x6B, 0x72, 0x63, 0x6C, 0x55, 0x78, 0x62, 0x46, 0x55, 0x72, 0x63, 0x42, 0x41, 0x6F, 0x62, 0x78, 0x41, 0x30, 0x61, 0x6C, 0x55, 0x6A, 0x63, 0x56, 0x4D, 0x67, 0x63, 0x46, 0x55, 0x6A, 0x48, 0x46, 0x45, 0x78, 0x62, 0x6C, 0x38, 0x6D, 0x58, 0x56, 0x34, 0x2F, 0x48, 0x46, 0x6B, 0x6A, 0x60, 0x56, 0x38, 0x2F, 0x48, 0x43, 0x6E, 0x6F};
-
- int Decode(unsigned char* csDestination, const unsigned char* csSource, int iSourceLen);
- bool IsThisOurFormat(char c);
-
- int main()
- {
- unsigned char msg[256];
- Decode(msg, dloc, sizeof(dloc));
- printf((char*)&msg);
- return 0;
- }
-
- inline bool IsThisOurFormat(char c)
- {
- return (c && (strchr(alfa, c) != 0));
- }
-
- inline char Value(char c)
- {
- const char* p = strchr(alfa, c + 1);
-
- if (p)
- return (p - alfa);
- else
- return 0;
- }
-
- int Decode(unsigned char* csDestination, const unsigned char* csSource, int iSourceLen)
- {
- unsigned char* p = csDestination;
- if (*csSource == 0)
- return 0;
-
- *csDestination = 0;
-
- do
- {
- char a = Value(csSource[0]);
- char b = Value(csSource[1]);
- char c = Value(csSource[2]);
- char d = Value(csSource[3]);
- *p++ = (a << 2) | (b >> 4);
- *p++ = (b << 4) | (c >> 2);
- *p++ = (c << 6) | d;
-
- if (!IsThisOurFormat(csSource[1]))
- {
- p -= 2;
- break;
- }
- else if (!IsThisOurFormat(csSource[2]))
- {
- p -= 2;
- break;
- }
- else if (!IsThisOurFormat(csSource[3]))
- {
- p--;
- break;
- }
-
- csSource += 4;
-
- while (*csSource && ((*csSource == 13) || (*csSource == 10)))
- ++csSource;
- }
- while (iSourceLen -= 4);
-
- *p = 0;
- return (p - csDestination);
- }