a64l.c 437 B

1234567891011121314151617181920212223242526
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <stdint.h>
  4. static const char digits[] =
  5. "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  6. long a64l(const char *s)
  7. {
  8. int e;
  9. uint32_t x = 0;
  10. for (e=0; e<36 && *s; e+=6, s++)
  11. x |= (strchr(digits, *s)-digits)<<e;
  12. return x;
  13. }
  14. char *l64a(long x0)
  15. {
  16. static char s[7];
  17. char *p;
  18. uint32_t x = x0;
  19. for (p=s; x; p++, x>>=6)
  20. *p = digits[x&63];
  21. *p = 0;
  22. return s;
  23. }