C/C++ on Linux/Unix

Moderators: Lundin
Number of threads: 336
Number of posts: 663

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Create a Signature or checksum Posted by shiranraviv on 19 Feb 2010 at 1:48 AM
Hi,
I want to create a function which will tell if me the last packet i got from the server is identical to the one i got now.
I thought about put in an array and just compare the two but it will be very inefficient.
So, a checksum or a signature implementation will ( i think ...) do the work.
But how do i make a checksum for let say a const char * data type?

Any help will be thankful!

Report
Re: Create a Signature or checksum Posted by urmele on 9 Mar 2010 at 8:51 AM
any hash function will do.

examples:
a fast one (32bit): djb2(xor) from http://www.cse.yorku.ca/~oz/hash.html
a strong one (64bit, less collisions): http://www.larc.usp.br/~pbarreto/WhirlpoolPage.html
Report
Re: Create a Signature or checksum Posted by urmele on 9 Mar 2010 at 9:04 AM
but a hash makes sense only if you want to compare several times. if you only need to compare to the last packet, you should use memcmp(). or make the server stop sending multiple packets of the same contents



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.