Bitwise XOR on ASCII string

A few ideas
Are you sure your input is a string and not a buffer object (set of bytes)?

If your sure its a string then I'd change it to a buffer

var check_sum_string = Buffer.from( msg.payload, 'utf8' )

I'd use

var check_sum = 0

to initialise it as numeric

check_sum = check_sum_string[i] ^ check_sum_string[i+1];

looks a bit wrong on the logic front :slight_smile:

I'd try something like

check_sum = check_sum ^ check_sum_string[i]
1 Like