implement the kmp substring algorithm