2
是否有VB.NET計算字符串或字節數組的CRC32的函數或示例?計算字符串或字節數組的CRC32
是否有VB.NET計算字符串或字節數組的CRC32的函數或示例?計算字符串或字節數組的CRC32
使用此:
Private Sub Main()
Crc32.ComputeChecksum(Encoding.UTF8.GetBytes("Some string")).Dump()
End Sub
Public Class Crc32
Shared table As UInteger()
Shared Sub New()
Dim poly As UInteger = &Hedb88320UI
table = New UInteger(255) {}
Dim temp As UInteger = 0
For i As UInteger = 0 To table.Length - 1
temp = i
For j As Integer = 8 To 1 Step -1
If (temp And 1) = 1 Then
temp = CUInt((temp >> 1) Xor poly)
Else
temp >>= 1
End If
Next
table(i) = temp
Next
End Sub
Public Shared Function ComputeChecksum(bytes As Byte()) As UInteger
Dim crc As UInteger = &HffffffffUI
For i As Integer = 0 To bytes.Length - 1
Dim index As Byte = CByte(((crc) And &Hff) Xor bytes(i))
crc = CUInt((crc >> 8) Xor table(index))
Next
Return Not crc
End Function
End Class
是[這](http://stackoverflow.com/questions/8128/how-do-i-calculate-crc32-of-a-string)你需要什麼。 ? – 2013-03-21 17:12:46
其實我看過之前,但他們沒有作品,其中大部分鏈接是用於計算文件的CRC32 – Shahriyar 2013-03-21 17:20:00
「非他們的作品」真的,他們有什麼不對? – Magnus 2013-03-21 17:29:08