Fabcoin Core  0.16.2
P2P Digital Currency
Base64.h
Go to the documentation of this file.
1 /*
2  base64.cpp and base64.h
3 
4  Copyright (C) 2004-2008 RenĂ© Nyffenegger
5 
6  This source code is provided 'as-is', without any express or implied
7  warranty. In no event will the author be held liable for any damages
8  arising from the use of this software.
9 
10  Permission is granted to anyone to use this software for any purpose,
11  including commercial applications, and to alter it and redistribute it
12  freely, subject to the following restrictions:
13 
14  1. The origin of this source code must not be misrepresented; you must not
15  claim that you wrote the original source code. If you use this source code
16  in a product, an acknowledgment in the product documentation would be
17  appreciated but is not required.
18 
19  2. Altered source versions must be plainly marked as such, and must not be
20  misrepresented as being the original source code.
21 
22  3. This notice may not be removed or altered from any source distribution.
23 
24  RenĂ© Nyffenegger rene.nyffenegger@adp-gmbh.ch
25 */
29 #pragma once
30 
31 #include <string>
32 #include "Common.h"
33 #include "FixedHash.h"
34 
35 namespace dev
36 {
37 
38 std::string toBase64(bytesConstRef _in);
39 bytes fromBase64(std::string const& _in);
40 
41 template <size_t N> inline std::string toBase36(FixedHash<N> const& _h)
42 {
43  static char const* c_alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
44  typename FixedHash<N>::Arith a = _h;
45  std::string ret;
46  for (; a > 0; a /= 36)
47  {
48  unsigned r = (unsigned)(a - a / 36 * 36); // boost's % is broken
49  ret = c_alphabet[r] + ret;
50  }
51  return ret;
52 }
53 
54 template <size_t N> inline FixedHash<N> fromBase36(std::string const& _h)
55 {
56  typename FixedHash<N>::Arith ret = 0;
57  for (char c: _h)
58  ret = ret * 36 + (c < 'A' ? c - '0' : (c - 'A' + 10));
59  return ret;
60 }
61 
62 }
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
#define c(i)
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< N *8, N *8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> Arith
The corresponding arithmetic type.
Definition: FixedHash.h:51
#define a(i)
FixedHash< N > fromBase36(std::string const &_h)
Definition: Base64.h:54
std::vector< byte > bytes
Definition: Common.h:75
vector_ref< byte const > bytesConstRef
Definition: Common.h:77
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
Definition: FixedHash.h:47
std::string toBase64(bytesConstRef _in)
Definition: Base64.cpp:49
bytes fromBase64(std::string const &_in)
std::string toBase36(FixedHash< N > const &_h)
Definition: Base64.h:41