Toby Stuart wrote:
thanks $Bill, i had to add binmode on $ifh and $ofh (see below) to make it
work



Try this one:

use strict;
use Crypt::CBC;
use IO::File;

my $key = pack "H16", "1122334455667788";
my $cipher = new Crypt::CBC ($key, 'DES');

die "Usage: perl $0 file-to-encrypt [encrypted_output_file]\n" .
"or: perl $0 -decrypt file-to-decrypt [decrypted_output_file]\n" .
" Second file arg defaults to STDIN for encrypt; STDOUT for decrypt\n\n"
if not @ARGV;

my $decrypt = 0;
for (my $ii = 0; $ii < @ARGV; ) {
if ($ARGV[$ii] =~ /^--?de/) {
$decrypt = 1;
splice @ARGV, $ii, 1;
next;
}
$ii++;
}

my $ifh = new IO::File;
if (@ARGV) {
$ifh->open("<$ARGV[0]") or die "open $ARGV[0]: $!";
} else {
$ifh->open("<&STDIN") or die "open $ARGV[0]: $!";
}

my $ofh = new IO::File;
if (@ARGV > 1) {
$ofh->open(">$ARGV[1]") or die "open $ARGV[1]: $!";
} else {
$ofh->open(">&STDOUT") or die "open $ARGV[1]: $!";
}
I'd do it here instead:

binmode $ifh;
binmode $ofh;


my $in;
if ($decrypt) {
	$cipher->start('decrypting');
	
	binmode($ofh);


	print $ofh $cipher->crypt($in) while read $ifh, $in, 1024;
	print $ofh $cipher->finish;
} else {
	$cipher->start('encrypting');

	binmode($ifh);
	

	print $ofh $cipher->crypt($in) while read $ifh, $in, 1024;
	print $ofh $cipher->finish;
}
$ifh->close;
$ofh->close;

__END__



--
  ,-/-  __      _  _         $Bill Luebkert   ICQ=162126130
 (_/   /  )    // //       DBE Collectibles   Mailto:dbe@;todbe.com
  / ) /--<  o // //      http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to