MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / DecodeBase32

Function DecodeBase32

src/commons/util/util.cpp:423–532  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

421}
422
423vector<unsigned char> DecodeBase32(const char* p, bool* pfInvalid) {
424 static const int decode32_table[256] = {
425 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
426 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
427 -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0,
428 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
429 23, 24, 25, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
430 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, -1, -1, -1,
431 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
432 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
433 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
434 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
435 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
436 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
437
438 if (pfInvalid) *pfInvalid = false;
439
440 vector<unsigned char> vchRet;
441 vchRet.reserve((strlen(p)) * 5 / 8);
442
443 int mode = 0;
444 int left = 0;
445
446 while (1) {
447 int dec = decode32_table[(unsigned char)*p];
448 if (dec == -1) break;
449 p++;
450 switch (mode) {
451 case 0: // we have no bits and get 5
452 left = dec;
453 mode = 1;
454 break;
455
456 case 1: // we have 5 bits and keep 2
457 vchRet.push_back((left << 3) | (dec >> 2));
458 left = dec & 3;
459 mode = 2;
460 break;
461
462 case 2: // we have 2 bits and keep 7
463 left = left << 5 | dec;
464 mode = 3;
465 break;
466
467 case 3: // we have 7 bits and keep 4
468 vchRet.push_back((left << 1) | (dec >> 4));
469 left = dec & 15;
470 mode = 4;
471 break;
472
473 case 4: // we have 4 bits, and keep 1
474 vchRet.push_back((left << 4) | (dec >> 1));
475 left = dec & 1;
476 mode = 5;
477 break;
478
479 case 5: // we have 1 bit, and keep 6
480 left = left << 5 | dec;

Callers 2

SetSpecialMethod · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 3

reserveMethod · 0.80
push_backMethod · 0.80
sizeMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68