#!/usr/local/bin/perl
use diagnostics;
use strict;
use warnings;
use Crypt::CBC; # CBC automatically loads Misty1 for us
my $key = pack "H32", "00112233445566778899aabbccddeeff";
my $IV = pack "H16", "0102030405060708";
my $cipher = Crypt::CBC->new({'key' => $key,
'cipher' => 'Misty1',
'iv' => $IV,
'regenerate_key' => 0,
'padding' => 'standard',
'prepend_iv' => 0
});
my $plaintext1 = pack "H32", "0123456789abcdeffedcba9876543210";
print "plaintext1 : ", unpack("H*", $plaintext1), "\n";
my $ciphertext1 = $cipher->encrypt($plaintext1);
print "ciphertext1 : ", unpack("H*", $ciphertext1), "\n";
my $plaintext2 = $cipher->decrypt($ciphertext1);
print "plaintext2 : ", unpack("H*", $plaintext2), "\n";
# Note that 'regenerate_key' was set to 0 just so that this example
# confirms the CBC result given in RFC 2994. However, it is highly
# recommended that 'regenerate_key' be set to 1 for maximum security.