开发者

Is this checksum calculation completely waterproof?

long make_checksum(const char* str)
{
  long chk=0;
  long rot=0;
  while(*str)
  {
    rot<<=9;
    rot|=(rot>>23);
    rot^=*(char*)str++;
    chk+=rot;
  }
  return chk;
}

Not waterproof means: there's a chance I can get the same checksum for two different s开发者_如何学运维trings.


As there are more possible strings than long values, there are surely two different strings resulting in the same checksum.


A checksum can never be waterproof, since it contains less data than the original data of which you are calculating the checksum.

If you want a real waterproof 'checksum', you need to create a second 'instance' of your data and make sure that it contains identically the same data as the original data, although it does not have to be in the same format (can be encryped or compressed).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