BEncode implementation and tests