This is the Bitap (or Shift-And) algorithm described here:
https://en.m.wikipedia.org/wiki/Bitap_algorithm
Change
maybe := prefixes << 1
to maybe := prefixes<<1 + 1
to fix the bug.