/ / Jak działa ta funkcja C - c

Jak działa ta funkcja C - c

#define BASE32_ONIONLEN 16
#define BASE32_ALPHABET "abcdefghijklmnopqrstuvwxyz234567"

void base32_onion(char *dst, unsigned char *src) { // base32-encode hash
uint8_t byte = 0, // dst location
offset = 0; // bit offset
for(; byte < BASE32_ONIONLEN; offset += 5) {
if(offset > 7) {
offset -= 8;
src++;
}
dst[byte++] = BASE32_ALPHABET[(htobe16(*(uint16_t*)src) >> (11-offset))
& (uint16_t)0x001F];
}
dst[byte] = "";
}

Mam problem ze zrozumieniem części, która zaczyna się od dst[byte++] . Jestem programistą Pythona, nie jestem dokładnie pewien, jak działa cała konwersja typów. src wskazuje na bajt w prawo? i (uint16_t*) zamienia to na wskaźnik na wartość 2-bajtową? to samo czyni bajt src początek dwubajtowej wartości lub koniec? i co jest z >> (11-offset) rzecz?

Odpowiedzi:

0 dla odpowiedzi № 1
uint16_t t1, t2, t3;
uint8_t t4, t5, t6;

t1 = *(uint16_t*)src;       // Whatever src is pointing to, treat the next
// 16 bits as an unsigned number
// Safer would be memcpy(&t1, src, sizeof(t1));
t2 = htobe(t1);             // Guessing this changes the value to have big-endian
// byte order
t3 = t2 >> (11-offset);     // Shift t2 to the right by (11-offset) bits
t4 = t3 & (uint16_t)0x001F; // t4 contains the lower 5 bits of t3
t5 = BASE32_ALPHABET[t4];   // t5 gets the t4-th byte of the base32 alphabet
t6 = byte++;                // t6 gets the value of byte, byte"s value is then
// incremented, so t6 + 1 == byte
dest[t6] = t5;              // t5 is assigned to dest[t6]

Przesunięcie bitu w prawo o wartość n bitów jest równoznaczne z podzieleniem wartości przez 2n.