  In order to research the security of the knapsack problem under quantum
algorithm attack, we study the quantum algorithm for knapsack problem over Z_r
based on the relation between the dimension of the knapsack vector and r.
First, the oracle function is designed based on the knapsack vector B and S,
and the quantum algorithm for the knapsack problem over Z_r is presented. The
observation probability of target state is not improved by designing unitary
transform, but oracle function. Its complexity is polynomial. And its success
probability depends on the relation between n and r. From the above discussion,
we give the essential condition for the knapsack problem over Z_r against the
existing quantum algorithm attacks, i.e. r<O(2^n). Then we analyze the security
of the Chor-Rivest public-key crypto.
