#!/usr/local/bin/perl -w
# much faster version of xorpad.pl
# This program is in the public domain.

use strict;
use constant BUFFER_SIZE => 4096;

my %files;

foreach my $file (@ARGV) {
	local *FH;
	open(FH, "<$file") or die "Can't open $file: $!\n";
	$files{$file} = *FH;
}
for (my $i=0; $i < 128*1024/BUFFER_SIZE; $i++) {
	my $outbuf;
	foreach my $file (keys %files) {
		my $buffer;
		my $count = read($files{$file}, $buffer, BUFFER_SIZE);
		die "Error reading from $file: $!\n" unless defined $count;
		$buffer .= "\000" x (BUFFER_SIZE - $count)
			if $count < BUFFER_SIZE; # padding
		$outbuf ^= $buffer;
	}
	print $outbuf;
}

exit 0;
#eof. This file has not been truncate
