+#! /usr/bin/perl
+
+if (@ARGV != 1) {
+ print STDERR "pad, for padding a file out to an even block size\n";
+ print STDERR "usage: pad BLOCKSIZE < INPUT > OUTPUT\n\n";
+ print STDERR "pad copies its input to its output, then writes\n";
+ print STDERR "zeroes to its output as necessary to make the\n";
+ print STDERR "output size an even multiple of BLOCKSIZE bytes\n";
+ exit 1;
+}
+
+$blocksize = $ARGV[0];
+$input_size = 0;
+while (read (STDIN, $input, 4096)) {
+ $input_size += length ($input);
+ print $input;
+}
+
+$odd_bytes = $input_size % $blocksize;
+print "\0" x ($blocksize - $odd_bytes) if $odd_bytes != 0;