z662 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use warnings; use Crypt::Tea; if (@ARGV != 3) { print STDERR "Usage: $0 [-d|-e] [FILENAME] [KEY] \n"; exit 1; } if (($ARGV[0] ne '-d') && ($ARGV[0] ne '-e')) { print "Specify '-d' to decrypt or '-e' to encrypt\n"; exit 1; } my ($action, $file, $key) = @ARGV; open (my $fh, '<', $file) or die $!; my @input = readline($fh) or die "readline failed: $!\n"; if ($action eq '-e') { my @cryptedText = cryptText($key,$action,\@input); my $i = join("\n",@cryptedText); print $i; } if ($action eq '-d') { my @cryptedText = cryptText($key,$action,\@input); my $i = join('',@cryptedText); print $i; } sub cryptText { die if @_ != 3; my ($key,$action,$input) = @_; my @cryptedText; foreach my $text (@$input) { if ($action eq '-d') { $text = decrypt($text,$key); } if ($action eq '-e') { $text = encrypt($text,$key); } push (@cryptedText,$text); } return @cryptedText; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: 32 Character limit
by ikegami (Patriarch) on Feb 09, 2011 at 00:27 UTC | |
by z662 (Initiate) on Feb 09, 2011 at 20:45 UTC | |
by ikegami (Patriarch) on Feb 09, 2011 at 21:33 UTC | |
by z662 (Initiate) on Feb 11, 2011 at 01:11 UTC | |
by z662 (Initiate) on Feb 15, 2011 at 23:50 UTC | |
by ikegami (Patriarch) on Feb 16, 2011 at 00:51 UTC | |
|
Re: 32 Character limit
by jethro (Monsignor) on Feb 08, 2011 at 23:43 UTC | |
by ikegami (Patriarch) on Feb 09, 2011 at 00:03 UTC |