Defined core KMP algorithm