fix: a variable 'c' value must be set to -1 if a 'state' variable is 0.
fix: bug of padding byte calculation has been fixed.
fix: part of decoding logic has been replaced to public domain implementation.