File containing its own checksum

后端 未结 12 1709
误落风尘
误落风尘 2020-12-23 13:16

Is it possible to create a file that will contain its own checksum (MD5, SHA1, whatever)? And to upset jokers I mean checksum in plain, not function calculating it.

12条回答
  •  無奈伤痛
    2020-12-23 14:16

    Yes. It's possible, and it's common with simple checksums. Getting a file to include it's own md5sum would be quite challenging.

    In the most basic case, create a checksum value which will cause the summed modulus to equal zero. The checksum function then becomes something like

    (n1 + n2 ... + CRC) % 256 == 0
    

    If the checksum then becomes a part of the file, and is checked itself. A very common example of this is the Luhn algorithm used in credit card numbers. The last digit is a check digit, and is itself part of the 16 digit number.

提交回复
热议问题