← All problemsFree · Python · 60 min

Algorithm design / guarantees under an adversary

Matching Fingerprints

Make polynomial fingerprints collide: for one base, for as many random bases as possible, and for every odd base at once when the arithmetic wraps around mod 2^64.

0 / 3 graded parts passSaved in this browser · loading saved work…
Jump to your work ↓

A plagiarism checker compares documents by fingerprints. A string s of length L gets F(s)=(s0rL−1+s1rL−2+…+sL−1)modM, where si is the code of the i-th character, r is the base and M the modulus. Rabin and Karp's matcher slides a window along the text and compares fingerprints, and it only compares characters when two fingerprints agree. Two different strings with the same fingerprint are a collision. Too many collisions make the matcher slow, or make a checker that trusts fingerprints wrong.

base r = 7, modulus M = 101, a = 1 … z = 26; pattern “bag”, F = 11cabbagebagF(cab) = 55F(abb) = 65F(bba) = 12F(bag) = 11 compareF(age) = 2F(geb) = 77F(eba) = 58F(bag) = 11 compareletters are compared only where the fingerprints agree
A window of 3 slides along the text; each position gets a fingerprint.

How hard is it to make collisions? It depends on what the checker keeps secret.

  • In parts A and B the letters a to z have codes 1 to 26, and M=101.
  • In part C the codes are ord(c), and M=2bits: the arithmetic of a machine word that simply wraps around, which is how many programs compute fingerprints.

Background: Fingerprinting and String Matching.

easy · Part A

Two words, one fingerprint

With base r=256 and M=101, give two different 4-letter words with the same fingerprint.

Explore in the sandbox

Experiment here, then copy a rule into the editor and test its guarantees.