Calculating the Checksum on a local file

Calculating the Checksum on a local file

Anonymous
Not applicable
1,782 Views
7 Replies
Message 1 of 8

Calculating the Checksum on a local file

Anonymous
Not applicable

http://forums.autodesk.com/t5/Vault-Customization/API-Doug-s-checksum-function-doesn-t-seem-to-work-...

 

The above thread is a dead end, so to repeat AlexF1980 question :

 

Where is the mentioned C# code sample from "vault mirror"? Doing a exhausted search in the SDK folder reveals nothing??

 

Any links? Please...

0 Likes
Accepted solutions (1)
1,783 Views
7 Replies
Replies (7)
Message 2 of 8

minkd
Alumni
Alumni
There are a variety of implementations of CRC32 which should all produce the same result, but which can have very different performance characteristics. I think if you google "crc32 c# implementation", you will find one that suits your needs. -Dave


Dave Mink
Fusion Lifecycle
Autodesk, Inc.
0 Likes
Message 3 of 8

Anonymous
Not applicable

"There are a variety of implementations of CRC32"

 

Couldn't be more true

 

 "which should all produce the same result"

 

Couldn´t be more wrong ( Based on two days implementation of various algorithms before posting  )

 

Why not simply provide this algorithm? Trespassing ADN territory?

 

Cheers!

 

 
0 Likes
Message 4 of 8

minkd
Alumni
Alumni

I didn't realize that CRC32 had so many variants - sorry - I mistakenly assumed it was a standard like MD5 or SHA.


But I can't take the code we use in Vault and share it since it is Autodesk's copyrighted Intellectual Property. I would need permission from the lawyers first, and I'm not sure how to go about doing that.


Doug maintains a blog where he posts a variety of samples & tutorials. I recommend searching there.


-Dave



Dave Mink
Fusion Lifecycle
Autodesk, Inc.
0 Likes
Message 5 of 8

Anonymous
Not applicable
Accepted solution

Hi Dave.. Cool runnings.. Doug just entered the building Let´s hope the lawyers lay low as it would be suicide to nail him Smiley Wink

 

Anyways : some more stubborn research led me to the origin of cadfish1´s "obfuscated" codesnippet that´s out of autodesk jurisdiction:

 

http://www.vbaccelerator.com/home/NET/Code/Libraries/CRC32/Crc32.asp

 

The C# sample will play ball changing types from uint to long.

0 Likes
Message 6 of 8

Anonymous
Not applicable

Good afternoon, could you please update the link http://www.vbaccelerator.com/home/NET/Code/Libraries/CRC32/Crc32.asp, because this link doesn't work anymore.

0 Likes
Message 7 of 8

Anonymous
Not applicable

Imagine life without web.archive.org Smiley Surprised

 

 

using System;
using System.IO;

namespace Vbaccelerator.Components.Algorithms
{
   /// <summary>
   /// Calculates a 32bit Cyclic Redundancy Checksum (CRC) using the
   /// same polynomial used by Zip.
   /// </summary>
   public class CRC32
   {      
      private UInt32[] crc32Table;
      private const int BUFFER_SIZE = 1024;

      /// <summary>
      /// Returns the CRC32 for the specified stream.
      /// </summary>
      /// <param name="stream">The stream to calculate the CRC32 for</param>
      /// <returns>An unsigned integer containing the CRC32
       calculation</returns>
      public UInt32 GetCrc32(System.IO.Stream stream)
      {
         unchecked
         {
            UInt32 crc32Result;
            crc32Result = 0xFFFFFFFF;
            byte[] buffer = new byte[BUFFER_SIZE];
            int readSize = BUFFER_SIZE;

            int count = stream.Read(buffer, 0, readSize);
            while (count > 0)
            {
               for (int i = 0; i < count; i++)
               {
                  crc32Result = ((crc32Result) >> 8) ^ crc32Table[(buffer[i]) ^
                   ((crc32Result) & 0x000000FF)];
               }
               count = stream.Read(buffer, 0, readSize);
            }
            
            return ~crc32Result;
         }
      }

      /// <summary>
      /// Construct an instance of the CRC32 class, pre-initialising the table
      /// for speed of lookup.
      /// </summary>
      public CRC32()
      {
         unchecked
         {
            // This is the official polynomial used by CRC32 in PKZip.
            // Often the polynomial is shown reversed as 0x04C11DB7.
            UInt32 dwPolynomial = 0xEDB88320;
            UInt32 i, j;

            crc32Table = new UInt32[256];

            UInt32 dwCrc;
            for(i = 0; i < 256; i++)
            {
               dwCrc = i;
               for(j = 8; j > 0; j--)
               {
                  if ((dwCrc & 1)==1)
                  {
                     dwCrc = (dwCrc >> 1) ^ dwPolynomial;
                  }
                  else
                  {
                     dwCrc >>= 1;
                  }
               }
               crc32Table[i] = dwCrc;
            }
         }
      }
   }
}

 

Message 8 of 8

Anonymous
Not applicable

Thanks!

0 Likes