⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crc.vb

📁 用VB.NET编写的在智能手机间传送文件的程序代码
💻 VB
字号:
Namespace Dreamworld.Tools
    Public Class CRC32

        ' This is v2 of the VB CRC32 algorithm provided by Paul
        ' (wpsjr1@succeed.net) - much quicker than the nasty
        ' original version I posted.  Excellent work!

        Private crc32Table() As Integer
        Private Const BUFFER_SIZE As Integer = 1024

        Public Function GetCrc32(ByRef stream As System.IO.Stream) As Integer

            Dim crc32Result As Integer
            crc32Result = &HFFFFFFFF

            Dim buffer(BUFFER_SIZE) As Byte
            Dim readSize As Integer = BUFFER_SIZE

            Dim count As Integer = stream.Read(buffer, 0, readSize)
            Dim i As Integer
            Dim iLookup As Integer
            Dim tot As Integer = 0
            Do While (count > 0)
                For i = 0 To count - 1
                    iLookup = (crc32Result And &HFF) Xor buffer(i)
                    crc32Result = ((crc32Result And &HFFFFFF00) \ &H100) And &HFFFFFF   ' nasty shr 8 with vb :/
                    crc32Result = crc32Result Xor crc32Table(iLookup)
                Next i
                count = stream.Read(buffer, 0, readSize)
            Loop

            GetCrc32 = Not (crc32Result)

        End Function

        Public Sub New()

            ' This is the official polynomial used by CRC32 in PKZip.
            ' Often the polynomial is shown reversed (04C11DB7).
            Dim dwPolynomial As Integer = &HEDB88320
            Dim i As Integer, j As Integer

            ReDim crc32Table(256)
            Dim dwCrc As Integer

            For i = 0 To 255
                dwCrc = i
                For j = 8 To 1 Step -1
                    If (dwCrc And 1) Then
                        dwCrc = ((dwCrc And &HFFFFFFFE) \ 2&) And &H7FFFFFFF
                        dwCrc = dwCrc Xor dwPolynomial
                    Else
                        dwCrc = ((dwCrc And &HFFFFFFFE) \ 2&) And &H7FFFFFFF
                    End If
                Next j
                crc32Table(i) = dwCrc
            Next i
        End Sub

    End Class
End Namespace

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -