All pastes #129251 Raw Edit

Untitled

public text v1 · immutable
#129251 ·published 2006-08-13 13:00 UTC
rendered paste body
/* Eat 5 bytes from src, write 8 bytes to dest */
void
encode_chunk(char *dest, char *src)
{
        char c;

        *dest++ = base32[(*src & 0xF8) >> 3];   // 1111 1000 first byte

        c = (*src++ & 0x07) << 2;               // 0000 0111 first byte
        c |=  ((*src & 0xC0) >> 6);             // 1100 0000 second byte
        *dest++ = base32[(int) c];

        *dest++ = base32[(*src & 0x3E) >> 1];   // 0011 1110 second byte

        c = (*src++ & 0x01) << 4;               // 0000 0001 second byte
        c |=  ((*src & 0xF0) >> 4);             // 1111 0000 third byte
        *dest++ = base32[(int) c];

        c = (*src++ & 0x0F) << 1;               // 0000 1111 third byte
        c |=  ((*src & 0x80) >> 4);             // 1000 0000 fourth byte
        *dest++ = base32[(int) c];

        *dest++ = base32[(*src & 0x7C) >> 2];   // 0111 1100 fourth byte

        c = (*src++ & 0x03) << 3;               // 0000 0011 fourth byte
        c |=  ((*src & 0xE0) >> 5);             // 1110 0000 fifth byte
        *dest++ = base32[(int) c];

        *dest++ = base32[*src++ & 0x1F];        // 0001 1111 fifth byte
}