Anti-attack method and device for data

The invention provides an anti-attack method and device for data. The method comprises the steps that before a first value and a second value, used as first input data and second input data respectively, are input to a first circuit and a second circuit of preset circuits, whether the first value is equal to the second value is judged; when the first value and the second value are equal, two unequal data are input to the first circuit and the second circuit as the first input data and the second input data; after the first circuit and the second circuit carry out computation on the two unequal data respectively to obtain a first computation result and a second computation result, and a third circuit of the preset circuits is used for carrying out computation on the first computation result and the second computation result, computation results of the corresponding preset circuits when the first value and the second value are used as the first input data and the second input data respectively are output. The method and device can improve data safety.