in reply to Reading two (2) file in byte[] form and then XOring them
Note that your code assumes that both files have the same number of lines, and that those lines have the same number of characters. To avoid that assumption, read in blocks with the read function instead of reading a line at a time. You should also use binmode, as PodMaster sggested.
Also, you may find that Crypt::CTR does some or all of what you want.
Something like this is a shorter way to do what you want. You can check they're equal with the string equality operators (eq and ne), as shown below.
# Read in my @my_a = <PLAIN>; my @my_b = <CTR>; # XOR my @my_c = map { $my_a[$_] ^ $my_b[$_] } 0..$#my_a; my @my_d = map { $my_b[$_] ^ $my_c[$_] } 0..$#my_b; # Check foreach (0..$#my_d) { $my_d[$_] eq $my_a[$_] or die "d[$my_d[$_]] != a[$my_a[$_]] at line $_\n"; } print "OK\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reading two (2) file in byte[] form and then XOring them
by cik_ail (Initiate) on Feb 25, 2005 at 02:37 UTC | |
by sgifford (Prior) on Feb 25, 2005 at 05:49 UTC |