Help calculate checksum (newbie)

A

Adriano

Hello.

I have a situation where need to calculate a checksum of some byte array.
Here's the sample output from server:
2008-09-30 11:35:00 `SC`00541.00TJ123456PPC 00000000DLGLGN
00000001TXBEG Login:user=mmlos, pswd=osmp

The checksum is 9afb81c7

I cannot figure out where this checksum come from, can anyone post a sample
in vb.net or C#?
See the packet description at http://www.epay.tj/img/MML-Packets.jpg
Any help on that whould be greatly appreciated.

Adriano
 
H

Herfried K. Wagner [MVP]

Adriano said:
I have a situation where need to calculate a checksum of some byte array.
Here's the sample output from server:
2008-09-30 11:35:00 `SC`00541.00TJ123456PPC 00000000DLGLGN
00000001TXBEG Login:user=mmlos, pswd=osmp

The checksum is 9afb81c7

I cannot figure out where this checksum come from, can anyone post a
sample in vb.net or C#?
See the packet description at http://www.epay.tj/img/MML-Packets.jpg

Doesn't the packet description contain information on how to calculate the
checksum (4.)?
 
A

Adriano

Yes it does, but I can't figure out how to calculate it using vb or c#.
Can you help me?

thanks in advance,
Adriano
 
J

James Hahn

What's the description of the calculation? There are many different ways
to calculate a checksum.

Here's one from VB6 that I use for my own purposes:
Dim k as Integer
k = 0
While Loc(1) < LOF(1) - 4
FileGet(1, j)
k = k Xor j
End While
FileClose()
ItemX.Add(Hex(k).PadLeft(8, "0"))

The (-4) is because that's where some additional data is stored that is
excluded from the calculation. This example is an XOR - adding
modulo(something) is also common. The result is an 8-byte hex value, same as
yours.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top