in reply to Re: Mod-2 add 2 binary files
in thread Mod-2 add 2 binary files
Now let's try it:use warnings; use strict; @ARGV or die "Usage: cipher keyfile < source > dest\n"; open K,shift or die "Can't open keyfile: $!\n"; undef $/; my $k = <K>; close K; # slurp length $k or die "error reading key file\n"; while (read STDIN, my $t, length $k) { my @k = unpack "C*", $k; print pack "C*", map { $_^shift @k } unpack "C*", $t; }
# make a key file, ok for demo purposes $ perl -e 'print chr int rand 256 for 0..10000' > key.file # make a test source file $ ls -al /dev > plain.txt # encipher $ perl cipher.pl key.file < plain.txt > cipher.txt # decipher $ perl cipher.pl key.file < cipher.txt > deciphered.txt # verify $ diff -s plain.txt deciphered.txt Files plain.txt and deciphered.txt are identical
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Mod-2 add 2 binary files
by thor (Priest) on May 19, 2004 at 11:56 UTC |