Note that there are some explanatory texts on larger screens.

plurals
  1. POChecksum Algorithm Producing Unpredictable Results
    primarykey
    data
    text
    <p>I'm working on a checksum algorithm, and I'm having some issues. The kicker is, when I hand craft a "fake" message, that is substantially smaller than the "real" data I'm receiving, I get a correct checksum. However, against the real data - the checksum does not work properly.</p> <p>Here's some information on the incoming data/environment:</p> <ul> <li>This is a groovy project (see code below)</li> <li>All bytes are to be treated as unsigned integers for the purpose of checksum calculation <ul> <li>You'll notice some finagling with shorts and longs in order to make that work.</li> </ul></li> <li>The size of the real data is 491 bytes.</li> <li>The size of my sample data (which appears to add correctly) is 26 bytes</li> <li>None of my hex-to-decimal conversions are producing a negative number, as best I can tell</li> <li>Some bytes in the file are not added to the checksum. I've verified that the switch for these is working properly, and when it is supposed to - so that's not the issue.</li> <li>My calculated checksum, and the checksum packaged with the real transmission always differ by the same amount.</li> <li>I have manually verified that the checksum packaged with the real data is correct.</li> </ul> <p>Here is the code:</p> <pre><code>// add bytes to checksum public void addToChecksum( byte[] bytes) { //if the checksum isn't enabled, don't add if(!checksumEnabled) { return; } long previouschecksum = this.checksum; for(int i = 0; i &lt; bytes.length; i++) { byte[] tmpBytes = new byte[2]; tmpBytes[0] = 0x00; tmpBytes[1] = bytes[i]; ByteBuffer tmpBuf = ByteBuffer.wrap(tmpBytes); long computedBytes = tmpBuf.getShort(); logger.info(getHex(bytes[i]) + " = " + computedBytes); this.checksum += computedBytes; } if(this.checksum &lt; previouschecksum) { logger.error("Checksum DECREASED: " + this.checksum); } //logger.info("Checksum: " + this.checksum); } </code></pre> <p>If anyone can find anything in this algorithm that could be causing drift from the expected result, I would greatly appreciate your help in tracking this down.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload