krot

CRC16-Algorithm

Jun 3rd, 2016
70
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function crc16($string) {
  2.   $crc = 0xFFFF;
  3.   for ($x = 0,$len=strlen ($string); $x < $len; $x++) {
  4.     $crc^=ord($string[$x]);
  5.     for($y=0;$y<8;$y++) {
  6.       if (($crc&0x0001)==0x0001){
  7.         $crc = (($crc >> 1) ^ 0xA001);
  8.       } else { $crc >>= 1; }
  9.     }
  10.   }
  11.   return $crc;
  12. }
RAW Paste Data