Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <skier.h>
- #include "skibase16.h"
- static unsigned char skibase16_decode_char(unsigned char c)
- {
- if(c >= '0' && c <= '9') return c - '0';
- if(c >= 'A' && c <= 'Z') return c - 'A' + 10;
- if(c >= 'a' && c <= 'z') return c - 'a' + 10;
- return 0xFF;
- }
- int skibase16_decode(char *buff, unsigned long size, unsigned char *out)
- {
- if(buff == NULL || size == 0) return 0;
- if(size & 1) size--; if(out == NULL) out = (unsigned char *) buff;
- unsigned char c, *base = out;
- for (; size; size -= 2) {
- if((c = skibase16_decode_char(*buff++)) == 0xFF) return 0;
- *out = c << 4;
- if((c = skibase16_decode_char(*buff++)) == 0xFF) return 0;
- *out++ |= c;
- }
- *out = 0;
- return out - base;
- }
- int skibase16_encode(unsigned char *buff, unsigned long size, char *out)
- {
- if(buff == NULL || size == 0 || out == NULL) return 0;
- char *base = out;
- while (size) {
- *out++ = "0123456789ABCDEF"[*buff >> 4];
- *out++ = "0123456789ABCDEF"[*buff & 15];
- size--, buff++;
- }
- *out = 0;
- return out - base;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement