Link to home
Start Free TrialLog in
Avatar of vigylant
vigylant

asked on

How to combine two CRC32 results

The thing is, i want to combine two calculated CRC32's...

Example:

The CRC32 of GetCRC32(New Byte() {1}) is 1526341860
The CRC32 of GetCRC32(New Byte() {2}) is -1007455906

Now, say i do not have access to the bytes (1 and 2) anymore, but i do have access to the CRC32 results (1526341860 and -1007455906).
Is it possible to combine these results as if the original calculation were GetCRC32(New Byte() {1, 2})?
Public Class Checksum
 
    Private CRC32Table(255) As Integer
 
    Public Sub New()
 
        Dim dwPolynomial As Integer = -306674912
        Dim j, dwCrc As Integer
 
        For i As Integer = 0 To 255
            dwCrc = i
            For j = 8 To 1 Step -1
                If (dwCrc And 1) Then
                    dwCrc = ((dwCrc And -2) \ 2&) And 2147483647
                    dwCrc = dwCrc Xor dwPolynomial
                Else
                    dwCrc = ((dwCrc And -2) \ 2&) And 2147483647
                End If
            Next j
            CRC32Table(i) = dwCrc
        Next
 
    End Sub
 
    Public Function GetCRC32(ByRef bt() As Byte) As Integer
 
        Dim CRC32Result As Integer = -1
        Dim iLookup As Integer
 
        For Each b As Byte In bt
 
            iLookup = (CRC32Result And 255) Xor b
            CRC32Result = ((CRC32Result And -256) \ 256) And 16777215
            CRC32Result = CRC32Result Xor CRC32Table(iLookup)
 
        Next
 
        Return CRC32Result
 
    End Function
 
End Class

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of graye
graye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vigylant
vigylant

ASKER

Was afraid of that :(
Well, thanks anyway.