Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File containing its own checksum

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.

like image 809
zakovyrya Avatar asked Jul 13 '09 07:07

zakovyrya


People also ask

What is the checksum of a file?

A checksum is a string of numbers and letters that's used to “check” whether data or a file has been altered during storage or transmission. Checksums often accompany software downloaded from the web so that users can ensure the file or files were not modified in transit.

Can two files have the same checksum?

Yes. There are an infinite number of binary files, but only a finite number of md5 hashes (since they have fixed size) hence there are infinitely many files that have the same hash.


2 Answers

I created a piece of code in C, then ran bruteforce for less than 2 minutes and got this wonder:

The CRC32 of this string is 4A1C449B 

Note the must be no characters (end of line, etc) after the sentence.

You can check it here: http://www.crc-online.com.ar/index.php?d=The+CRC32+of+this+string+is+4A1C449B&en=Calcular+CRC32

This one is also fun:

I killed 56e9dee4 cows and all I got was... 

Source code (sorry it's a little messy) here: http://www.latinsud.com/pub/crc32/

like image 82
LatinSuD Avatar answered Oct 13 '22 20:10

LatinSuD


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.

like image 43
brianegge Avatar answered Oct 13 '22 19:10

brianegge