A method for mapping an input message to an output message by a keyed cryptographic operation in a white-box cryptographic system to resist differential attacks, wherein the keyed cryptographic operation is a substitution-permutation network, SPN, the keyed cryptographic operation including a plurality of substitution layers and state data, comprising: mapping the input message to first state data in a first substitution layer of the keyed cryptographic operation, wherein the first substitution layer includes N basic blocks that implement the first substitution layer and wherein a non-linear encoding having a first size is placed on the inputs and outputs of the N basic blocks of the first substitution layer, where N is an integer; mapping the first state data to second state data in a plurality of intermediate substitution layers of the keyed cryptographic operation, wherein the intermediate substitution layers include M basic blocks that implement the intermediate substitution layers and wherein a plurality of non-linear encodings having a second size are placed on the inputs and outputs of the M basic blocks of the intermediate substitution layers, where M is an integer; and mapping the second state data to an output message in a final substitution layer of the keyed cryptographic operation, wherein the final substitution layer includes K basic blocks that implement the final substitution layer and wherein a non-linear encoding having a third size is placed on the inputs and outputs of the K basic blocks of the final substitution layer, where K is an integer, wherein the first and third size is greater than the second size, wherein N > M, wherein K > M, wherein the first size is 8-bits, the second size is 4-bits, and the third size is 8-bits, and wherein basic blocks implementing an XOR function in the intermediated substitution layers operate on inputs having the second size to produce outputs having the second size; basic blocks implementing an XOR function in the first substitution layer operate on inputs having the first size to produce outputs having the first size; and basic blocks implementing an XOR function in the last substitution layer operate on inputs having the third size to produce outputs having the third size. mapping the input message to first state data in a first substitution layer of the keyed cryptographic operation, wherein the first substitution layer includes N basic blocks that implement the first substitution layer and wherein a non-linear encoding having a first size is placed on the inputs and outputs of the N basic blocks of the first substitution layer, where N is an integer; mapping the first state data to second state data in a plurality of intermediate substitution layers of the keyed cryptographic operation, wherein the intermediate substitution layers include M basic blocks that implement the intermediate substitution layers and wherein a plurality of non-linear encodings having a second size are placed on the inputs and outputs of the M basic blocks of the intermediate substitution layers, where M is an integer; and mapping the second state data to an output message in a final substitution layer of the keyed cryptographic operation, wherein the final substitution layer includes K basic blocks that implement the final substitution layer and wherein a non-linear encoding having a third size is placed on the inputs and outputs of the K basic blocks of the final substitution layer, where K is an integer, wherein the first and third size is greater than the second size, wherein N > M, wherein K > M, wherein the first size is 8-bits, the second size is 4-bits, and the third size is 8-bits, and wherein basic blocks implementing an XOR function in the intermediated substitution layers operate on inputs having the second size to produce outputs having the second size; basic blocks implementing an XOR function in the first substitution layer operate on inputs having the first size to produce outputs having the first size; and basic blocks implementing an XOR function in the last substitution layer operate on inputs having the third size to produce outputs having the third size.