Page 1 of 1

Adler32 crc generator

Posted: Tue Aug 01, 2023 12:22 am
by jacdelad
Hi,
here's an Adler32-crc-generator. I hope I got it right.

Code: Select all

#Mod_Adler = 65521
Procedure.l Adler32(*Buffer,BufferSize)
  Protected a.l=1,b.l,c.i,d.i=*Buffer+BufferSize-1
  For c=*Buffer To d
    a=(a+PeekA(c)) % #Mod_Adler
    b=(b+a) % #Mod_Adler
  Next
  ProcedureReturn (b << 16) | a
EndProcedure

CompilerIf #PB_Compiler_IsMainFile
  Define *Test=AllocateMemory(1024),t
  For t=0 To MemorySize(*Test)-1
    PokeA(*Test+t,Random(255,0))
  Next
  Debug Hex(Adler32(*Test,MemorySize(*Test)) & $FFFFFFFF)
CompilerEndIf
According to Wikipedia it should be faster than CRC32, but isn't as reliable as it. Also, short memory blocks (up to several hundred bytes) tend to be problematic.

However, that's the easiest implementation. There's obviously a better one, but I have to admit that I didn't understand the concept how it works (and this one should be the fast one). Maybe someone wants to add this:
https://en.wikipedia.org/wiki/Adler-32