Returns a BASE32 encoded byte array [In] buffer: Pointer to byte array bufLen: Length of buffer array [Return] wxString object with BASE32 encoded byte array
| 340 | // [Return] |
| 341 | // wxString object with BASE32 encoded byte array |
| 342 | wxString EncodeBase32(const unsigned char* buffer, unsigned int bufLen) |
| 343 | { |
| 344 | wxString Base32Buff; |
| 345 | unsigned int i, index; |
| 346 | unsigned char word; |
| 347 | |
| 348 | for(i = 0, index = 0; i < bufLen;) { |
| 349 | // Is the current word going to span a byte boundary? |
| 350 | if (index > 3) { |
| 351 | word = (buffer[i] & (0xFF >> index)); |
| 352 | index = (index + 5) % 8; |
| 353 | word <<= index; |
| 354 | if (i < bufLen - 1) { |
| 355 | word |= buffer[i + 1] >> (8 - index); |
| 356 | } |
| 357 | ++i; |
| 358 | } else { |
| 359 | word = (buffer[i] >> (8 - (index + 5))) & 0x1F; |
| 360 | index = (index + 5) % 8; |
| 361 | if (index == 0) { |
| 362 | ++i; |
| 363 | } |
| 364 | } |
| 365 | Base32Buff += (char) base32Chars[word]; |
| 366 | } |
| 367 | |
| 368 | return Base32Buff; |
| 369 | } |
| 370 | |
| 371 | |
| 372 | // Decodes a BASE32 string into a byte array |