# Universal collisions

`P = 1000003def hash(s):x = random key 1for byte in s:    x = (x * P) + bytex ^= random key 2return x`
`step(oldstate, byte) = oldstate * P + byte`
`step(x, b) = x * P + b`
`act(b)(x) = x * P + b`
`act('a' + 'b')(x) = act('b')(act('a')(x)) `
`let act(s1) = a*x + blet act(s2) = c*x + dact(s1 + s2) = c*(a*x + b) + d = (a*c)*x + (b*c + d)`
`P = 1000003def hash(s):if len(s) == 0:     return 0x = random key 1x ^= s << 7for byte in s:    x = (x * P) ^ bytex ^= len(s)x ^= random key 2if x == -1:    return -2return x`
`def hash(s):x = random key 1for byte in s:    x = (x * P) ^ bytex ^= random key 2return x`

# Second try: near optimal collisions

## Meet in the middle

`act(lhs + rhs)(i) = (act(lhs)(i)-j)*P^len(rhs) + act(rhs)(j) where j = act(lhs)(i) mod 256`
`act(lhs+rhs) = act(lhs)*Pn + act(rhs)`
`a*Pn + b = e mod 2^k`
`a' = e - a * Pna' = b mod 2^k`

# XML parsing

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just \$5/month. Upgrade