C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.


Tutorials
| Forums

Download to Enter
| Contest Rules

DOWNLOAD INTEL® GPA FOR FREE

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 26th, 2003, 10:19 PM
theRaginCajun theRaginCajun is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: USA
Posts: 144 theRaginCajun User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
checksum theory?

Hi everyone,

I was trying to put some error checking in this file serialization I was doing. I was wondering about how checksum works - is it basically like you add up the values of all the variables you're serializing then store that in one variable and also write that to the same file - then when you read it back in, if all the read in varaibles' values don't equal the checksum value from the last save, then you know the file is corrupt / messed up?

Code:
WriteFile()
{
    int         x = 5;
    int         y = 10;
    CString z = "hello";
    
    int nCheckSum = (x + y + ASCII value of 'hello'?);

    WriteTheFile();
}

ReadFile()
{
    int         x, y, z, nCheckSum;
    CString z;

    ar >> x;
    ar >> y;
    ar >> z;
    ar >> nCheckSum;

    if (x + y + ASCII value of z? != nCheckSum)
        return false;
}


Thanks!

Reply With Quote
  #2  
Old November 26th, 2003, 11:14 PM
peenie's Avatar
peenie peenie is offline
Google Relay Server
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Oct 2003
Location: Oh christ I don't even know any more.
Posts: 1,810 peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)  Folding Points: 9953 Folding Title: Novice Folder
Time spent in forums: 2 Weeks 1 Day 19 h 12 m 24 sec
Reputation Power: 436
Send a message via AIM to peenie Send a message via MSN to peenie
Yeah that's about it. There's lots of different checksum algorithms. CRC16 and CRC32 are fairly common: http://www.vbaccelerator.com/home/V...C32/article.asp .

If simplicity is all you care about, you could just add up the ASCII values of all the characters. This is generally not very reliable though, because swapping two characters will yield the same checksum, and so will say, changing a 'b' to a 'c' and a 'x' to a 'w' in the same file. The MD5 hashing algorithm is very reliable, and you can find implementations of it all over the place; but it's probably a bit of overkill.

That's the general idea though. Compute checksum, store somewhere. Then, when you read the data back in, compute checksum, compare it with stored checksum. Checksums are useful for detecting data corruption because the chance of both the data being corrupted AND the checksum being accidently corrupted to the "correct" value are very slim indeed.

Reply With Quote
  #3  
Old November 27th, 2003, 02:36 AM
theRaginCajun theRaginCajun is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: USA
Posts: 144 theRaginCajun User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Ok thanks alot for the info - I was thinking about what you said about someone being able to switch like two chars around in a string and the sum will still be the same - I was gonna try a + - operation on every other char value when checksumming that type, so that if the order of chars is switched around it should produce a different sum - I think subtraction and addition wasn't commutative or whatever that word was from middle school

5 + 4 - 3 + 2 = 8
5 + 3 - 4 + 2 = 6

Thanks!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > checksum theory?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap