http://qs321.pair.com?node_id=11107887


in reply to Re^2: String differs from printing to STDOUT and printing to file
in thread String differs from printing to STDOUT and printing to file

encrypt() seems to NUL pad the string to the required block size:

  $plaintext .= "\0" x $trail;

That's where your NULs are coming from. If you know that trailing \0s are not ever valid, you can strip them right before your return in decrypt():

$plaintext =~ s/\0+$//;

On the other hand, if trailing NUL are a legitimate possibility, you will have to come up with a different plan, such as encoding the real length within your plaintext in encrypt() so you can trim it in the decrypt() sub.