0

I am seeking for an algorithm, that knows how to combine 2 checksums.

Specifically I want something like: Combine(CheckSum(FirstHalf(File)), CheckSum(SecondHalf(File))) = CheckSum(File)

EDIT: it is important that the algorithm recognizes the application order. More formally: Combine(CheckSum(FirstHalf(File)), CheckSum(SecondHalf(File))) != Combine(CheckSum(SecondHalf(File)), CheckSum(FirstHalf(File)))

Timofey
  • 2,478
  • 3
  • 37
  • 53
  • Sounds like CRC32 might help you (not a duplicate, but worth a read): http://stackoverflow.com/questions/6978372/is-crc32-additive – Gassa Mar 16 '17 at 23:40

2 Answers2

0

The simplest checksum algorithm simply sums the bytes of the file, hence the name.

So, the checksums of the two halves of the file can simply be added together to equal the checksum of the entire file.

Doug Currie
  • 40,708
  • 1
  • 95
  • 119
  • It doesn't seem to be resistant to unintentional file modification, does it? – Timofey Mar 16 '17 at 20:23
  • It will catch many unintentional changes; how many depends on the size of the checksum. In particular, it detects any single bit change. If you're asking about resistance to attack by a motivated miscreant, then this simple summation approach is awfully bad. – Doug Currie Mar 16 '17 at 20:31
  • I should have added the requirement, that the algorithm must detect the order of part's combination, which simple bytes summation doesn't detect – Timofey Mar 16 '17 at 20:34
0

Plain old CRC can do this if you know the length of second chunk, as explained here. There is an efficient implementation in zlib.

Community
  • 1
  • 1
yuri kilochek
  • 12,709
  • 2
  • 32
  • 59