Snippet content copied to clipboard.
Are you sure to delete this snippet? No, don't delete
  1. #include <stdio.h>
  2. #include <string.h>
  3. const char alfa[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  4. 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};
  5. int Decode(unsigned char* csDestination, const unsigned char* csSource, int iSourceLen);
  6. bool IsThisOurFormat(char c);
  7. int main()
  8. {
  9. unsigned char msg[256];
  10. Decode(msg, dloc, sizeof(dloc));
  11. printf((char*)&msg);
  12. return 0;
  13. }
  14. inline bool IsThisOurFormat(char c)
  15. {
  16. return (c && (strchr(alfa, c) != 0));
  17. }
  18. inline char Value(char c)
  19. {
  20. const char* p = strchr(alfa, c + 1);
  21. if (p)
  22. return (p - alfa);
  23. else
  24. return 0;
  25. }
  26. int Decode(unsigned char* csDestination, const unsigned char* csSource, int iSourceLen)
  27. {
  28. unsigned char* p = csDestination;
  29. if (*csSource == 0)
  30. return 0;
  31. *csDestination = 0;
  32. do
  33. {
  34. char a = Value(csSource[0]);
  35. char b = Value(csSource[1]);
  36. char c = Value(csSource[2]);
  37. char d = Value(csSource[3]);
  38. *p++ = (a << 2) | (b >> 4);
  39. *p++ = (b << 4) | (c >> 2);
  40. *p++ = (c << 6) | d;
  41. if (!IsThisOurFormat(csSource[1]))
  42. {
  43. p -= 2;
  44. break;
  45. }
  46. else if (!IsThisOurFormat(csSource[2]))
  47. {
  48. p -= 2;
  49. break;
  50. }
  51. else if (!IsThisOurFormat(csSource[3]))
  52. {
  53. p--;
  54. break;
  55. }
  56. csSource += 4;
  57. while (*csSource && ((*csSource == 13) || (*csSource == 10)))
  58. ++csSource;
  59. }
  60. while (iSourceLen -= 4);
  61. *p = 0;
  62. return (p - csDestination);
  63. }

Edit this Snippet