|
crc-32
Jul 18, 2019 16:23:38 GMT -5
Post by blametroi on Jul 18, 2019 16:23:38 GMT -5
I wanted to create a hash on a file and figured I'd use a CRC. After some research I was beginning to think I should be using another language for what I was doing (bit shifts), but then I found out there's a CRC-32 API call in windows. Stealing the idea from rosettacode, here's a LB example of calculating a CRC-32 on a string in case anyone is interested.
' crc32.bas - attempt to use the rtlComputeCrc32 function from nt.dll ' on windows. '
' borrowing from the vb example on https://rosettacode.org/wiki/CRC-32
' In ntdll.dll we have: ' ' RtlComputeCrc32( byval initial as Long, pdata as Any, byval ilen as long) as long ' ' crc32 of "The quick brown fox jumps over the lazy dog" should be ' &H414FA339, is it?
s$ = "The quick brown fox jumps over the lazy dog" ls = len(s$)
print "calculating crc-32 of : "; s$ print "expected crc-32 is : "; dechex$(hexdec("&H414FA339"))
open "ntdll.dll" for dll as #ntdll calldll #ntdll, "RtlComputeCrc32", 0 as long, s$ as ptr, ls as long, result as long close #ntdll
print "calculated crc-32 is : "; dechex$(result)
if result = hexdec("&H414FA339") then print "crc-32 calculated correctly" else print "crc-32 calculated is incorrect!" end if
print print "done"
|
|