Okay

There is an issue in your code where you set the arg side to the length of the in.
Then you base64 encode it, so it goes longer into the out.

Then it no longer fits in the string length which was based on the in.

Cheers
Marco