Search code examples
c++aes

AES - How do I write Inverse Sub Bytes in C++?


How do I write Inverse Sub Bytes for AES Decryption in C++? I only found Sub Bytes for AES Encryption, which is shown below.

void SubBytes(unsigned char* state)
{
    for(int i=0, i<16; i++)
    state[i] = sbox[state[i]];
}


Solution

  • I am hardly a programmer but you could define an inverse sbox table using the sbox table. define its entries via

    sboxinv[sbox[u]]:=u

    as u ranges over 0 to 255.

    Then use the same structure as in the code fragment above

    void InvSubBytes(unsigned char* state)
    {
        for(int i=0, i<16; i++)
        state[i] = sboxinv[state[i]];
    }