150
P A S T E B I N | #1 paste tool since 2002 P A S T E B I N P A S T E B I N search... create new paste trending pastes Don't like ads? PRO users don't see any ads ;-) bitcoin BY: A GUEST ON SEP 7TH, 2013 | SYNTAX: C++ | SIZE: 414.77 KB | HITS: 115 | EXPIRES: NEVER DOWNLOAD | RAW | EMBED | REPORT ABUSE | PRINT 0 0 Public Pastes Untitled 1 sec ago Untitled 5 sec ago 36 sec ago pecesita 7 sec ago Untitled 10 sec ago Untitled 10 sec ago Untitled 10 sec ago Untitled Modula 3 | 20 sec ago create new paste tools api archive faq Like 54k sign up login my alerts my settings my profile Pastebin launched a little side project called HostCabi.net, check it out ;-) 1. static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; 2. inline string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend) 3. { 4. CAutoBN_CTX pctx; 5. CBigNum bn58 = 58; 6. CBigNum bn0 = 0; 7. vector<unsigned char> vchTmp(pend-pbegin+1, 0); 8. reverse_copy(pbegin, pend, vchTmp.begin()); 9. CBigNum bn; 10. bn.setvch(vchTmp); 11. string str; 12. str.reserve((pend - pbegin) * 138 / 100 + 1); 13. CBigNum dv; 14. CBigNum rem; 15. while (bn > bn0) 16. { 17. if (!BN_div(&dv, &rem, &bn, &bn58, pctx)) 18. throw bignum_error("EncodeBase58 : BN_div failed"); 19. bn = dv; 20. unsigned int c = rem.getulong(); 21. str += pszBase58[c]; 22. } 23. for (const unsigned char* p = pbegin; p < pend && *p == 0; p++) 24. str += pszBase58[0]; 25. reverse(str.begin(), str.end()); 26. return str; 27. } 28. inline string EncodeBase58(const vector<unsigned char>& vch) 29. { 30. return EncodeBase58(&vch[0], &vch[0] + vch.size()); 31. } 32. inline bool DecodeBase58(const char* psz, vector<unsigned char>& vchRet) 33. { 34. CAutoBN_CTX pctx; 35. vchRet.clear(); 36. CBigNum bn58 = 58; 37. CBigNum bn = 0; 38. CBigNum bnChar; 39. while (isspace(*psz)) 40. psz++; 41. for (const char* p = psz; *p; p++) 42. { 43. const char* p1 = strchr(pszBase58, *p); 44. if (p1 == NULL) 45. { 46. while (isspace(*p)) 47. p++; 48. if (*p != '\0') 49. return false; 50. break; 51. } 52. bnChar.setulong(p1 - pszBase58); 53. if (!BN_mul(&bn, &bn, &bn58, pctx)) 54. throw bignum_error("DecodeBase58 : BN_mul failed"); 55. bn += bnChar; 56. } 57. vector<unsigned char> vchTmp = bn.getvch(); 58. if (vchTmp.size() >= 2 && vchTmp.end()[-1] == 0 && vchTmp.end()[-2] >= 0x80) 59. vchTmp.erase(vchTmp.end()-1); 60. int nLeadingZeros = 0; 61. for (const char* p = psz; *p == pszBase58[0]; p++) 62. nLeadingZeros++; 63. vchRet.assign(nLeadingZeros + vchTmp.size(), 0); 64. reverse_copy(vchTmp.begin(), vchTmp.end(), vchRet.end() - vchTmp.size()); 65. return true; 66. }

Bitcoin 12,222 lines of code

Embed Size (px)

DESCRIPTION

Bitcoin 12,222 lines of code