Coding Horror

programming and human factors

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.

Written by Jeff Atwood

Indoor enthusiast. Co-founder of Stack Overflow and Discourse. Disclaimer: I have no idea what I'm talking about. Find me here: https://infosec.exchange/@codinghorror