473,395 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Compress a String


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,

Nov 11 '06 #1
6 8790
Adriano wrote:
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
Nov 11 '06 #2
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

Can anyone recommend a simple way to compress/decomress a String in .NET
1.1 ?
Nov 11 '06 #3
Adriano <ad*********@btconnect.comwrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 11 '06 #4
giddy wrote:
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
Nov 11 '06 #5
i'm sorry!! i did'nt see that!

Gideon
Arne Vajhøj wrote:
And the original poster explicit stated .NET 1.1 ...
Nov 12 '06 #6
All,

Thanks for all your advice. Indeed DES3 output is not compressable, as it mostly noise,
cheers, Adrian
"Adriano" <ad*********@btconnect.comwrote in message news:12*************@corp.supernews.com...

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,

Nov 13 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: José Carlos | last post by:
Hi. How i could compress string of data?. I heart that it´s possible to make with librep, but i´dont know the way to do it. if somebody know any way to do it or any web where explain it i...
0
by: Patrick Questembert | last post by:
I am developping with Visual Studio 2003 + C# + MySQL 4.1 and the OleDb components. My problem is that a stament using the COMPRESS() function seems to work or not depending on the data ... Here...
3
by: Edward | last post by:
Thanks to Bob Powel (http://www.bobpowell.net/onebit.htm) I'm able to compress an image. However, this method takes a long time to compress an image. Does anyone know a quicker way? (The images I...
3
by: delphiconsultingguy | last post by:
Anybody? thanks, Sean
14
by: Hugh Janus | last post by:
Hi all, I have several *long* strings (see bottom of post for an example) which I will be sending across a network. Therefore, I want to compress them for speed and because later they will be...
6
by: Champika Nirosh | last post by:
Hi, I have two machine where I needed to have a extended TCP/IP protocol to make the link between the two machines Mean,I need to write a application that compress every data the machine send...
0
by: vampire1986 | last post by:
Hi all. I have project compress file using C#. I'm using name space IO.Compression and i saw this code on Internet but it is compress to file bigger than source file. Can you help me, please.Thanks...
0
by: J. Clifford Dyer | last post by:
On Sun, May 18, 2008 at 07:06:10PM +0100, Matt Porter wrote regarding Compress a string: def compress_str(s): # str is a builtin keyword. Don't overload it. out = for c in s: if out and c ==...
0
by: Matt Porter | last post by:
On Sun, 18 May 2008 19:13:57 +0100, J. Clifford Dyer <jcd@sdf.lonestar.orgwrote: Thanks. Had to change a few bits to make it behave as I expected: def compress_str(s): # str is a builtin...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.