Compress a String

  • Thread starter Thread starter Adriano
  • Start date Start date
A

Adriano

Can anyone recommend a simple way to compress/decomress a String in .NET 1.1 ?

I have a random string of 70 characters, the output from a DES3 encryption, and I wish to reduce the lengh of it,


thanks,
 
Adriano said:
Can anyone recommend a simple way to compress/decomress a String in .NET
1.1 ?

I have a random string of 70 characters, the output from a DES3
encryption, and I wish to reduce the lengh of it,

For general compression look at something like #ZipLib.

But I don't think it is worth it in this case. Encrypted
data usually don't compress very well.

Arne
 
C# comes with the GZip and Deflate algorithm for compression
system.IO.Compression
....
...
...
//GZIP
static void SaveCompressedFile(string filename, string data)
{
FileStream fileStream =
new FileStream(filename, FileMode.Create, FileAccess.Write);
GZipStream compressionStream =
new GZipStream(fileStream, CompressionMode.Compress);
StreamWriter writer = new StreamWriter(compressionStream);
writer.Write(data);
writer.Close();
}

static string LoadCompressedFile(string filename)
{
FileStream fileStream =
new FileStream(filename, FileMode.Open, FileAccess.Read);
GZipStream compressionStream =
new GZipStream(fileStream, CompressionMode.Decompress);
StreamReader reader = new StreamReader(compressionStream);
string data = reader.ReadToEnd();
reader.Close();
return data;
}

//replacing GZipStream with DeflateStream uses the Deflate algorithm


but like he said.. encrypted data does'nt compress well becuase the
algorithms just removes repeats.... it works well with strings that
have repetitions.

I would suggest not encrypting the text.... compress them first (they
end up somewhat encrypted , but someone could just read and uncompress
it with the above code) ... so you can try encrypting the compressed
data.

Hope i helped,
Gideon

 
Adriano said:
Can anyone recommend a simple way to compress/decomress a String in
.NET 1.1 ?

I have a random string of 70 characters, the output from a DES3
encryption, and I wish to reduce the lengh of it,

I doubt very much whether you'll be able to compress it at all. The
more "random" data is, the less likely you are to be able to compress
it. Compression is almost always based on repeated patterns.

One thought though: the output of DES3 is binary, not text: how are you
converting the bytes into a string? There may be a way of doing that
which saves some more size.
 
giddy said:
C# comes with the GZip and Deflate algorithm for compression
system.IO.Compression

..NET 2.x does !

And the original poster explicit stated .NET 1.1 ...

Arne
 
All,

Thanks for all your advice. Indeed DES3 output is not compressable, as it mostly noise,


cheers, Adrian



Can anyone recommend a simple way to compress/decomress a String in ..NET 1.1 ?

I have a random string of 70 characters, the output from a DES3 encryption, and I wish to reduce the lengh of it,


thanks,
 
Back
Top