I’ve searched Stackoverflow already and unfortunately nothing came up. I am working with the FIX protocol and I need to generate a Modulo 256 checksum as described at http://fixwiki.fixprotocol.org/fixwiki/CheckSum.
$count = strlen($message);
$count = $count % 256;
$checksum = 256 - $count;
if(strlen($checksum) == 1) {
$checksum = '00' . $checksum;
}
if(strlen($checksum) == 2) {
$checksum = '0' . $checksum;
}
Using the FIX string of:
8=FIX.4.2|9=42|35=0|49=A|56=B|34=12|52=20100304-07:59:30
It should return:
8=FIX.4.2|9=42|35=0|49=A|56=B|34=12|52=20100304-07:59:30|10=185|
However my script returns:
8=FIX.4.2|9=42|35=0|49=A|56=B|34=12|52=20100304-07:59:30|10=199|
I’d be grateful if someone could point me in the right direction!
According to http://fixwiki.fixprotocol.org/fixwiki/CheckSum the checksum isn’t just the length of the message modulo 256.
It’s the sum of each character (as ascii value) modulo 256.
prints
or to stay closer to the example function in the documentation