I have changed the implementation of the algorithm.
I used the Aho-Corasick algorithm, and the N-gram algorithm.