Re: dealing with hex values in c# vs VB



The resulting CRC must match up against a CRC generated by someone elses
program so I'm stuck with this seed and algorithm. I personally would have
gone directly with the MD5 function but the choice was made long before I
started writing.

I may just DLL it but I'm curious as to where the differences in the
language are. Using the reflector program I managed to get the table
built correctly. It was a case of the hex values not directly transfering
between the languages. I'm now moving onto the second function that
actually uses the table.

the original vb

'CRC computation function

Public Function AdDDNc32(ByVal Item As String, ByVal Crc32 As Long) As Long

'Declare following variables

Dim bCharValue As Byte, iCounter As Integer, lIndex As Long

Dim lAccValue As Long, lTableValue As Long

On Error Resume Next

'Iterate through the string that is to be checksum-computed

For iCounter = 1 To Len(Item)

'Selects the current character and converts it to an ASCII value

bCharValue = Asc(Mid$(Item, iCounter, 1))

'Only update CRC for valid ASCII characters, 32 to 126

If (bCharValue > 31) And (bCharValue < 127) Then

'Right shift an Unsigned Long 8 bits

lAccValue = Crc32 And &HFFFFFF00

lAccValue = lAccValue \ &H100

lAccValue = lAccValue And &HFFFFFF

'Now select the right adding value from the holding table

lIndex = Crc32 And &HFF

lIndex = lIndex Xor bCharValue 'inverts the byte

lTableValue = Crc32Table(lIndex)

'Then mix new Crc32 value with previous accumulated Crc32 value

Crc32 = lAccValue Xor lTableValue

End If

Next

'Return new Crc32 checksum

AdDDNc32 = Crc32

End Function


The line that is causing me issues is

bCharValue = Asc(Mid$(Item, iCounter, 1))

Mid$(Item,iCounter,1) should I think turn into item.substring(icounter,1)
but I'm not sure how to recreate the Asc function or exactly what it does.




"Michael Bray" <mbray@makeDIntoDot_ctiusaDcom> wrote in message
news:Xns9749A51EB8D75mbrayctiusacom@xxxxxxxxxxxxxxxx
> "=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?="
> <pbromberg@xxxxxxxxxxxxxxxxxxx> wrote in
> news:E50877FE-7F23-4028-B483-0A0E10802AC1@xxxxxxxxxxxxx:
>
>> 1) Compile the VB.NET and use Lutz Roeder's Reflector freeware product
>> to decompile it to C#. Its' not perfect, but it works for most
>> classes.
>>
>
> Or for that matter, compile the VB.NET in a DLL and reference it. :)
>
> As an aside, if the OP is using CRC only within his own applications (ie
> not communicating with other applications that he didn't write) he could
> also use MD5.ComputeHash(...). It works nicely because you can put the
> result into a Guid.
>
> -mdb


.



Relevant Pages

  • Re: Shorter checksum than MD5
    ... CRC algorithms were ... within that arithmetic, the CRC of a string is ... def crc(s, salt): ... 'The probability of the changed dada having the same CRC32 is 1/2**32' ...
    (comp.lang.python)
  • Re: CRC32 Question
    ... Basically I understand CRC from the examples on wikipedia. ... CRC32 generators and I found out CRC32 is a little different which I ... CRC32 inverts its register before and after processing. ... Let's write t for the indeterminate in the polynomials, ...
    (sci.crypt)
  • [PATCH 2/6] crc32: replace bitreverse by bitrev32
    ... The only users of bitreverse() are crc32 itself and via-velocity. ... crc1 = crc32_le; ...
    (Linux-Kernel)
  • Re: implementing ethernet FCS code in verilog
    ... have to data stream before applying to crc and when checksum created ... The crc you need to apply is the CRC32 AUTODIN II. ... before feeding the bits to the crc32 generator. ... generator aswell, sometimes these may need swapping aswell. ...
    (comp.arch.fpga)
  • Re: Checking CRC?? [URJENT!!]
    ... > I want to write my own routine to calculate the CRC of any given file. ... Dim iBytes As Integer ... Dim lAccValue As Long, lTableValue As Long ... Dim wfsiu As Integer ...
    (comp.lang.basic.visual.misc)