jmamer has asked for the wisdom of the Perl Monks concerning the following question:
Looking at the line that says $plaintext = "This is a test \n with a line-break in it\n";. If I leave this line in, the script works fine, prints out the plain text, then the encrypted text and then the correct plaintext again. If I now comment out this line and uncomment out the file read statement, and then read from a file containing exactly the same text, the program does not create the same encryption, and cannot decrypt what it produces back to clear text. I looked at the output of RC4.pm and it looks to me like it inserts some ascii codes into the output string when the string is read from a file, but not when the string is defined as a variable in the program. At this point, I am stumped and am likely missing something very obvious. Any insight would be greatly appreciated. Could it be something in my perl installation is hosed? thanks j.#!/usr/bin/perl -w use strict; use diagnostics; use Crypt::RC4; #grab command line args and get keyphrase my $key_phrase = $ARGV[0]; my $cleartext_file = $ARGV[1]; my $cyphertext_file = $ARGV[2]; chomp($key_phrase); #define some variables my $plaintext; my $cyphertext; my $plaintext2; #complain if mis-used if ($#ARGV <2) { die "Usage crypt_file.pl <key phrase> <cleartext file> <cyphertext f +ile> "; } #open the plaintext file open INFILE, "<$cleartext_file" or die "Can't open input file: ",$cleartext_file,"\n"; my $cph_in = new Crypt::RC4($key_phrase); undef $/; #$plaintext = <INFILE>; close(INFILE); $plaintext = "This is a test\n with a line-break in it\n"; print the plaintext to check it print "+++++++++++++++plain text+++++++++++++++++++++++\n"; print $plaintext; $cyphertext = $cph_in->RC4($plaintext); my $cph_out = new Crypt::RC4($key_phrase); $plaintext2 = $cph_out->RC4($cyphertext); open OUTFILE, ">$cyphertext_file"; print OUTFILE $cyphertext; print "\n----------------cypher text---------------------\n"; print $cyphertext; close(OUTFILE); print "\n++++++++++++++plain text again +++++++++++++++++\n"; print $plaintext2;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help with RC4
by PodMaster (Abbot) on Jul 26, 2004 at 05:30 UTC | |
by jmamer (Initiate) on Jul 26, 2004 at 05:56 UTC | |
by hbo (Monk) on Jul 26, 2004 at 06:04 UTC | |
by PodMaster (Abbot) on Jul 26, 2004 at 06:19 UTC | |
by hbo (Monk) on Jul 26, 2004 at 06:43 UTC | |
| |
|
Re: Help with RC4
by hbo (Monk) on Jul 26, 2004 at 05:58 UTC | |
|
Re: Help with RC4
by iburrell (Chaplain) on Jul 26, 2004 at 16:35 UTC | |
by TStanley (Canon) on Jul 26, 2004 at 19:37 UTC | |
by jmamer (Initiate) on Jul 26, 2004 at 20:31 UTC | |
by jdalbec (Deacon) on Jul 27, 2004 at 01:58 UTC |