MCPcopy Create free account
hub / github.com/LUX-Core/lux / DecodeBase32

Function DecodeBase32

src/utilstrencodings.cpp:348–459  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

346}
347
348vector<unsigned char> DecodeBase32(const char* p, bool* pfInvalid)
349{
350 static const int decode32_table[256] =
351 {
352 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
353 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
354 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1,
355 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
356 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 0, 1, 2,
357 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
358 23, 24, 25, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
359 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
360 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
361 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
362 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
363 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
364 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
365
366 if (pfInvalid)
367 *pfInvalid = false;
368
369 vector<unsigned char> vchRet;
370 vchRet.reserve((strlen(p)) * 5 / 8);
371
372 int mode = 0;
373 int left = 0;
374
375 while (1) {
376 int dec = decode32_table[(unsigned char)*p];
377 if (dec == -1) break;
378 p++;
379 switch (mode) {
380 case 0: // we have no bits and get 5
381 left = dec;
382 mode = 1;
383 break;
384
385 case 1: // we have 5 bits and keep 2
386 vchRet.push_back((left << 3) | (dec >> 2));
387 left = dec & 3;
388 mode = 2;
389 break;
390
391 case 2: // we have 2 bits and keep 7
392 left = left << 5 | dec;
393 mode = 3;
394 break;
395
396 case 3: // we have 7 bits and keep 4
397 vchRet.push_back((left << 1) | (dec >> 4));
398 left = dec & 15;
399 mode = 4;
400 break;
401
402 case 4: // we have 4 bits, and keep 1
403 vchRet.push_back((left << 4) | (dec >> 1));
404 left = dec & 1;
405 mode = 5;

Callers 2

SetSpecialMethod · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 3

reserveMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68