Author Topic: Shadows over Checksums  (Read 1503 times)

Snoogy

  • Sr. Member
  • ****
  • Posts: 364
  • ^Flipping Tables made of Snow
    • View Profile
Shadows over Checksums
« on: November 22, 2015, 02:20:56 am »
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;
}

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

  • Sr. Member
  • ****
  • Posts: 364
  • ^Flipping Tables made of Snow
    • View Profile
Re: Shadows over Checksums
« Reply #1 on: November 22, 2015, 02:11:09 pm »
...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