Generic string encoder in C#
<p>What I need is very simple, but before I reinvent the wheel, I would like to know if something similar exist in the framework already.</p>

<p>I would like to encode (and decode) strings from a predefined characters table. I have many strings that contains few characters. Here is a string I would like to encode:</p>

<p>cn=1;pl=23;vf=3;vv=0</p>

<p>This string size is 20 chars, so 20 bytes. </p>

<p>In the string, I only use the following characters: cn=1;p23vf0</p>

<p>A total of 11 characters. So each character can be encoded with 4 bits only isn't ? Reducing the total amount of bytes used to 10.</p>

<p>Is there any existing method in .NET that can take a string in parameter and the reference table array and return the encoded bytes ? </p>

<p>char[] reference = "cn=1;p23vf0".ToCharArray();
string input = "cn=1;pl=23;vf=3;vv=0";</p>

<p>byte[] encoded = someClass.Encode(input, reference);
string decoded = someClass.Decode(encoded, reference);</p>

<p>Assert.AreEqual(input, decoded);</p>
