3

When I run the command cksum I get the following as output

2836376023   36 myfile.txt

I understand that 36 is the size of the file followed by the name of the file

But I would like to know the formula for how the number 2836376023 is generated. I know that from one file to another the number is completely different.

Zanna
  • 70,465

1 Answers1

5

The number 2836376023 is the CRC checksum of the file

CRC = cyclic redundancy check

In short, a mathematical operation (polynomial division) is performed on the contents of a file and the remainder is used to generate the checksum. If the file has changed since the last time the calculation was done, the checksum would be different, so it can be used to make sure files have not been damaged in transit. The method is only useful to check for accidental data corruption; it is not secure against deliberate attacks, as it is quite trivial to modify a file in such a way that the CRC checksum stays the same.

To expand on this, the program doing the checksum (such as cksum) defines a generator polynomial to be the denominator in the polynomial division. The contents of the file to be checked are the numerator.

Detailed examples of the computation can be found on Wikipedia:
Computation of Cyclic Redundancy Checks

If you want to know the exact details of implementation in the case of cksum, you can read the source code online at Savannah

Or download it by enabling source downloads and running (in your home)

sudo apt update
mkdir coreutils-src && cd coreutils-src
apt source coreutils

Then cd into the new directory. cksum.c is in the src subdirectory.

Zanna
  • 70,465