1. As far as understand AES takes 16 bytes, shuffles them and replaces every of the 256 bits via XOR.
  2. Then the same procedure applies to the next 16 bytes, and then again - until the entire file is encrypted.
  3. What if I just randomly shuffle numbers from 0 to 15, and also randomly write zeros and ones, 256 in total, and then use these results to do the same thing AES does (shuffling and substituting) - it would provide the same safety, wouldn't it?
  4. If I got the AES concept wrong, an explanation would be much appreciated.
  • 6
    $\begingroup$ NO. Many things are seriously wrong in the question: 1) 16 bytes is 128 bits, not 256. There's more than shuffling bytes and XORing them with a constant in AES. That's clear in the wiki article. 2) AES encrypts 16 bytes, not files. A block cipher mode of operation is needed for the later. The description made could be ECB mode. That's often insecure, even with AES. 3) What's proposed would be very insecure if applied to a file of more than 16 bytes. $\endgroup$
    – fgrieu
    Jul 29, 2022 at 17:08
  • $\begingroup$ also, xor does not replace bits, unless you xor with 11111... $\endgroup$ Jul 30, 2022 at 2:46

1 Answer 1


Your understanding of AES is completely wrong. It works nothing like that.

AES, being a block cipher, takes 16 input bytes and spits out 16 output bytes.* The process can be reversed by running the algorithm in reverse, but only if you use the same key. AES is actually made up of 10 to 14 rounds, which can be thought of as mini-ciphers. Like AES itself, they take 16 bytes of input and generate 16 bytes of output. A round's output is used as the input for the next round. Each round is also given its own key, created from the master key after being fed through an algorithm (the key schedule) that ensures that each key for each round is different.

The rounds themselves are composed of four stages, each of which also take 16 bytes of input and has an output of 16 bytes. They operate on the 16-byte input as if it were a 4-by-4 matrix of bytes.

  • SubBytes: This step substitutes each byte for another byte. The same input byte will always result in the same output byte. For example, 0x58 always becomes 0x6a. Here is the table.

  • ShiftRows: This step shifts each "row" of four bytes to the left and wraps them around (so it's more like a rotation than a shift). The first row is moved by 0, the second by 1, etc.

  • MixColumns: This step operates on each "column" of four bytes individually and reversibly mixes them using a simple permutation algorithm. Each column can be acted on in parallel.

  • AddRoundKey: This is the last step and is simply an XOR of the input with the round key.

The last round lacks the MixColumns step because it would not add any security, and the first round is preceded by an extra AddRoundKey step (so there will always be one more round key generated than there are rounds). Each round, on its own, is pretty weak, but when they're stacked up on top of each other, they create an extremely secure cipher. Even though breaking through only a few rounds is easy, it's necessary to break through them all at once to break the entire cipher.

* You can't just use AES to encrypt a file by running it over each 16-byte block sequentially or you end up with an ECB penguin. AES must be used with a secure mode of operation to be used to encrypt more than 16 bytes with any given key.

I strongly suggest you read A Stick Figure Guide to the Advanced Encryption Standard (AES). It is an entertaining visual explanation of AES in three different levels of difficulty after giving a brief history of the cipher: basic cryptographic concepts, AES specific design details, and lastly the underlying mathematics. It explains it in more detail than I do, and it explains why each step is done the way it is.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.