Converts an unsigned integer into a base64 string of length l
| 34 | |
| 35 | // Converts an unsigned integer into a base64 string of length l |
| 36 | std::string base64(unsigned value, int length) { |
| 37 | const int BASE64 = 64; |
| 38 | std::string result; |
| 39 | result.reserve(length); |
| 40 | while (value != 0U) { |
| 41 | result.push_back(chars[value % BASE64]); |
| 42 | value /= BASE64; |
| 43 | } |
| 44 | while ((int)result.size() != length) { |
| 45 | result.push_back('0'); |
| 46 | } |
| 47 | std::reverse(result.begin(), result.end()); |
| 48 | return result; |
| 49 | } |
| 50 | |
| 51 | // Converts a base64 string into an unsigned integer |
| 52 | unsigned from_base64(const std::string& string) { |