A really simple encoding and decoding algorithm. It uses a list to track the index of a character, and appends that index to the encoded value. Note: Just edited it down from 72 blocks to 52 blocks, and I don't think it can be any smaller, so it is very compact I guess.
All code by me.