Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21922

CRC CCiTT Kermit calculation in VB6

$
0
0
I want to calculate a 2byte crc value for a string like:

01 2D 23 0F 27 02 2B

The answer should be: 91 C3
The CRC type is: CRC CCITT Kermit
I'am using VB6.

It works, but the answers al all bad.

Here's my code:
========================================

Public Function CRCKERMIT(Buffer() As Byte) As Long

Dim i As Long
Dim Temp As Long
Dim CRC As Long
Dim j As Integer
CRC = 0
For i = LBound(Buffer) To UBound(Buffer)
Temp = Buffer(i) * &H100&
CRC = CRC Xor Temp
For j = 0 To 255
If (CRC And &H8404&) Then
CRC = ((CRC * 2) Xor &H1021&) And &HFFFF&
Else
CRC = (CRC * 2) And &HFFFF&
End If
Next j
Next i
CRCKERMIT = CRC And &HFFFF

End Function


Private Sub Command1_Click()

Dim aBuf() As Byte

Dim CRC As Long
Dim p As String

p = Text1.Text
aBuf = StrConv(p, vbFromUnicode)
CRC = CRCKERMIT(aBuf)
Text2.Text = Hex(CRC)

End Sub

Private Sub Command2_Click()
End
End Sub

======================================

Anyone with an idea?

Viewing all articles
Browse latest Browse all 21922

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>