XOR on string
Peter Hansen
peter at engcorp.com
Wed Jan 26 15:57:17 EST 2005
snacktime wrote:
> I need to calculate the lrc of a string using an exclusive or on each
> byte in the string. How would I do this in python?
lrc == Linear Redundancy Check? or Longitudinal? Note that
such terms are not precisely defined... generally just acronyms
people make up and stick in their user manuals for stuff. :-)
import operator
lrc = reduce(operator.xor, [ord(c) for c in string])
Note that this returns an integer, so if you plan
to send this as a byte or compare it to a character
received, use chr(lrc) on it first.
-Peter
More information about the Python-list
mailing list