0 Replies Latest reply on Jun 8, 2009 2:01 PM by detangleit

    Generating a cyclical redundancy check

    detangleit

      Title

      Generating a cyclical redundancy check

      Post

      I need to generate standard 8-bit CRC from a user-modified number field.  Does anyone know of a plugin or other solution to do this?  Below is PHP source code that does the job, but I need to build this into a Filemaker database, or somehow process the number field Externally and capture the result.  I also have source code written in C if that can be of any use.  Any help would be greatly appreciated. 

       

      <?
      function computeCrc($slideId) {
       $policy = 0x25;
       $crc = 0x0;
       
       $table = array();
       
       /* setup crc table */
       for ( $i = 0; $i < 256; $i++ ) {
        $accum = $i;
        
        for ( $j = 0; $j < 8; $j++ ) {
         if ( $accum & 0x80 ) {
          $accum = ( $accum << 1 ) ^ $policy;
         } else {
          $accum = ( $accum << 1 );
         }
        }
        
        $table[$i] = $accum % 256;
       }
       
       /* calculate crc*/
       $l = strlen($slideId);
       
       for ( $i = 0; $i < $l; $i++ ) {
        $c = ord(substr($slideId, $i, 1));
        $t = ( $crc ^ $c ) & 0xFF;

        $crc = ( $crc << 8 ) ^ $table[$t];
        $crc = $crc % 256;
       }
       
       return($crc);
      }


      ?>
      <HTML><BODY>
      <h2>CRC Test</H2>
      <FORM METHOD=GET ACTION="crc.php">
      Slide Id: <INPUT TYPE=TEXT NAME="id" VALUE="<?= htmlspecialchars($_REQUEST['id']) ?>">
      <INPUT TYPE="SUBMIT" VALUE="Calculate CRC">
      </FORM>
      <P>
      <?
      if ( isset($_REQUEST['id']) ) {
       $crc = computeCrc($_REQUEST['id']);
       print "The CRC is: " . $crc;
      }
       
      ?>
      </BODY></HTML>