An encoding program comprising instructions which, when executed by a computer, causes the computer to execute a process comprising: determining whether a target character string is registered in a first dictionary, the target character string being a compression target contained in input data, the first dictionary correlating compression codes and corresponding strings; first reading, from the first dictionary, a compression code corresponding to the target character string when the target character string is registered in the first dictionary; searching the target character string in a second dictionary when the target character string is not registered in the first dictionary; second reading, from the second dictionary, a compression code corresponding to the target character string when the target character string is registered in the second dictionary; searching the target character string in first data when the target character string is not registered in the first dictionary nor in the second dictionary, the first data accumulating character strings that are a part of the input data and have been determined to be not registered in the first dictionary and are not from the second dictionary; registering the target character string in the second dictionary different from the first dictionary when the target character string has been found in the first data and the target character string is equal to or larger than a predetermined length; third reading a compression code corresponding to a registration number of the target character string in the second dictionary, when a compression code corresponding to the target character string is not read by the second reading and the target character string is registered in the second dictionary by the registering; adding a first identifier to the head of the compression code read by the first reading, before output of the compression code; and adding a second identifier to the head of the compression code read by the second reading or by the third reading, before output of the compression code. determining whether a target character string is registered in a first dictionary, the target character string being a compression target contained in input data, the first dictionary correlating compression codes and corresponding strings; first reading, from the first dictionary, a compression code corresponding to the target character string when the target character string is registered in the first dictionary; searching the target character string in a second dictionary when the target character string is not registered in the first dictionary; second reading, from the second dictionary, a compression code corresponding to the target character string when the target character string is registered in the second dictionary; searching the target character string in first data when the target character string is not registered in the first dictionary nor in the second dictionary, the first data accumulating character strings that are a part of the input data and have been determined to be not registered in the first dictionary and are not from the second dictionary; registering the target character string in the second dictionary different from the first dictionary when the target character string has been found in the first data and the target character string is equal to or larger than a predetermined length; third reading a compression code corresponding to a registration number of the target character string in the second dictionary, when a compression code corresponding to the target character string is not read by the second reading and the target character string is registered in the second dictionary by the registering; adding a first identifier to the head of the compression code read by the first reading, before output of the compression code; and adding a second identifier to the head of the compression code read by the second reading or by the third reading, before output of the compression code.