I have a struct with 2 bytes inside. How to compute checksum (e.g. MD5 hash) for array of such structs?
public struct MyStruct
{
public byte Byte1;
public byte Byte2;
}
public class MyClass
{
public static byte[] ComputeChecksum(MyStruct[] myStructs)
{
// TODO: calculation.
}
}
So do you want STRONG digesting or just a quick error-check/consistent-lookup value?
MD5/SHA is pretty intensive operations – they’re built around block-structures that are multiples of hundreds of bytes.
fletcher and CRC32 are very efficient and do a decent job of producing a random number.. What they are not good at is having random bit positions.. So for example, you wouldn’t want a fletcher than only look at only the upper or bottom 8 bits (since there would be too little varience)..
Either find an open-source library or hit wikipedia for the various algorithms.. I tend to just use something like: