in reply to 32 Character limit

That's a very unsafe way of doing things! You should be calling encrypt once, not once per line.

encrypt(join("\n", @$input), $key)

I do get garbage at character 32 (or thereabouts, I didn't look closely) when I use your version. I didn't spend any time finding out why because it goes away if you encode once as I urged you to do above.

... my ($action, $file, $key) = @ARGV; my $input; { open(my $fh, '<', $file) or die("Can't open $file: $!\n"); binmode($fh); local $/; $input = <$fh>; } if ($action eq '-e') { print encrypt($input, $key); } else { print decrypt($input, $key); }
$ diff -au a.pl <( perl a.pl -d <( perl a.pl -e a.pl key ) key ) $

Replies are listed 'Best First'.
Re^2: 32 Character limit
by z662 (Initiate) on Feb 09, 2011 at 20:45 UTC

    Thanks for the replies. However I am not sure I understand. Isn't my code

    if ($action eq '-e') { my @cryptedText = cryptText($key,$action,\@input); my $i = join("\n",@cryptedText); print $i; }

    Only calling cryptText (my encrypt sub) one time? It is then joining the newline characters to the end, because when I didn't it would fail to encode properly. Maybe I am missing the boat here.. Please explain

      Isn't my code only calling cryptText (my encrypt sub) one time?

      No, once for each element in @$input.

      foreach my $text (@$input) { ... $text = encrypt($text,$key); ... }
        Alright thanks. Gonna be pretty busy over the next few days, but ill modify my code and post back my results at some point.
        Thanks, I have fixed the problem with the following code:
        #!/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; my $input; { open (my $fh, '<', $file) or die $!; binmode($fh); local $/; $input = <$fh>; } if ($action eq '-e') { print encrypt($input,$key); } if ($action eq '-d') { print decrypt($input,$key); }
        Can someone explain the "my $input; { ... }" part. I am unfamiliar with this type of code. Is this shorthand for a function?