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";

In reply to Re: Reading two (2) file in byte[] form and then XOring them by sgifford
in thread Reading two (2) file in byte[] form and then XOring them by cik_ail

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.