RageBin - Collaborative Raging

Ragebin is a collaborative Raging tool allowing you to share and modify rage snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a browser that supports this.

VB.NET RageBin - Home - View Help - Archive - Ragers IRC - Image Boards

Posted by eri X9 2 0 on Friday 12th November 2010 04:10:03 - Never Expires
download | new post

  1. ' Here CRC32 for all my vb.net niggaz
  2. ' COPYRIGHT 2010-EOT Erix920 ;)
  3.  
  4. Namespace Cryptography
  5.     Public Class CRC32
  6.         Inherits HashAlgorithm
  7.         Private Const _DefaultPolynomial As Integer = &HEDB88320
  8.  
  9. #Region " Member Variables "
  10.         Private _Table() As Integer
  11.         Private _CRC32 As Integer = &HFFFFFFFF
  12.         Private _Polynomial As Integer
  13. #End Region
  14.  
  15. #Region " Contructors "
  16.         Public Sub New()
  17.             Me.HashSizeValue = 32 ' CRC32 is a 32bit hash
  18.             _Polynomial = _DefaultPolynomial
  19.             Initialize()
  20.         End Sub
  21.         Public Sub New(ByVal Polynomial As Integer)
  22.             _Polynomial = Polynomial
  23.         End Sub
  24. #End Region
  25.  
  26. #Region " HashAlgorithm "
  27.  
  28.         Protected Overrides Sub HashCore(ByVal array() As Byte, ByVal ibStart As Integer, ByVal cbSize As Integer)
  29.  
  30.             Dim intLookup As Integer
  31.             For i As Integer = 0 To cbSize - 1
  32.                 intLookup = (_CRC32 And &HFF) Xor array(i)
  33.                 'This is a workaround for a right bit-shift because vb.net
  34.                 'does not support unsigned Integers, so _CRC32 >> 8
  35.                 'gives the wrong value (any better fixes?)
  36.                 _CRC32 = ((_CRC32 And &HFFFFFF00) \ &H100) And &HFFFFFF
  37.                 _CRC32 = _CRC32 Xor _Table(intLookup)
  38.             Next (i)
  39.         End Sub
  40.  
  41.         Protected Overrides Function HashFinal() As Byte()
  42.             Return (BitConverter.GetBytes(Not _CRC32))
  43.         End Function
  44.  
  45.         Public Overrides Sub Initialize()
  46.             _CRC32 = &HFFFFFFFF
  47.             _Table = BuildTable(_Polynomial)
  48.         End Sub
  49.  
  50. #End Region
  51.  
  52. #Region " Helper Methods "
  53.         ''' <summary>
  54.         ''' Generates the CRC32 Table
  55.         ''' </summary>
  56.         ''' <param name="Polynomial">A polynomial that should be used to generate the table.</param>
  57.         ''' <returns>The CRC32 Table based on the Polynomial given</returns>
  58.         Private Shared Function BuildTable(ByVal Polynomial As Integer) As Integer()
  59.             Dim Table(255) As Integer
  60.             Dim Value As Integer
  61.             For I As Integer = 0 To 255
  62.                 Value = I
  63.                 For X As Integer = 0 To 7
  64.                     If (Value And 1) = 1 Then
  65.                         'This is a workaround for a right bit-shift because vb.net
  66.                         'does not support unsigned Integers, so _CRC32 >> 1
  67.                         'gives the wrong value (any better fixes?)
  68.                         Value = Convert.ToInt32(((Value And &HFFFFFFFE) \ 2&) And &H7FFFFFFF)
  69.                         Value = Value Xor Polynomial
  70.                     Else
  71.                         'Same as above.
  72.                         Value = Convert.ToInt32(((Value And &HFFFFFFFE) \ 2&) And &H7FFFFFFF)
  73.                     End If
  74.                 Next
  75.                 Table(I) = Value
  76.             Next
  77.             Return Table
  78.         End Function
  79. #End Region
  80.  
  81.     End Class
  82. End Namespace

Submit a correction or amendment below. (click here to post a fresh rage)
After submitting an amendment, you'll be able to view the differences between the old and new rage easily.
Syntax Highlighting:
To highlight particular lines, prefix each line with @@
Pressing TAB inserts 3 spaces