2

I have an issue which I am banging my head against, I am trying to decompress text in this format:

eJx7v3t/QWJxcXl+UQoAJ94F3Q==

The problem I am having is that it works awesome on this site: http://www.unit-conversion.info/texttools/compress/

But I can't seem to get it to work with C#, I have tried Gzip and Zip, but it they both throw invalid data errors.

using (Stream fs = GenerateStreamFromString("eJx7v3t/QWJxcXl+UQoAJ94F3Q=="))
{
    using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Read))
    {
        //Do stuff
    }
}

public Stream GenerateStreamFromString(string s)
{
    MemoryStream stream = new MemoryStream();
    StreamWriter writer = new StreamWriter(stream);
    writer.Write(s);
    writer.Flush();
    stream.Position = 0;
    return stream;
}

it thows an error on the ZipArchive line for the invalid data, it should decompress to "password" but I am unsure why it wont work.

If anyone knows of why or another library that will work, I would love to know!

Thanks!

EDIT

I tried the LZW algorithm with no luck, I figured it was zip because the header stated it was gzipped, but I am not sure how the data is compressed due to lack of documentation.

here is my LZW example code.

byte[] decodedBytes = Convert.FromBase64String("eJx7v3t/QWJxcXl+UQoAJ94F3Q==");
String text = System.Text.Encoding.UTF8.GetString(decodedBytes);

SharpLZW.LZWDecoder test = new SharpLZW.LZWDecoder();
string testval = test.Decode(text);

Decode is where I get the error, I tried with and without Base64 conversion, also with every type of encoding I could think of.

Any ideas?

Krum110487
  • 611
  • 1
  • 7
  • 20

6 Answers6

2

That is a Base-64 encoding of a zlib stream, not gzip, nor zip. You can use zlib to decode it. It decompresses to ef bb bf 70 61 73 73 77 6f 72 64. (The last eight bytes are "password".)

A quick perusal of the documentation indicates that .NET doesn't have a zlib decoder. You could write your own zlib header and trailer processing code using RFC 1950, and then the DeflateStream class to decompress the raw compressed data. Though you probably shouldn't use .NET for compression.

I would recommend looking at DotNetZip.

Community
  • 1
  • 1
Mark Adler
  • 101,978
  • 13
  • 118
  • 158
1

It looks like your compressed text is in Base64 string, you can try first base64 to binary conversation and then try the zip library.

Joe
  • 129
  • 3
  • 6
1

The website you link to claims the compression algorithm it uses is unix compress.

Compress is a Unix based compress program. Once a file is compressed using Compress, you can restore the file to its original state with the uncompress utility. Uncompress restores attributes of a compressed file

A brief bit of research leads to the conclusion this is LZW compression.

Compress is a Unix shell compression program based on the LZW compression algorithm.

You need a .NET implementation of this - SharpLZW was the first I found.

Charles Mager
  • 25,735
  • 2
  • 35
  • 45
  • AH! I can't believe I didn't notice that bit of text, I am embarrassed to say I don't know much about compression types, I will try this! Thanks. – Krum110487 May 05 '15 at 15:30
  • Unfortunately this didn't work for me, with and without base64 conversion, and I tried it with every type of encoding with base64, no luck. – Krum110487 May 05 '15 at 18:09
1

eJx7v3t/QWJxcXl+UQoAJ94F3Q== looks like a base64-encoded string. You need to decode this with the proper method before trying to uncompress it.

byte[] decodedBytes = Convert.FromBase64String("eJx7v3t/QWJxcXl+UQoAJ94F3Q==");

Unfortunately, there's still a problem: the compressed data is not a zip archive. As Ron Beyer pointed out, it's LZW compression. SharpLZW is one example of a library that can read that in .Net.

Community
  • 1
  • 1
Tim S.
  • 55,448
  • 7
  • 96
  • 122
0

The compress program is using the unix compress software

http://en.wikipedia.org/wiki/Compress

Compress is a Unix shell compression program based on the LZW compression algorithm.[1] Compared to more modern compression utilities such as gzip and bzip2, compress performs faster and with less memory usage, at the cost of a significantly lower compression ratio.

I have searched around for some prebuilt libraries and have found http://www.codeproject.com/Articles/6838/LZW-Compression Since th algorithm is actually in the public domain you could build it yourself for fun. :D A link to the implementation is: http://warp.povusers.org/EfficientLZW/

Nathan
  • 201
  • 1
  • 7
0

I think you have Base64 Encoding not a Zip-Format. Try something like this:

var bytes = Convert.FromBase64String("eJx7v3t/QWJxcXl+UQoAJ94F3Q==");
var text = Encoding.ASCII.GetString(bytes);

I have no idea if ASCII encoding is the right choice here, because the decoded text is:

x?{?{Abqqy~Q '??

Maybe you have to use zip with that.

CarenRose
  • 1,266
  • 1
  • 12
  • 24
GreenEyedAndy
  • 1,485
  • 1
  • 14
  • 31