Hi everyone im making a perl script to encrypt and decrypt text, i just have started i have this:
#!/usr/bin/perl
use Crypt::IDEA;
my $key = pack("H32", "0123456789ABCDEF0123456789ABCDEF");
my $cipher = new IDEA $key;
my $palabra= "plaintex";
my $ciphertext = $cipher->encrypt($palabra); # NB - 8 bytes
print unpack("H16", $ciphertext), "\n";
my $plaintext = $cipher->decrypt($ciphertext);
print $plaintext , "\n";
The trouble is the text to encrypt must be of 8 bytes of length. why? if i put “plaintext” instead “plaintex” gives me error.
input must be 8 bytes long at /usr/lib/perl5/site_perl/Crypt/IDEA.pm line 62.
Wrap Crypt::IDEA with Crypt::CBC – it will allow to use non-aligned data length. See doc for Crypt::CBC.
This is because IDEA and many other crypt algorithms are block encryption algorithms. This means they operate with blocks of data of specified size, so data you encrypting must be prepared (padded with zeros or whatever)