Is there a special reason why you wrote this yourself; why don't you use a well-tested library like Apache Jakarta Commons Codec?
If you encode and decode something and the result is different from the input, then there's obviously a bug somewhere in your code. Use a debugger to step through your code and see if it is doing what you expect it to do. You could also put System.out.println(...); statements in your code to print the value of variables at strategic places to see if the program is doing what you expect it to do.