Added the encode/decode methods provided by the teacher