Mercurial > code
diff C++/Base64.h @ 242:a9883eeb9757
Add tests for Base64
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 11 Sep 2014 21:09:58 +0200 |
parents | b97d75a78e22 |
children | 73e5381d7baf |
line wrap: on
line diff
--- a/C++/Base64.h Thu Sep 11 17:22:11 2014 +0200 +++ b/C++/Base64.h Thu Sep 11 21:09:58 2014 +0200 @@ -67,8 +67,8 @@ inputbuf[count] = *input++; *output++ = lookup(inputbuf[0] >> 2 & 0x3f); - *output++ = lookup(inputbuf[0] << 4 & 0x3f | inputbuf[1] >> 4 & 0x0f); - *output++ = (count < 2) ? '=' : lookup(inputbuf[1] << 2 & 0x3c | inputbuf[2] >> 6 & 0x03); + *output++ = lookup((inputbuf[0] << 4 & 0x3f) | (inputbuf[1] >> 4 & 0x0f)); + *output++ = (count < 2) ? '=' : lookup((inputbuf[1] << 2 & 0x3c) | (inputbuf[2] >> 6 & 0x03)); *output++ = (count < 3) ? '=' : lookup(inputbuf[2] & 0x3f); } } @@ -98,12 +98,12 @@ if (count != 4) throw std::invalid_argument("truncated string"); - *output++ = inputbuf[0] << 2 & 0xfc | inputbuf[1] >> 4 & 0x03; + *output++ = (inputbuf[0] << 2 & 0xfc) | (inputbuf[1] >> 4 & 0x03); if (inputbuf[2] != '=') - *output++ = inputbuf[1] << 4 & 0xf0 | inputbuf[2] >> 2 & 0x0f; + *output++ = (inputbuf[1] << 4 & 0xf0) | (inputbuf[2] >> 2 & 0x0f); if (inputbuf[3] != '=') - *output++ = inputbuf[2] << 6 & 0xc0 | inputbuf[3] & 0x3f; + *output++ = (inputbuf[2] << 6 & 0xc0) | (inputbuf[3] & 0x3f); } } @@ -125,4 +125,4 @@ static std::string decode(const std::string &input); }; -#endif // !_BASE_64_H_ \ No newline at end of file +#endif // !_BASE_64_H_