A non-transient computer readable medium storing similarity calculation program causing a computer to calculate a distance between a first vector stored while being encrypted and a second vector entered from an input terminal, the similarity calculation program:
- transmitting to the input terminal a ciphertext of each element of the first vector and a weighted distance table with respect to combinations of possible values of the elements of the first vector and possible values of the elements of the second vector;
- having the input terminal refer to the weighted distance table to calculate a ciphertext of element distances for all combinations of the value of a single element of the second vector and possible values of elements of the first vector corresponding to the single element and receiving from the input terminal a ciphertext of the sum of the element distances calculated for each element of the second vector using additive homomorphic encryption;
- and
- extracting the distance between the first and the second vectors from the ciphertext of the sum.