#!/usr/perl5/bin -w use Crypt::CBC; $inFile = "test.dat"; $cryptFile = "Crypt.dat"; $decrypFile = "DeCrypt.dat"; if ($#ARGV < 0) { print STDOUT "Invalid number of command line parameters! \n"; exit(1); } $mode = shift @ARGV; unless (($mode == 0) || ($mode == 1)) { print STDOUT "Invalid command line argument1 \n"; exit(2); } $cipher = Crypt::CBC->new( { 'key' => '18829298', 'cipher' => 'DES', 'iv' => '87654321', 'regenerate_key' => 0, 'prepend_iv' => 0 } ); if ($mode == 0) { open(INFILE, "<$inFile") || die "Error opening source file for input! \n"; open(CRYPTFILE, ">$cryptFile") || die "Error opening crypt file for output! \n"; $cipher->start('encrypting'); while () { print CRYPTFILE $cipher->crypt($_); } close INFILE; close CRYPTFILE; } else { open(CRYPTFILE, "<$cryptFile") || die "Error opening crypt file for input! \n"; open(DECRYPFILE, ">$decrypFile") || die "Error opening decrypt file for output! \n"; $cipher->start("decrypting"); while () { print DECRYPFILE $cipher->crypt($_); } close CRYPTFILE; close DECRYPFILE; }