A method for executing by a circuit a substitution operation whereby an output data is selected in an original substitution table using an input data as an index, wherein the substitution operation is performed using a masked substitution table, the input data being combined by Exclusive OR operations (⊕) with a first mask and the output data being combined by XOR operations with a second mask, characterized in that the masked substitution table is generated by performing a plurality of successive iterations, a first iteration of the plurality of iterations comprising generating a masked substitution table from the original substitution table, each of subsequent iterations of the successive iterations after the first iteration comprising generating a masked substitution table from a previous masked substitution table generated by a previous iteration of the successive iterations, the first iteration being performed in a protected area, each iteration comprising: selecting a first and a second input mask (U, V); computing a next value of a first mask parameter by applying XOR operations to a previous value of the first mask parameter and to the first input mask; computing a next value of a second mask parameter by applying XOR operations to a previous value of the second mask parameter and to the second input mask, the previous values of the first and second mask parameters being set to zero in the first iteration; selecting each value in the previous masked substitution table; and for each selected value (SB0[i], SB0[i⊕U]): computing a masked value (SB0[i]⊕V, SB0[i⊕U]⊕V) by applying XOR operations to the selected value and to the second input mask, computing a masked index (i⊕U) by applying XOR operations to the first mask and to an original index (i), and storing the masked value in the masked substitution table, the selected value being selected at the original index and the masked value being stored at the masked index, or the selected value being selected at the masked index and the masked value being stored at the original index, the substitution operation being performed using the masked substitution table generated in a last iteration of the successive iterations, the substitution operation being applied to the input data combined by XOR operations with the next value of the first mask parameter (u), computed in the last iteration, the output data of the masked substitution operation being equal to the output data of the substitution operation combined by XOR operations with the next value of the second mask parameter (v), computed in the last iteration. selecting a first and a second input mask (U, V); computing a next value of a first mask parameter by applying XOR operations to a previous value of the first mask parameter and to the first input mask; computing a next value of a second mask parameter by applying XOR operations to a previous value of the second mask parameter and to the second input mask, the previous values of the first and second mask parameters being set to zero in the first iteration; selecting each value in the previous masked substitution table; and for each selected value (SB0[i], SB0[i⊕U]): computing a masked value (SB0[i]⊕V, SB0[i⊕U]⊕V) by applying XOR operations to the selected value and to the second input mask, computing a masked index (i⊕U) by applying XOR operations to the first mask and to an original index (i), and storing the masked value in the masked substitution table, the selected value being selected at the original index and the masked value being stored at the masked index, or the selected value being selected at the masked index and the masked value being stored at the original index, computing a masked value (SB0[i]⊕V, SB0[i⊕U]⊕V) by applying XOR operations to the selected value and to the second input mask, computing a masked index (i⊕U) by applying XOR operations to the first mask and to an original index (i), and storing the masked value in the masked substitution table, the selected value being selected at the original index and the masked value being stored at the masked index, or the selected value being selected at the masked index and the masked value being stored at the original index, the substitution operation being performed using the masked substitution table generated in a last iteration of the successive iterations, the substitution operation being applied to the input data combined by XOR operations with the next value of the first mask parameter (u), computed in the last iteration, the output data of the masked substitution operation being equal to the output data of the substitution operation combined by XOR operations with the next value of the second mask parameter (v), computed in the last iteration.