in reply to xor encrypt-decrypt routine
You should use binmode() on your input and output. This might explain your problem. I'd also not read "a line at a time" since during decryption the line endings will be encrypted. No other errors pop out at me so give that a try.
You can tell you converted this from C code. Perl will let you xor entire strings so you could make this faster and simpler, something like:
#!/usr/bin/perl -w use strict; if(@ARGV < 3) { print "Usage: $0 <key> <input file> <output file>\n"; exit(0); } my $key = $ARGV[0]; open(IN, $ARGV[1]) or die "Can't read $ARGV[1]: $!\n"; open(OUT, ">$ARGV[2]") or die "Can't wrote $ARGV[2]: $!\n"; binmode(IN); binmode(OUT); my $in; while( sysread(IN,$in,length($key)) ) { print OUT $in^substr($key,0,length($in)); } close(IN); close(OUT);
I tested this and it works for me.
Update: I tested your code under Win98 and the first part of the file decrypted properly and then it fell apart. Looking at the encrypted file I find that the description fell apart at the first character that got encrypted into a newline. So I may have actually diagnosed the problem correctly.
Also, interestingly enough, when I was in college and worked for their computer department, I helped investigate some cracking that a student was doing. The student had encrypted the source code to their tools using something very much like this. They didn't keep the encrypt/decrypt source code on their account. So working with just the contents of some files, I was able to decrypt their files using fairly simple techniques. So don't consider this simple xoring as other than a very insecure obscuring and not really encrypting.
- tye (but my friends call me "Tye"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (tye)Re: xor encrypt-decrypt routine
by 2501 (Pilgrim) on Jan 23, 2001 at 02:33 UTC | |
by tye (Sage) on Jan 23, 2001 at 04:07 UTC |