Advertisement
mortalbotec

Untitled

Mar 27th, 2022
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. template <std::size_t N>
  2.  
  3. constexpr auto DecodeBase85(const char(&input)[N]) noexcept
  4. {
  5. std::array<char*, N * 4 / 5> out{};
  6.  
  7. constexpr auto decode85Byte = [](char c) constexpr -> unsigned int { return c >= '\\' ? c - 36 : c - 35; };
  8.  
  9. for (std::size_t i = 0, j = 0; i < N - 1; i += 5, j += 4) {
  10. unsigned int tmp = decode85Byte(input[i]) + 85 * (decode85Byte(input[i + 1]) + 85 * (decode85Byte(input[i + 2]) + 85 * (decode85Byte(input[i + 3]) + 85 * decode85Byte(input[i + 4]))));
  11. out[j] = ((tmp >> 0) & 0xFF); out[j + 1] = ((tmp >> 8) & 0xFF); out[j + 2] = ((tmp >> 16) & 0xFF); out[j + 3] = ((tmp >> 24) & 0xFF);
  12. }
  13.  
  14. return out;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement