I <3 Steve McConnell*
Coding Horror
programming and human factors
by Jeff Atwood

October 07, 2005

C# implementation of ASCII85

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    View blog reactions

 

« Equipping our ASCII Armor ALT+TAB Extreme* »

 

Comments

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

Will on October 9, 2005 02:44 PM

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 PM

Phenomenal..!

Lyronne on August 24, 2006 06:10 AM

sdsdsd sw

aababa on January 24, 2008 04:32 AM







(hear it spoken)


(no HTML)




Content (c) 2008 Jeff Atwood. Logo image used with permission of the author. (c) 1993 Steven C. McConnell. All Rights Reserved.