Pensieve Header: This is a jff implementation of key elements of the bzip2 compression algorithm. When run on the Wikipedia entry for Bzip2 it is 7% worse than the true bzip2, I'm not sure why.

urls={"http://www.math.toronto.edu/~drorbn/papers/WKO", "http://en.wikipedia.org/wiki/Bzip2"};
text=StringTake[
Import[urls[[1]], "Text"],
All
];
text=StringReplace[text, "\n" -> "|"]

l=Length[charseq = Characters[text]]

Total[Length /@ Select[Split[charseq], Length[#]>4&]]

Sort[Reverse /@ Tally[charseq]] // Reverse

entropy[seq_List] := Total[
N[-#*Log[2, #]]& /@ ((Last /@ Tally[seq])/Length[seq])
];
entropy[charseq]

StringJoin[pivots=
charseq[[
Sort[
Range[l],
(
{i1,i2}={#1,#2};
While[charseq[[i1]]==charseq[[i2]], {i1,i2}=({i1,i2}/.l->0)+1];
OrderedQ[{charseq[[i1]], charseq[[i2]]}]
)&
]-1 /. 0-> l
]]
]

alphabet = Union[pivots]

codeseq = Table[
k = Position[alphabet, pivots[[i]]][[1,1]];
alphabet[[Range[k]]]=RotateRight[alphabet[[Range[k]]]];
k,
{i,l}
]

Sort[Reverse /@ Tally[codeseq]] // Reverse

entropy[codeseq]*{1,1/8,l/8}

rleseq=Flatten[
{First[#], Rest[IntegerDigits[Length[#], 2] /. {0->Efes, 1->Ekhad}]}& /@ Split[codeseq]
]

entropy[rleseq]*{1,1/8,Length[rleseq]/8}

Sort[Reverse /@ Tally[rleseq]] // Reverse

Length[rleseq]