clrghouz/app/Traits/CRC.php

36 lines
834 B
PHP

<?php
namespace App\Traits;
trait CRC
{
private function CRC16USD_UPDATE($b,$crc): int
{
return (self::crc16usd_tab[(($crc >> 8) ^ $b) & 0xff] ^ (($crc & 0x00ff) << 8)) & 0xffff;
}
private function CRC32_FINISH($crc)
{
return ~$crc & 0xffffffff;
}
private function CRC32_UPDATE($b,$crc)
{
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;
}
private function LSZ_FINISH_CRC($crc)
{
return ($this->ls_Protocol & self::LSZ_OPTCRC32) ? $this->CRC32_FINISH($crc) : $crc;
}
private function LSZ_UPDATE_CRC($b,$crc)
{
return ($this->ls_Protocol & self::LSZ_OPTCRC32) ? $this->CRC32_UPDATE($b,$crc) : $this->CRC16USD_UPDATE($b,$crc);
}
}