Lewis_P@cc.curtin.edu.au (Peter Lewis) (12/05/90)
Hi All, Could someone tell me how the CRC is calculated in a BinHex 4.0 encoded file? I know the format of .hqx files, and I can decode them, but I can't calculate and check the CRCs. Any information on this would be greatly appreciated, Peter. -- Disclaimer:Curtin & I have an agreement:Neither of us listen to either of us. *-------+---------+---------+---------+---------+---------+---------+-------* Internet: Lewis_P@cc.curtin.edu.au I Peter Lewis ACSnet: Lewis_P@cc.cut.oz.au I NCRPDA, Curtin University Bitnet: Lewis_P%cc.curtin.edu.au@cunyvm.bitnet I GPO Box U1987 UUCP: uunet!munnari.oz!cc.curtin.edu.au!Lewis_P I Perth, WA, 6001, AUSTRALIA ResEdit 2.0 is great, but if your sick of seeing the about box every launch - Hack: ResEdit ResEdit 2.0b2, change CODE=5, 00091C: 4EBA 02A4 to 4E71 4E71
physi-hf@garnet.berkeley.edu (Howard Haruo Fukuda) (12/06/90)
In article <5063.275cde88@cc.curtin.edu.au> Lewis_P@cc.curtin.edu.au (Peter Lewis) writes: >Hi All, > Could someone tell me how the CRC is calculated in a BinHex 4.0 encoded >file? I know the format of .hqx files, and I can decode them, but I can't >calculate and check the CRCs. > >Any information on this would be greatly appreciated, > Peter. BinHex 4.0 uses a 16-bit CRC with a 0x1021 seed. The general algorithm is to take data 1 bit at a time and process it through the following: 1) Take the old CRC (use 0x0000 if there is no previous CRC) and shift it to the left by 1. 2) Put the new data bit in the least significant position (right bit). 3) If the bit shifted out in (1) was a 1 then xor the CRC with 0x1021. 4) Loop back to (1) until all the data has been processed. You should be careful that when BinHex has a 2 Byte location for the CRC (such as at then end of the header), you should feed in 2 bytes of 0x00 before you compare the CRCs. -Howard