Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Custom 24bit(3bytes) checksum algorithm by TizzyT, based on Adler32.
- Public Class Myra24
- Const FlipBits As Byte = 170
- Public Shared Function Sum(ByVal Data() As Byte) As Integer
- Dim A As UShort = 1
- Dim T As UShort = 0
- Dim B As Integer = 0
- Dim Stage As Integer = 0
- For i = 0 To Data.Length - 1
- Select Case Stage
- Case 0
- T = CUShort(Data(i) Xor FlipBits) << 4
- Stage = 1
- If B > 2147471361 Then B = B Mod 2147471362
- Case 1
- T = ((Data(i) Xor FlipBits) >> 4) Or T
- A = (A + T) Mod 4096
- B += A
- T = CUShort((Data(i) Xor FlipBits) << 4) << 4
- Stage = 2
- Case 2
- T = T Or (Data(i) Xor FlipBits)
- A = (A + T) Mod 4096
- B += A
- Stage = 0
- End Select
- Next
- If Stage <> 0 Then
- A = (A + T) Mod 4096
- B += A
- End If
- Return ((B Mod 4096) << 12) Or A
- End Function
- Public Shared Function GetBytes(ByVal Data() As Byte) As Byte()
- Dim bytes As Byte() = BitConverter.GetBytes(Sum(Data))
- Return {bytes(0), bytes(1), bytes(2)}
- End Function
- End Class
- 'This is a version that swaps out most of the Mod operators for Xor operators for a little bit more speed. It doesn't pass the appended zeros test.
- Public Class Xyra24
- Public Shared Function GetBytes(ByVal Data() As Byte) As Byte()
- Dim bytes As Byte() = BitConverter.GetBytes(Sum(Data))
- Return {bytes(0), bytes(1), bytes(2)}
- End Function
- Public Shared Function Sum(ByVal Data() As Byte) As Integer
- Dim A As UShort = 1
- Dim T As UShort = 0
- Dim B As Integer = 0
- Dim Stage As Integer = 0
- For i = 0 To Data.Length - 1
- Select Case Stage
- Case 0
- T = CUShort(Data(i)) << 4
- Stage = 1
- If B > 2147471361 Then B = B Mod 2147471362
- Case 1
- T = CUShort(Data(i)) >> 4 Or T
- A = A Xor T
- B += A
- T = CUShort(Data(i) << 4) << 4
- Stage = 2
- Case 2
- T = T Or Data(i)
- A = A Xor T
- B += A
- Stage = 0
- End Select
- Next
- A = A Xor T
- B += A
- Return ((B Mod 4096) << 12) Or A
- End Function
- End Class
Advertisement
Add Comment
Please, Sign In to add comment