Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' Was looking for a good checksum algorithm which was faster than CRC16 and stumbled upon Adler32
- ' Adler32 unfortunately was 32 bits, so I thought I could throw a 16 bit version together given some info
- ' from the wikipedia page: https://en.wikipedia.org/wiki/Adler-32
- ' NOTE: This is completely my attempt at implementing Adler32 at 16bits, use at your on risk.
- ' On a good note, this implementation doesn't have any collisions (when input is also 16bits)
- ' Fast Version
- Public Shared Function Adler16fast(ByVal Data() As Byte) As UShort
- Dim A As UShort = 1, B As ULong = 0
- For i As Integer = 0 To Data.Length - 1
- A = A Xor Data(i)
- B += A
- Next
- Return (CUShort(B Mod 256) << 8) Or A
- End Function
- ' Original POC Version
- Public Shared Function Adler16(ByVal Data() As Byte) As UShort
- Dim A As UShort = 1, B As UShort = 0
- For Each D As Byte In Data
- A = (A + D) Mod 256
- B = (A + B) Mod 256
- Next
- Return (B << 8) Or A
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement