Check your understanding of the previous reading: calculating hashes with the hashing formula.

Question 1

Use the hashing formula to calculate the hash of all the following strings. Use the Python Shell (the code playground below) to help you calculate these numbers, since they get very large, very fast!


A with a base of 11 and a hash size of 100:

Show worked solution

The codes: A is 65. (0 + 11) ** 65 % 100 is 51.

AB with a base of 11 and a hash size of 100:

Show worked solution

The codes: A is 65, B is 66. ((0 + 11) ** 65 + (1 + 11) ** 66) % 100 is 35.

ABC with a base of 11 and a hash size of 100:

Show worked solution

The codes: A is 65, B is 66, C is 67. ((0 + 11) ** 65 + (1 + 11) ** 66 + (2 + 11) ** 67) % 100 is 52.

ABC with a base of 33 and a hash size of 10000:

Show worked solution

The codes: A is 65, B is 66, C is 67. ((0 + 33) ** 65 + (1 + 33) ** 66 + (2 + 33) ** 67) % 10000 is 9484.

Hello with a base of 31 and a hash size of 1000000000:

Show worked solution

The codes: H is 72, e is 101, l is 108, o is 111. ((0 + 31) ** 72 + (1 + 31) ** 101 + (2 + 31) ** 108 + (3 + 31) ** 108 + (4 + 31) ** 111) % 1000000000 is 590934605.