Skip to content

Latest commit

 

History

History

file-integrity

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Overview

The program checksum.py is very simple: it can be used to calculate checksums of different flavors (addition, xor-based, or fletcher) on either random values (as generated by the program) or on values you pass in as a series of bytes.

When run in the default mode:

prompt> ./checksum.py

OPTIONS seed 0
OPTIONS data_size 4
OPTIONS data

Decimal:          216        194        107         66
Hex:             0xd8       0xc2       0x6b       0x42
Bin:       0b11011000 0b11000010 0b01101011 0b01000010

Add:      ?
Xor:      ?
Fletcher: ?

prompt>

In this example, the program produces a random set of four numbers (the "data") of 216 194 107 66 (decimal). The numbers are also shown in hex and binary.

The program then asks you to compute the additive, xor-based, and fletcher checksums. The addition is just the result of adding each of the bytes together, with the result modulo 256 (it's just a single byte checksum). The xor-based checksum is the result of xor'ing each byte together (it is also a single byte). Finally, fletcher is the result of computing the two parts of the fletcher checksum (as described in the chapter), which is two bytes in total.

You can change the seed to get a different problem:

prompt> ./checksum.py -s 1

OPTIONS seed 1
OPTIONS data_size 4
OPTIONS data

Decimal:           34        216        195         65
Hex:             0x22       0xd8       0xc3       0x41
Bin:       0b00100010 0b11011000 0b11000011 0b01000001

Add:      ?
Xor:      ?
Fletcher: ?

prompt> 

You can specify a different length for the random data:

prompt> ./checksum.py -D 2

...

You can also specify your own data string:

prompt> ./checksum.py -D 1,2,3,4

OPTIONS seed 0
OPTIONS data_size 4
OPTIONS data 1,2,3,4

Decimal:            1          2          3          4
Hex:             0x01       0x02       0x03       0x04
Bin:       0b00000001 0b00000010 0b00000011 0b00000100

Add:      ?
Xor:      ?
Fletcher: ?

prompt> 

Finally, you can use -c to have the program compute the checksums for you.

prompt> ./checksum.py -D 1,2,3,4 -c

OPTIONS seed 0
OPTIONS data_size 4
OPTIONS data 1,2,3,4

Decimal:            1          2          3          4
Hex:             0x01       0x02       0x03       0x04
Bin:       0b00000001 0b00000010 0b00000011 0b00000100

Add:             10       (0b00001010)
Xor:              4       (0b00000100)
Fletcher(a,b):   10, 20   (0b00001010,0b00010100)

prompt> 

Thus ends the worst README in this collection of READMEs.