#include #include /* Define this to have an encoding backward from RFC. #define ALT_ENCODING 1 */ static const char b32_to[32] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; static const char b32_from[] = { ['A']=1, ['a']=1, ['B']=2, ['b']=2, ['C']=3, ['c']=3, ['D']=4, ['d']=4, ['E']=5, ['e']=5, ['F']=6, ['f']=6, ['G']=7, ['g']=7, ['H']=8, ['h']=8, ['I']=9, ['i']=9, ['J']=10, ['j']=10, ['K']=11, ['k']=11, ['L']=12, ['l']=12, ['M']=13, ['m']=13, ['N']=14, ['n']=14, ['O']=15, ['o']=15, ['P']=16, ['p']=16, ['Q']=17, ['q']=17, ['R']=18, ['r']=18, ['S']=19, ['s']=19, ['T']=20, ['t']=20, ['U']=21, ['u']=21, ['V']=22, ['v']=22, ['W']=23, ['w']=23, ['X']=24, ['x']=24, ['Y']=25, ['y']=25, ['Z']=26, ['z']=26, ['2']=27, ['3']=28, ['4']=29, ['5']=30, ['6']=31, ['7']=32, }; int b32_encode(const void *data, size_t data_len, char *s, size_t s_len) { const unsigned char *d=data; unsigned tmp, bits; /* buffer that needs to hold up to 12 bits */ assert(data != NULL); assert(s != NULL); tmp=0; bits=0; while(data_len>0) { assert(bits < 5); #if ALT_ENCODING tmp|=(unsigned)*d<=5) { if(s_len<=1) return 0; /* failure */ bits-=5; #if ALT_ENCODING *s++=b32_to[tmp&31]; tmp>>=5; #else *s++=b32_to[tmp>>bits]; tmp&=(1< int main() { // TODO: implement a test abort(); }