A ciphertext processing device comprising: first acquisition unit adapted to acquire a first polynomial into which first text data is converted with a first order and which is encrypted in a homomorphic encryption with a first public key and a first square-value polynomial into which square-value vector data of each component of the first text data is converted with the first order and which is encrypted in the homomorphic encryption with the first public key; second acquisition unit adapted to acquire a second polynomial into which second text data is converted with a second order and which is encrypted in the homomorphic encryption with the first public key and a second square-value polynomial into which square-value vector data of each component of the second text data is converted with the second order and which is encrypted in the homomorphic encryption with the first public key; and a determination unit adapted to calculate a norm distance of a vector space between the first text data and the second text data, as a pattern matching which determines whether the second text data is included in the first text data, characterized in that the determination unit is further adapted to calculate auxiliary data for calculation the norm distance and calculates, while maintaining the encrypting, the norm distance using the auxiliary data, the first polynomial, the first square-value polynomial, the second polynomial and the second square-value polynomial, the first polynomial and the first square-value polynomial including each element of a numerical vector of the first text data which is represented by a coefficient in the first order, and the second polynomial and the second square-value polynomial including each element of a numerical vector of the second text data which is represented by a coefficient in the second order. first acquisition unit adapted to acquire a first polynomial into which first text data is converted with a first order and which is encrypted in a homomorphic encryption with a first public key and a first square-value polynomial into which square-value vector data of each component of the first text data is converted with the first order and which is encrypted in the homomorphic encryption with the first public key; second acquisition unit adapted to acquire a second polynomial into which second text data is converted with a second order and which is encrypted in the homomorphic encryption with the first public key and a second square-value polynomial into which square-value vector data of each component of the second text data is converted with the second order and which is encrypted in the homomorphic encryption with the first public key; and a determination unit adapted to calculate a norm distance of a vector space between the first text data and the second text data, as a pattern matching which determines whether the second text data is included in the first text data, characterized in that the determination unit is further adapted to calculate auxiliary data for calculation the norm distance and calculates, while maintaining the encrypting, the norm distance using the auxiliary data, the first polynomial, the first square-value polynomial, the second polynomial and the second square-value polynomial, the first polynomial and the first square-value polynomial including each element of a numerical vector of the first text data which is represented by a coefficient in the first order, and the second polynomial and the second square-value polynomial including each element of a numerical vector of the second text data which is represented by a coefficient in the second order. <EOS>