At long last (thanks to a lot of help from Kitty Hello - you're a legend!!!) , I now have CRC calculation functions that work correctly. I'm also rather proud of it as it's my first bit of inline code. It's a porting of the "GetCRC" code by Dirk Stöcker with a few additions. The original has been modified to use Kitty Hello's file reading function, and I've written a HEX conversion function as most utilities seem to report the results in HEX format.
It supports the following functions (listed are the routine and some of the utilities that use them)
CRC-16 1 : PCompress2, Arc, DMS, ProPack, LhA, Zoo, Shrink
CRC-16 2 : CCITT, XModem, LU
CRC-16 3 : Donald Kindred's CRC
CRC-16 4 : old Zoom, CompDisk
CRC-32 1 : Olaf Barthel's CRC, PCompress, Zoom 5, LhPak
CRC-32 2 : Zip, GZip, LZX, RAR, Arj
CRC-32 3 : Brik (Binary mode), Ace
CRC-32 4 : GPatch (old)
CRC-32 5 : BZip2
CRC-32 6 : BZip2 inverted
CRC-32 7 : chksum utility
CHS-16 1 : PowerPacker Passwords
CHS-16 2 : BSD sum
CHS-16 3 : SYSV sum
CHS-32 1M (WRAP) : Olaf Barthel's CRC, Bootblock of OFS/FFS
CHS-32 1I :
CHS-32 2 : LightFileSystem
EOR Byte :
EOR Word (M/I) :
EOR Long (M/I) : ByteKiller, RSI-Packer
Sum Byte Signed :
Sum Byte Unsigned : SQ
Sum Word Si (M/I) :
Sum Word Un (M/I) :
Sum Long M : Root-, Bitmap-, File-, Datablock of OFS/FFS
Sum Long I :
SHA1
The following would be supported if I knew a bit more about how to do inline code. It only requires either importing a few commands from some standard (external) C libraries like stdio.h (commands like memcpy) or providing the same functionality through GLBasic commands. I've commented the code out in case anyone wants to get the MD4/MD5 code working.
MD4 : EDonkey, Samba
MD5 :
I'd also put this in a library if I knew how to get a GLBasic library working properly with inline calls to functions, but it all works as is regardless. Chop out any of the computation functions that aren't relevant to you to streamline the code.
Usage
NOTE : The file you want to process must be able to fit totally within memory.
The inline "extern" block MUST go before you use any functions or you'll get errors about the function name not being "declared in this scope".
Example usage
ReadFile("C:/temp/a.txt", CRCBuffer$) // Read file into buffer
StringLength=LEN(CRCBuffer$) // Calculate its length
//
// CRC example - Calculate CRC32 according to IEEE802.3 standard
//
INLINE
CRCValue = DoCRC32_2((const unsigned char*)CRCBuffer_Str.c_str(), StringLength);
ENDINLINE
DEBUG "CRCValue2 = "+Convert_CRC_To_Hex$(CRCValue)+"\n"
//
// SHA1 example - Calculate SHA1 value for the file
//
GLOBAL SHA1ResultArray#[]
DIM SHA1ResultArray#[20]
INLINE
unsigned char Result[20];
sha1((const unsigned char*)CRCBuffer_Str.c_str(), StringLength, Result);
int Loop;
for (Loop=0;Loop<20;Loop++)
SHA1ResultArray(Loop) = Result[Loop];
ENDINLINE
DEBUG "SHA1 result = "
FOR Loop = 0 TO 19
DEBUG Convert_SHA_To_Hex$(SHA1ResultArray[Loop])
NEXT
The code is attached.
[attachment deleted by admin]