-
-
Save trietptm/05083e9e13860cc5e8c3415e95c02f9c to your computer and use it in GitHub Desktop.
ZLib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Decoding. | |
bytes_t crypt = {120, 156, 251, 255, 127, 100, 3, 0, 8, 0, 255, 1}; | |
bytes_t plain(196864); | |
z_stream stream; | |
inflateInit(&stream); | |
stream.next_in = crypt.data(); | |
stream.avail_in = crypt.size(); | |
stream.next_out = plain.data(); | |
stream.avail_out = plain.size(); | |
int ret = inflate(&stream, Z_FINISH); | |
inflateEnd(&stream); | |
if (ret == Z_STREAM_END) { | |
plain.resize(stream.total_out); | |
std::cout << "plain = "; | |
for (int i = 0; i < plain.size(); i++) | |
std::cout << (int) plain[i] << " "; | |
std::cout << std::endl; | |
} | |
// Encoding. | |
bytes_t encrypt(plain.size()); | |
stream = z_stream(); | |
deflateInit(&stream, Z_DEFAULT_COMPRESSION); | |
stream.next_in = plain.data(); | |
stream.avail_in = plain.size(); | |
stream.next_out = encrypt.data(); | |
stream.avail_out = encrypt.size(); | |
ret = deflate(&stream, Z_FINISH); | |
deflateEnd(&stream); | |
if (ret == Z_STREAM_END) { | |
encrypt.resize(stream.total_out); | |
std::cout << "crypt = "; | |
for (int i = 0; i < encrypt.size(); i++) | |
std::cout << (int) encrypt[i] << " "; | |
std::cout << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment