0

I'm trying to figure out the checksum for certain messages, but I can not even get the github files from this link https://github.com/meetanthony/crcphp. In the site of the link above works, but when I run a test, no one was able to run the calc for CRC16 X25?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • The actual code is in the crc32 directory. Take a look at this [github link](https://github.com/meetanthony/crcphp/commit/dabeee9b6fe76e73340fda548f81ea9c53d75de2) . – rcgldr Mar 15 '19 at 02:26

1 Answers1

0

I discovered why I was wrong with my code, I was passing a number in hexadecimal and to calculate, I needed to convert from hexadecimal to decimal, follow function with adaptation ( hexdec($d) solved my problem):

public function ComputeCrc($crcParams, $data) {
    if ($crcParams->RefIn) {
        $crc = $crcParams->InvertedInit;
    } else {
        $crc = $crcParams->Init;
    }
    if ($crcParams->RefOut) {
        foreach ($data as $d) {
            $d = hexdec($d);
            echo "<br>".$d."<br>";
            $crc = $crcParams->Array[($d ^ $crc) & 0xFF] ^ ($crc >> 8 & 0xFF);
        }
    } else {
        foreach ($data as $d) {
            $crc = $crcParams->Array[(($crc >> 8) ^ $d) & 0xFF] ^ ($crc << 8);
        }
    }

    $crc = $crc ^ $crcParams->XorOut;

    $result = new CrcResult();
    $result->Crc = $crc & 0xFFFF;

    return $result;
}