Calculating Checksums
Calculating Checksums
Calculating Checksums
Calculating Checksums
Calculating Checksums
Calculating Checksums Calculating Checksums Calculating Checksums Calculating Checksums Calculating Checksums Calculating Checksums Calculating Checksums Calculating Checksums
Calculating Checksums Calculating Checksums
Calculating Checksums
Go Back  Xtreme Visual Basic Talk > > > Calculating Checksums


Reply
 
Thread Tools Display Modes
  #21  
Old 07-21-2006, 03:47 AM
CodeCruncher CodeCruncher is offline
Junior Contributor
 
Join Date: Jul 2006
Posts: 355
Default


Quote:
Originally Posted by namrekka
Look at:
http://en.wikipedia.org/wiki/Cyclic_redundancy_check

Or try Poly: &H1021
And crc=0 and crc=&HFFFF
Thanks for the link, I think that is outside of my mathimatical scope to understand but will have a read anyway.
Reply With Quote
  #22  
Old 07-21-2006, 04:19 AM
namrekka namrekka is offline
Junior Contributor
 
Join Date: Feb 2005
Location: Netherlands
Posts: 219
Default

Try this module. It is not optimized but easy to track in the debugger. Play with the "CRC" value and the "Poly".
Attached Files
File Type: zip CRC16_2.zip (651 Bytes, 12 views)
Reply With Quote
  #23  
Old 07-21-2006, 08:15 AM
OnErr0r's Avatar
OnErr0rCalculating Checksums OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,774
Default

I went ahead and moved this to .net. I guess I didn't read the first post very well.

The code you're using will need to be altered to use the proper data types in .net. Long becomes Integer and Integer becomes Short, etc.
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #24  
Old 07-21-2006, 10:58 AM
DougT's Avatar
DougT DougT is offline
Ultimate Antique

Administrator
* Expert *
 
Join Date: Sep 2005
Location: Maldon,Essex, UK
Posts: 3,939
Default

Well, News and Bad News,

I ran the code namrekka posted for every value of 'Poly' for a 'CRC' value of 0 and Hex FFFF using the data you gave (hex: 07010000).

With a 'CRC' of zero and a 'Poly' of Hex 3974 it returned a value of Hex FFF8. With a 'CRC' value of Hex FFFF and a 'Poly' value of Hex 2878 it also returned a value of Hex FFF8.

Unfortunately, using either / both the 'Poly' and initial 'CRC' values above, none of the other examples you gave in post #5 returned the correct Checksum.

So, I would conclude that:

(a) Haltec do not use this algorithm to calculate the checksum
or
(b) Haltec do not use a CRC algorithm at all
or
(c) The examples you gave in post #5 are incorrect

Not much help I'm afraid, but may save you some time

(Needles should never be put in Haystacks in the first place)

Regards
Doug
__________________
semel insanivimus omnes
S Data in context = Information, S Information in context = Knowledge, S Knowledge in context = Experience
S Experience in context = Wisdom= Data
Reply With Quote
  #25  
Old 07-22-2006, 03:45 PM
mkaras's Avatar
mkarasCalculating Checksums mkaras is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Mar 2004
Location: Beaverton, OR
Posts: 1,874
Default Simple Checksum - Not a CRC

I see that the work on this project is going in the wrong direction. The samples provided in Posting #5 are easy to see that the checksum is a simple Checksum and not a CRC (cyclic redundancy check).

I created a spreadsheet to show how this computes. The attached image shows the spreadsheet display. The spreadsheet and image file are also attached in a ZIP file.

I found if you simply add up all the first four bytes and then subtract that sum from 65536 (i.e. 2^^16) you have the resulting checksum. For a general purpose algorithm you probably want to add up the byte values of the packet into a long and then AND the sum with &HFFFF&. Then place the value 65536 into a long from which you subtract the result of the ANDed sum. The low 8 biits of the subtraction result are the Checksum low byte value (i.e. Result And &HFF&) and the next higher bits are the Chexksum high byte value (i.e. (Result \ 256) And &HFF&).
Attached Images
File Type: gif CheckSum.gif (9.1 KB, 10 views)
Attached Files
File Type: zip CheckSum.zip (11.8 KB, 8 views)
Reply With Quote
  #26  
