I'm a little confused on how permutation and substitution works, I've been reading about S-DES and how it goes through P-Boxes and S-Boxes but what goes on inside P or S in the algorithm?

Are these p and B boxes generated from the key?

If for example I have some plaintext of 11010011011110100001 and want to permute or substitute it, what process would I follow? - Preferably by hand so I can understand it...

  • 2
    $\begingroup$ P box shuffles, S box transforms. The key is mixed into the input, so it has no effect on P but the results of S are changed. P's job is to diffuse, S to confuse. $\endgroup$
    – user10653
    Jan 4, 2018 at 22:43
  • $\begingroup$ @dingrite But what does P and S diffuse and confuse on? Based on what? For example XOR is a logically process as you can XOR with the key and input but with P or S what do you do? $\endgroup$
    – Erdss4
    Jan 4, 2018 at 22:52

1 Answer 1


The concepts here are diffusion and confusion, the goal of diffusion is to spread the influence of one bit over all bits. The job of confusion is to obscure the relationship between input and output.

S-boxes confuse (transform series of bits into different bits), P-boxes diffuse (shuffle bits around).

S-boxes need to have certain properties to be secure, they need to be non-linear to a degree where they can't even be linearly approximated. Given any two possible inputs into the box the difference in input must not correlate with difference in output.

Consider some input going into some number of S-boxes, it has changed drastically. But now consider that input being mixed (XOR) with the key before going to the box, it now changed in a very different way. If all you do is shuffle your entire function is linear and you can just build a matrix to represent it, then it's broken trivially.

In practice you apply shuffling and S-boxes multiple times (rounds) with multiple keys (derived from a master key).

  • $\begingroup$ Ok I understand what S and P are and what they are suppose to do, my confusion is with how do I perform S or P with an input such as 110101 and with a key like 10101010 for example? $\endgroup$
    – Erdss4
    Jan 4, 2018 at 23:00
  • $\begingroup$ P(S(110101 XOR 101010)) or S(P(110101) XOR 101010) $\endgroup$
    – user10653
    Jan 4, 2018 at 23:01
  • $\begingroup$ Ok so are you saying XOR is a form of S? But what about P what do you reorder on, what basis or is that defined randomly in code? $\endgroup$
    – Erdss4
    Jan 4, 2018 at 23:03
  • 1
    $\begingroup$ S is just a lookup table. P is just some way to shuffle bits, a primitive P would be to just rotate the bits in a circle by some number. XOR is what you do with the secret key in order to prevent someone who does not have it from reversing what you did. $\endgroup$
    – user10653
    Jan 4, 2018 at 23:05
  • $\begingroup$ Ohh ok then, so an S or P box is just generated randomly? If it was then how do you follow the decryption process? Like does the S or P box relate to the key or are they hard coded? $\endgroup$
    – Erdss4
    Jan 4, 2018 at 23:08

Your Answer

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

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