in reply to Re: xor encrypt-decrypt routine
in thread xor encrypt-decrypt routine

The newline chars in the file should be encrypted/decrypted with everything else. Using the >= operator instead of > is probably a good idea, as whilst doing a little "print debugging" I found that there was a NULL or something at the end of the $key variable. That didn't seem to fix it, but oddly enough I seem to get much better results when I use the following loop:
while(my $char = getc(IN)) { if($kp >= length($key)) { $kp = 0; } my $kc = substr($key, $kp++, 0); $char ^= $kc; print OUT $char; }
That encrypts/decrypts perfectly, but seems to end abruptly after running through 1k of data. Now I'm even more confused. What's the difference between this code and the code I posted before?

Replies are listed 'Best First'.
(tye)Re2: xor encrypt-decrypt routine
by tye (Sage) on Jan 21, 2001 at 10:06 UTC

    You probably finally hit a point that encrypts to a CTRL-Z which is end-of-file under Windows unless you use binmode as I suggested below.

            - tye (but my friends call me "Tye")