Skip to content

Instantly share code, notes, and snippets.

@gahfy
Created July 25, 2023 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gahfy/b55d0a580fbe97ae9ec1d26ea295bc78 to your computer and use it in GitHub Desktop.
Save gahfy/b55d0a580fbe97ae9ec1d26ea295bc78 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <zlib.h>
int main() {
// Le message "Hello World" à compresser
const char *message = "Hello World";
// Données pour la compression
char compressed_data[4096];
uLong compressed_size;
// Taille du message original et de sa version compressée
uLong original_size = strlen(message) + 1; // +1 pour inclure le caractère null de fin de chaîne
// Compression du message
compressed_size = sizeof(compressed_data);
compress((Bytef *)compressed_data, &compressed_size, (const Bytef *)message, original_size);
// Affichage du message compressé
printf("Message compressé : ");
for (uLong i = 0; i < compressed_size; i++) {
printf("%02x ", compressed_data[i] & 0xFF);
}
printf("\n");
// Décompression du message pour vérification
char decompressed_data[4096];
uLong decompressed_size = sizeof(decompressed_data);
uncompress((Bytef *)decompressed_data, &decompressed_size, (const Bytef *)compressed_data, compressed_size);
// Affichage du message décompressé
printf("Message décompressé : %s\n", decompressed_data);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment