write en/decoder in C++
(still some bugs though...)