I'm looking for a generic algorithm which encode / decode a given string on a defined chars set to / from a byte array. It must use minimal space.
I started developping mine which is a kind of Base'n' to Base 2 algorithm, but I think something like that must have already been developped.
My need is to encode in a minimal bits number strings using a known restricted charset. Maybe I should use bzip2?
Edit: My strings length maximum is 160 chars. I can pad them if needed.
Edit2: I must know the worst-case bits number.
byte[] encode(string charset, string value)
string decode(string charset, byte[] encodedValue)
Usage:
string myString = "HELLO WORLD";
string charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ "; // Base 27
byte[] encodedString = encode(charset, myString); // Base 27 -> Base 2
Debug.Assert(myString.Equals(decode(charset, encodedString))); // Base 2 -> Base 27