

Task

Demonstrate a method of deriving the Cyclic Redundancy Check from within the language.



The result should be in accordance with ISO 3309, ITU-T V.42, Gzip and PNG.

Algorithms are described on Computation of CRC in Wikipedia.
This variant of CRC-32 uses LSB-first order, sets the initial CRC to FFFFFFFF16, and complements the final CRC.

For the purpose of this task, generate a CRC-32 checksum for the ASCII encoded string:

 The quick brown fox jumps over the lazy dog


 
Module CheckIt {
      Function PrepareTable {
            Dim Base 0, table(256)
            For i = 0 To 255 {
                    k = i
                    For j = 0 To 7 {
                              If binary.and(k,1)=1 Then {
                                  k =binary.Xor(binary.shift(k, -1) ,  0xEDB88320)
                              }  Else k=binary.shift(k, -1)
                    }
                    table(i) = k
             }
             =table()      
      }       
      crctable=PrepareTable()
      crc32= lambda crctable (buf$) -> {
                crc =0xFFFFFFFF
                For i = 0 To Len(buf$) -1
                     crc = binary.xor(binary.shift(crc, -8), array(crctable, binary.xor(binary.and(crc, 0xff), asc(mid$(buf$, i+1, 1)))))
                Next i
                =0xFFFFFFFF-crc       
      }
      Print crc32("The quick brown fox jumps over the lazy dog")=0x414fa339
}
CheckIt
 