Created
July 30, 2015 14:09
-
-
Save rgchris/d981107b44741cb63eca to your computer and use it in GitHub Desktop.
Calculate a CRC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rebol [ | |
Title: "Make CRC" | |
Date: 25-May-2015 | |
Author: "Christopher Ross-Gill" | |
] | |
shift32: func [value [integer!] bits [integer!] /logical][ | |
apply :shift [to integer! #{00000000FFFFFFFF} and to binary! value bits logical] | |
] | |
make-crc: use [legacy-table crc-table crc][ | |
crc-table: new-line/all collect [ | |
repeat n 256 [ | |
crc: n - 1 | |
loop 8 [ | |
crc: either equal? 1 crc and 1 [ | |
-306674912 xor shift32/logical crc -1 | |
][ | |
shift32/logical crc -1 | |
] | |
] | |
keep crc | |
] | |
] false | |
func [chk [binary!]][ | |
crc: -1 | |
foreach byte chk [ | |
byte: crc xor byte and 255 + 1 | |
crc: crc-table/:byte xor shift32/logical crc -8 | |
] | |
remove/part to binary! crc xor -1 4 | |
] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment