in reply to Re: XOR checksum for string of bytes
in thread XOR checksum for string of bytes
Just to add, the XOR operator will only work on numeric datatypes. A slight change to t. alex's code would be:
$Result ^= ord($_);
but then again, not knowing the packet format, you may have to pack the data and then unpack the bytes and roll through it that way.
Update My apologies t. alex, Just as Juerd pointed out, you can XOR strings! The problem was setting $Result to 0 and then trying to XOR that with a string causes problems. So you could set $Result to "" but then $Result will have a PV value and not an IV (but as long as you know that ... )
Moral: Mixing numerics, strings, and XOR will not produce the desired results (oh and use -w).
-derby
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (3): XOR checksum for string of bytes
by talexb (Chancellor) on Jan 10, 2002 at 20:12 UTC | |
|
Re: Re: Re: XOR checksum for string of bytes
by Juerd (Abbot) on Jan 10, 2002 at 20:20 UTC |