M CRC32 calculates a cyclic redundancy code (CRC), known as CRC-32, using  a byte-wise algorithm.  (B Is reportedly used in PKZip, AUTODIN II, Ethernet, and FDDI. 23 Polynomial used to create table is &04C11DB7 < FL (C) Copyright 1989, 1995-1996, 1998 Earl F. Glynn, Overland Park, KS. P All Rights Reserved. Z dF This UNIT was derived from the CRCT FORTRAN 77 program given in nK "Byte-wise CRC Calculations" by Aram Perez in IEEE Micro, June 1983, xN pp. 40-50. The constants here are for the CRC-32 generator polynomial, K as defined in the Microsoft Systems Journal, March 1995, pp. 107-108  Z This CRC algorithm emphasizes speed at the expense of the 256-element lookup table.  4 Modified 3/20/98 to work in Delphi 1, 2 or 3. @ Modified 11/29/98 to avoid compiler warnings in Delphi 4. G Translated into BBC BASIC 26/2/99 from Delphi code obtained from 3 http://www.efg2.com/lab/Mathematics/CRC.htm : ` As a check, the CRC32 of a file containing just the string "123456789" should be &CBF43926 :  initCRC32table  buffSize%=4096 B buff% buffSize%-1 : Buffer to store data read from file ! "Enter Filename: ";name$ > "CRC is: &";~(calcFileCRC32(name$,buff%,buffSize%)) " ,: 60 initCRC32table: Create the lookup table @ Table%(255) Jd Table%(0) =&00000000 : Table%(1) =&77073096 : Table%(2) =&EE0E612C : Table%(3) =&990951BA Td Table%(4) =&076DC419 : Table%(5) =&706AF48F : Table%(6) =&E963A535 : Table%(7) =&9E6495A3 ^d Table%(8) =&0EDB8832 : Table%(9) =&79DCB8A4 : Table%(10) =&E0D5E91E : Table%(11) =&97D2D988 hd Table%(12) =&09B64C2B : Table%(13) =&7EB17CBD : Table%(14) =&E7B82D07 : Table%(15) =&90BF1D91 rd Table%(16) =&1DB71064 : Table%(17) =&6AB020F2 : Table%(18) =&F3B97148 : Table%(19) =&84BE41DE |d Table%(20) =&1ADAD47D : Table%(21) =&6DDDE4EB : Table%(22) =&F4D4B551 : Table%(23) =&83D385C7 d Table%(24) =&136C9856 : Table%(25) =&646BA8C0 : Table%(26) =&FD62F97A : Table%(27) =&8A65C9EC d Table%(28) =&14015C4F : Table%(29) =&63066CD9 : Table%(30) =&FA0F3D63 : Table%(31) =&8D080DF5 d Table%(32) =&3B6E20C8 : Table%(33) =&4C69105E : Table%(34) =&D56041E4 : Table%(35) =&A2677172 d Table%(36) =&3C03E4D1 : Table%(37) =&4B04D447 : Table%(38) =&D20D85FD : Table%(39) =&A50AB56B d Table%(40) =&35B5A8FA : Table%(41) =&42B2986C : Table%(42) =&DBBBC9D6 : Table%(43) =&ACBCF940 d Table%(44) =&32D86CE3 : Table%(45) =&45DF5C75 : Table%(46) =&DCD60DCF : Table%(47) =&ABD13D59 d Table%(48) =&26D930AC : Table%(49) =&51DE003A : Table%(50) =&C8D75180 : Table%(51) =&BFD06116 d Table%(52) =&21B4F4B5 : Table%(53) =&56B3C423 : Table%(54) =&CFBA9599 : Table%(55) =&B8BDA50F d Table%(56) =&2802B89E : Table%(57) =&5F058808 : Table%(58) =&C60CD9B2 : Table%(59) =&B10BE924 d Table%(60) =&2F6F7C87 : Table%(61) =&58684C11 : Table%(62) =&C1611DAB : Table%(63) =&B6662D3D  d Table%(64) =&76DC4190 : Table%(65) =&01DB7106 : Table%(66) =&98D220BC : Table%(67) =&EFD5102A d Table%(68) =&71B18589 : Table%(69) =&06B6B51F : Table%(70) =&9FBFE4A5 : Table%(71) =&E8B8D433 d Table%(72) =&7807C9A2 : Table%(73) =&0F00F934 : Table%(74) =&9609A88E : Table%(75) =&E10E9818 d Table%(76) =&7F6A0DBB : Table%(77) =&086D3D2D : Table%(78) =&91646C97 : Table%(79) =&E6635C01 d Table%(80) =&6B6B51F4 : Table%(81) =&1C6C6162 : Table%(82) =&856530D8 : Table%(83) =&F262004E &d Table%(84) =&6C0695ED : Table%(85) =&1B01A57B : Table%(86) =&8208F4C1 : Table%(87) =&F50FC457 0d Table%(88) =&65B0D9C6 : Table%(89) =&12B7E950 : Table%(90) =&8BBEB8EA : Table%(91) =&FCB9887C :d Table%(92) =&62DD1DDF : Table%(93) =&15DA2D49 : Table%(94) =&8CD37CF3 : Table%(95) =&FBD44C65 Dd Table%(96) =&4DB26158 : Table%(97) =&3AB551CE : Table%(98) =&A3BC0074 : Table%(99) =&D4BB30E2 Nd Table%(100)=&4ADFA541 : Table%(101)=&3DD895D7 : Table%(102)=&A4D1C46D : Table%(103)=&D3D6F4FB Xd Table%(104)=&4369E96A : Table%(105)=&346ED9FC : Table%(106)=&AD678846 : Table%(107)=&DA60B8D0 bd Table%(108)=&44042D73 : Table%(109)=&33031DE5 : Table%(110)=&AA0A4C5F : Table%(111)=&DD0D7CC9 ld Table%(112)=&5005713C : Table%(113)=&270241AA : Table%(114)=&BE0B1010 : Table%(115)=&C90C2086 vd Table%(116)=&5768B525 : Table%(117)=&206F85B3 : Table%(118)=&B966D409 : Table%(119)=&CE61E49F d Table%(120)=&5EDEF90E : Table%(121)=&29D9C998 : Table%(122)=&B0D09822 : Table%(123)=&C7D7A8B4 d Table%(124)=&59B33D17 : Table%(125)=&2EB40D81 : Table%(126)=&B7BD5C3B : Table%(127)=&C0BA6CAD  d Table%(128)=&EDB88320 : Table%(129)=&9ABFB3B6 : Table%(130)=&03B6E20C : Table%(131)=&74B1D29A d Table%(132)=&EAD54739 : Table%(133)=&9DD277AF : Table%(134)=&04DB2615 : Table%(135)=&73DC1683 d Table%(136)=&E3630B12 : Table%(137)=&94643B84 : Table%(138)=&0D6D6A3E : Table%(139)=&7A6A5AA8 d Table%(140)=&E40ECF0B : Table%(141)=&9309FF9D : Table%(142)=&0A00AE27 : Table%(143)=&7D079EB1 d Table%(144)=&F00F9344 : Table%(145)=&8708A3D2 : Table%(146)=&1E01F268 : Table%(147)=&6906C2FE d Table%(148)=&F762575D : Table%(149)=&806567CB : Table%(150)=&196C3671 : Table%(151)=&6E6B06E7 d Table%(152)=&FED41B76 : Table%(153)=&89D32BE0 : Table%(154)=&10DA7A5A : Table%(155)=&67DD4ACC d Table%(156)=&F9B9DF6F : Table%(157)=&8EBEEFF9 : Table%(158)=&17B7BE43 : Table%(159)=&60B08ED5 d Table%(160)=&D6D6A3E8 : Table%(161)=&A1D1937E : Table%(162)=&38D8C2C4 : Table%(163)=&4FDFF252 d Table%(164)=&D1BB67F1 : Table%(165)=&A6BC5767 : Table%(166)=&3FB506DD : Table%(167)=&48B2364B d Table%(168)=&D80D2BDA : Table%(169)=&AF0A1B4C : Table%(170)=&36034AF6 : Table%(171)=&41047A60  d Table%(172)=&DF60EFC3 : Table%(173)=&A867DF55 : Table%(174)=&316E8EEF : Table%(175)=&4669BE79 d Table%(176)=&CB61B38C : Table%(177)=&BC66831A : Table%(178)=&256FD2A0 : Table%(179)=&5268E236  d Table%(180)=&CC0C7795 : Table%(181)=&BB0B4703 : Table%(182)=&220216B9 : Table%(183)=&5505262F *d Table%(184)=&C5BA3BBE : Table%(185)=&B2BD0B28 : Table%(186)=&2BB45A92 : Table%(187)=&5CB36A04 4d Table%(188)=&C2D7FFA7 : Table%(189)=&B5D0CF31 : Table%(190)=&2CD99E8B : Table%(191)=&5BDEAE1D > Hd Table%(192)=&9B64C2B0 : Table%(193)=&EC63F226 : Table%(194)=&756AA39C : Table%(195)=&026D930A Rd Table%(196)=&9C0906A9 : Table%(197)=&EB0E363F : Table%(198)=&72076785 : Table%(199)=&05005713 \d Table%(200)=&95BF4A82 : Table%(201)=&E2B87A14 : Table%(202)=&7BB12BAE : Table%(203)=&0CB61B38 fd Table%(204)=&92D28E9B : Table%(205)=&E5D5BE0D : Table%(206)=&7CDCEFB7 : Table%(207)=&0BDBDF21 pd Table%(208)=&86D3D2D4 : Table%(209)=&F1D4E242 : Table%(210)=&68DDB3F8 : Table%(211)=&1FDA836E zd Table%(212)=&81BE16CD : Table%(213)=&F6B9265B : Table%(214)=&6FB077E1 : Table%(215)=&18B74777 d Table%(216)=&88085AE6 : Table%(217)=&FF0F6A70 : Table%(218)=&66063BCA : Table%(219)=&11010B5C d Table%(220)=&8F659EFF : Table%(221)=&F862AE69 : Table%(222)=&616BFFD3 : Table%(223)=&166CCF45 d Table%(224)=&A00AE278 : Table%(225)=&D70DD2EE : Table%(226)=&4E048354 : Table%(227)=&3903B3C2 d Table%(228)=&A7672661 : Table%(229)=&D06016F7 : Table%(230)=&4969474D : Table%(231)=&3E6E77DB d Table%(232)=&AED16A4A : Table%(233)=&D9D65ADC : Table%(234)=&40DF0B66 : Table%(235)=&37D83BF0 d Table%(236)=&A9BCAE53 : Table%(237)=&DEBB9EC5 : Table%(238)=&47B2CF7F : Table%(239)=&30B5FFE9 d Table%(240)=&BDBDF21C : Table%(241)=&CABAC28A : Table%(242)=&53B39330 : Table%(243)=&24B4A3A6 d Table%(244)=&BAD03605 : Table%(245)=&CDD70693 : Table%(246)=&54DE5729 : Table%(247)=&23D967BF d Table%(248)=&B3667A2E : Table%(249)=&C4614AB8 : Table%(250)=&5D681B02 : Table%(251)=&2A6F2B94 d Table%(252)=&B40BBE37 : Table%(253)=&C30C8EA1 : Table%(254)=&5A05DF1B : Table%(255)=&2D02EF8D  : G The following is a little cryptic (but executes very quickly). % The algorithm is as follows: g 1. exclusive-or the input byte with the low-order byte of the CRC register to get an INDEX k 2. shift the CRC register eight bits to the right (Use >>> for unsigned integer instead of >>) $O 3. exclusive-or the CRC register with the contents of Table[INDEX] .7 4. repeat steps 1 through 3 for all bytes} 8 : B# calcCRC32(addr%,num%, crc%) L i% V i%=0 num%-1 `= crc%=(crc% >>> 8) Table%(addr%?i% (crc% &FF)) j t ~: N calcFileCRC32(name$,buff%,buffSize%): Calculate CRC-32 for file name$ D Read maximum of buffSize% bytes from file into buffer buff% 4 Store number of bytes actually read in num% 9 num%,crcValue%,f% : num%=0 : crcValue%=&FFFFFFFF  f%=(name$)  f%<>0  7 ș "OS_GBPB",4,f%,buff%,buffSize% ,,num% F num%-=buff% : Calculate the number of bytes transferred 8 num%>0 calcCRC32(buff%,num%,crcValue%)  num%=0  #f%   =(crcValue%)