Subject: | Output from decrypt() behaves strangely under very specific circumstances |
OK, this is one of the weirdest things I've ever seen. In the attached file is a Perl script that *should* print "116,101,115,116" to screen from the print statement on line 19. It should do this because line 17 contains a substitution that should get rid of all the null characters that are at the end of the string after it gets returned from decrypt() (and are printed from the print statement on line 16). However, when this is done in a subroutine, and when the scalar $key has 'my' in front of it, it doesn't work. It's like $plaintext is immutable under these conditions. But, if you remove the 'my' from $key on line 5, it will start working. Or, if you put all the code in mySub into the main body of the program, that will make it work too. I have no idea what could be causing this. I have tested this on two different machines. One is a PC running Debian GNU/Linux i386 woody (kernel 2.4.18) with the latest Crypt::Rijndael from CPAN on Perl version 5.6.1. The other is Debian GNU/Linux powerpc sid (kernel 2.4.19-pre4) running Crypt::Rijndael from the Debian package libcrypt-rijndael-perl on Perl version 5.6.1.
#!/usr/bin/perl
use Crypt::Rijndael;
my $key = "a" x 32;
my $cipher = new Crypt::Rijndael $key, Crypt::Rijndael::MODE_CBC;
mySub();
sub mySub
{
my $encryptedData = "eeb1fabf451aa59252003bdd6d568357";
my $encryptedData = pack("H*", $encryptedData);
my $plaintext = $cipher->decrypt($encryptedData);
print $plaintext,"\n";
print join(',', unpack 'C*', $plaintext),"\n";
$plaintext =~ s/\x00+$//;
print $plaintext,"\n";
print join(',', unpack 'C*', $plaintext),"\n";
}