How to use the patterns mined by KDD algorithms is very important to real-time and effectiveness of IDS. This paper put forward an algorithm of pattern encoding, which can express patterns in digits, thus the intrusion pattern can be detected efficiently. At the same time, it also has proved that the patterns detection methods based on pattern encoding are equal to the methods with similarity theory, as a result, any intrusion pattern detection algorithms based on similarity theory can be realized by pattern encoding.