C# implementation of ASCII85

October 7, 2005

As promised, here is my C# implementation of the ASCII85 algorithm. This code is a loose port of the C sample referenced from the Wikipedia page. It's too much code to paste into a single entry, so I packaged it as a VS.NET 2003 solution -- using Clean Sources Plus, of course!

This includes both encoding and decoding, with reasonable data validation and a few minor options. Here's a quick list of the public methods:

Encode(byte[] ba)
Decode(string s)

And a handful of properties:

EnforceMarks (bool)
LineLength (int)
PrefixMark (string) 
SuffixMark (string)

The sample app includes a basic test harness which tests string and binary file encoding, as well as some bad data scenarios. Here's the default demo running against the vaguely creepy Wikipedia slogan:

C# console app output

Of course, converting printable text to, er.. printable text.. isn't exactly an earth-shattering demo. Normally you'd be doing this on some kind of real binary data, as in the GUID.ToByteArray() example.

Posted by Jeff Atwood
5 Comments

Hey Atwood, you are a real nerd. Just kidding. This is Will from the office.

Will on October 9, 2005 3:44 AM

Thank you for this code which i found on the wikipedia, I was looking for a while on how to create the encoder.

Cheers.

Obble on January 7, 2006 10:31 AM

Phenomenal..!

Lyronne on August 24, 2006 7:10 AM

sdsdsd sw

aababa on January 24, 2008 4:32 AM

Hi! I'm using a small glitch in your code, to illustrate the benefits of stateless (functional) programming. To play fair, I'd better let you know about it :-). The link in question is http://blog.wezeku.com/2010/07/01/f-ascii85-module/

John Reynolds on June 30, 2010 5:03 PM

The comments to this entry are closed.