clrghouz/app/Traits/CRC.php

41 lines
984 B
PHP
Raw Permalink Normal View History

2021-04-01 10:59:15 +00:00
<?php
namespace App\Traits;
trait CRC
{
2021-08-21 11:15:22 +00:00
private function CRC16USD_UPDATE(int $b,int $crc): int
2021-04-01 10:59:15 +00:00
{
return (self::crc16usd_tab[(($crc >> 8) ^ $b) & 0xff] ^ (($crc & 0x00ff) << 8)) & 0xffff;
}
private function CRC32_CR(int $c,int $b)
{
return (self::crc32_tab[((int)($c) ^ ($b)) & 0xff] ^ (($c) >> 8));
}
2021-08-21 11:15:22 +00:00
private function CRC32_FINISH(int $crc)
2021-04-01 10:59:15 +00:00
{
return ~$crc & 0xffffffff;
}
2021-08-21 11:15:22 +00:00
private function CRC32_UPDATE(int $b,int $crc)
2021-04-01 10:59:15 +00:00
{
return ((self::crc32_tab[($crc^$b) & 0xff] ^ (($crc>>8) & 0x00ffffff)) & 0xffffffff);
}
private function LSZ_INIT_CRC()
{
return ($this->ls_Protocol & self::LSZ_OPTCRC32) ? self::LSZ_INIT_CRC32 : self::LSZ_INIT_CRC16;
}
2021-08-21 11:15:22 +00:00
private function LSZ_FINISH_CRC(int $crc)
2021-04-01 10:59:15 +00:00
{
return ($this->ls_Protocol & self::LSZ_OPTCRC32) ? $this->CRC32_FINISH($crc) : $crc;
}
2021-08-21 11:15:22 +00:00
private function LSZ_UPDATE_CRC(int $b,int $crc)
2021-04-01 10:59:15 +00:00
{
return ($this->ls_Protocol & self::LSZ_OPTCRC32) ? $this->CRC32_UPDATE($b,$crc) : $this->CRC16USD_UPDATE($b,$crc);
}
}