Old 07-23-2006, 02:15 AM
mkaras's Avatar
mkarasCalculating Checksums mkaras is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Mar 2004
Location: Beaverton, OR
Posts: 1,874
Default Calculating Checksum VB Style

Here is another way in VB Code to calculate the checksum.

Code:
Dim Cks As Long Cks = 0 Cks = Cks + Byte1 Cks = Cks + Byte2 Cks = Cks + Byte3 Cks = Cks + Byte4 Cks = Not Cks Cks = Cks + 1 Cks = Cks And &HFFFF&

Attached is a VB demo program that shows this code in use. It includes an ability to allow the user to enter their own four bytes and compute the checksum based upon those bytes.
Attached Images
File Type: jpg ChecksumDemo.jpg (32.3 KB, 4 views)
Attached Files
File Type: zip ChecksumDemo.zip (29.1 KB, 10 views)
Reply With Quote
  #27  
Old 07-23-2006, 02:22 AM
DougT's Avatar
DougT DougT is offline
Ultimate Antique

Administrator
* Expert *
 
Join Date: Sep 2005
Location: Maldon,Essex, UK
Posts: 3,939
Default

mkaras......

Just out of interest, and without going too far off topic, is that method a 'standard' or common way to calculate checksums ? (You obviously knew what you were looking at whereas we were floundering around in the dark.)

Regards
Doug
__________________
semel insanivimus omnes
S Data in context = Information, S Information in context = Knowledge, S Knowledge in context = Experience
S Experience in context = Wisdom= Data
Reply With Quote
  #28  
Old 07-23-2006, 03:04 AM
mkaras's Avatar
mkarasCalculating Checksums mkaras is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Mar 2004
Location: Beaverton, OR
Posts: 1,874
Default

A standard checksum is just a linear sum of bytes that is often trimmed to some boundary size like 8-bits or 16-bits.

Sometimes the final checksum value is manipulated after the summing process so that it is possible sum through the data region and the stored checksum to get a result with a known value. This would be most common for checksums that are modulo 2^^8 summations (i.e. trimmed to 8-bits) with a final value of zero or &HFF.

The scheme here is not standard as far as I can tell. The first time I read this thread I also thought that this was a CRC problem. When I came back to see more of the thread content later I noticed that the high byte of the checksum was almost always 255 in the samples provided. That is what gave it away. If the samples had included longer arrays of numbers or the values had not always had so many zeros or the first byte value varied from the constant 7 then it would not have been at all so easy to spot the pattern. And then I would have still thought maybe CRCs were involved.
Reply With Quote
  #29  
Old 07-23-2006, 08:01 PM
CodeCruncher CodeCruncher is offline
Junior Contributor
 
Join Date: Jul 2006
Posts: 355
Default

Thanks a lot guys you rock... I will try the attachments out when I get home, I can't tell you how much I appriciate your help.

Edit: I have just had a look at the Excel spreadsheet, I can't believe how unbelievably simple that is. If I wasn't so happy that I have answer, I would be dissapointed that it has taken so long to get such a simple sum.

Once again thank you to all that contributed, you have been fantastic.

Regards,
Paul

Last edited by CodeCruncher; 07-23-2006 at 11:03 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Calculating Checksums
Calculating Checksums
Calculating Checksums Calculating Checksums
Calculating Checksums
Calculating Checksums
Calculating Checksums Calculating Checksums Calculating Checksums Calculating Checksums Calculating Checksums Calculating Checksums Calculating Checksums
Calculating Checksums
Calculating Checksums
 
Calculating Checksums
Calculating Checksums
 
-->