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
    Thanx..

    But the problem that arrive in Crypt::CTR (the counter is not be able to be transfer to another PC) limits me.. Could anyone here help me??

    How can I used the same counter on other PC?? Its due change on every file running and how can I decrypt it back??

      It looks like the counter is stored in the object's hashref, in register. So you can get it out as a string by using register, or as an integer by using unpack like this: my ($ctr, undef) = unpack "La*", $cipher->{register}. If you wanted to put it into a new object, you could probably just set that object's register property. Subclassing would be a slightly more elegant way to do this, but any way you slice it, this is a hack, and could change under your feet since it's not an official part of the interface. But, it should work well enough to test, and make the case to the module author that an interface to the counter should be exposed.

      Generally you shouldn't need to get the counter out. What are you doing that requires that?