Implemented the decode() method with tests.