Hi Stephen,
> Is this right? So far I believe it does not because what I get in
> 'unzip_text' is rubbish.
Probably not if you are getting rubbish.
Here's a non-elegant sample (I'm almost embarrassed to post it). Notice how
all the objects basically act the same. You can drop in a base64
(en/de)coder in place of the hex. That's one of the great benefits of using
this library. Sadly, I don't take advantage of chaining...
Jeff
BTW, sample code that we could compile would be nice next time.
#include "gzip.h"
#include "hex.h"
#include <iostream>
#include <string>
#pragma comment( lib, "cryptlibd" )
using std::string;
using std::cout;
using std::endl;
int main(int argc, char* argv[]) {
string original("B o o H o o I a m s o s c a
r e d");
cout << "Original String:" << endl << original << endl << endl;
///////////////////////////
//
// Compress
//
CryptoPP::Gzip compressor;
compressor.PutMessageEnd( (const byte*)original.c_str(), original.size()
);
// Alternately
// compressor.Put( (const byte*)original.c_str(), original.size() );
// compressor.MessageEnd();
byte* zip = NULL;
int size = compressor.MaxRetrievable();
zip = new byte[ size ];
compressor.Get( zip, size );
///////////////////////////
//
// Encode
//
CryptoPP::HexEncoder encoder;
encoder.PutMessageEnd( zip, size );
byte* hex = NULL;
hex = new byte[ encoder.MaxRetrievable() + 1 ];
hex[ encoder.MaxRetrievable() ] = '\0';
encoder.Get( hex, encoder.MaxRetrievable() );
cout << "Compressed String:" << endl << hex << endl << endl;
///////////////////////////
//
// Decode
//
// Would look like the rest of it.
///////////////////////////
//
// Decompress
//
CryptoPP::Gunzip decompressor;
decompressor.PutMessageEnd( zip, size );
string decompressed;
decompressed.resize( decompressor.MaxRetrievable() + 1 );
decompressed[ decompressor.MaxRetrievable() ] = '\0';
decompressor.Get( (byte*)decompressed.c_str(),
decompressor.MaxRetrievable() );
cout << "Decompressed String:" << endl << decompressed << endl << endl;
if( NULL != zip ) {
delete[] zip;
}
if( NULL != zip ) {
delete[] hex;
}
return 0;
}
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Stephen torri
> Sent: Tuesday, November 18, 2003 7:38 PM
> To: cryptopp
> Subject: Gzip & Gunzip code: Correct or rubbish
>
>
> I decided to work on get my encrypt and decrypt methods in
> stages. The first stage is to get the plain text string
> compressed and decompressed correctly.
>
> Gcc:3.2.3
> Crypto:5.1
>
> Compress:
>
> string gzip_text;
> Gzip aes_compressor2 (new StringSink (gzip_text));
> StringStore(plaintext).TransferTo(aes_compressor2);
>
> string unzip_text;
> Gunzip aes_decompressor2 (new StringSink (unzip_text));
> StringStore(gzip_text).TransferTo(aes_decompressor2);
>
> I got this from searching the archive of the mailing list.
> Shame we do not have a directory of example programs. Is this
> right? So far I believe it does not because what I get in
> 'unzip_text' is rubbish.
>
> Plaintext char: B o o H o o I a m s o s c
> a r e d
> Plaintext hex: 0x42 0x6f 0x6f 0x20 0x48 0x6f 0x6f 0x20 0x49
> 0x20 0x61 0x6d 0x20 0x73 0x6f 0x20 0x73 0x63 0x61
> 0x72 0x65
> 0x64
>
> <OUTPUT: Compress plain text>
> Compressed text2: 0x1f 0xffffff8b 0x8 0 0 0 0 0 0 0
>
> <OUTPUT: Decompressed plain text>
> Decompressed text2:
>
> Stephen
>