LackeyCCG Forum > Programming Help Forum

Shadows over Checksums

(1/1)

Snoogy:
Dear Trevor,

A long while back you posted your algorithm for generating checksums:


--- Quote from: Trevor, ages ago ---int GetCheckSumFromFile(char PathNamePart[])
{
    FILE* fp = FOpen(PathNamePart,"rb");
    if(fp==NULL)
        return 0; // If there is no file, return with a sum of 0.
    long f1,f2=0;
    char TempChar=0;
    int Sum=0;
    do
        {
        f1 = f2;
        TempChar = fgetc(fp);
        f2 = ftell(fp);
        if(TempChar!=10 && TempChar!=13)
            Sum+=(unsigned int)TempChar;
        Sum=Sum%100000000; //modulo to prevent memory type overflow               
        } while(f1 != f2);
    fclose(fp);
    return Sum;
}
--- End quote ---

I have since attempted to recreate that algorithm in C#, for the purpose of quickly obtaining checksums when updating.  However, my algorithm never produces the same value, no matter how much I tinker with it...  Did you, perchance, rewrite yours?

Snoogy:
...Apparently not, since I just compiled your code as a DLL (after much trial-and-error-and-hair-pulling) and implemented it in my tool and it worked exactly as intended!  :D

Navigation

[0] Message Index

Go to full version