Securing the Digital Realm: A Closer Look at S-boxes and P-boxes in Encryption

Maitri Hingu
4 min readDec 1, 2023

--

The Art and Science of S-boxes and P-boxes in Cryptography

In cryptography, S-boxes (Substitution boxes) and P-boxes (Permutation boxes) are components used in symmetric key algorithms, particularly in block ciphers. These boxes play a crucial role in the confusion and diffusion properties of cryptographic algorithms.

S-Box (Substitution Box):

S-Box, also known as the swap box.

Function: S-boxes are utilised for the purpose of substitution, wherein each set of input bits is substituted with a different set of bits based on a predetermined replacement table.
Purpose: The primary objective of S-boxes is to incorporate non-linearity into the cryptographic algorithm, hence enhancing its resistance against various cryptanalysis approaches, including linear and differential cryptanalysis.
Construction: S-boxes are commonly formed by the utilisation of mathematical procedures, such as modular arithmetic or polynomial transformations. The construction of S-boxes is a pivotal element in ensuring the security of a cryptographic method.
In the Advanced Encryption Standard (AES), a designated S-box is employed in the substitution layer. This S-box replaces each byte of the input with a corresponding byte from the S-box.

NOTE: This is just an example of 16 bit S-Box. But it depends on your encryption block size whether to keep it 16-bit, 32-bit, or 64-bit. Here 0th bit from the plain-text block will be substituted by 10th bit from the substitution key phrase. Keep in mind that plain-text block size and Key Phrase must be compatible size with the requirements of the cryptographic algorithm you are using.

S — BOX (For reference Only. It may change based on algorithm and its block size)

P-Box (Permutation Box):

A P-box, also known as a Permutation Box, is a cryptographic component that rearranges the bits of a binary input in a specific order.

Function: P-boxes are utilised for the purpose of permutation, wherein the placements of bits within the data block are reorganised based on a designated permutation table.
Purpose: P-boxes serve the purpose of enhancing the dispersion feature of a cryptographic method by dispersing the impact of individual bits throughout the entire block. They contribute to the guarantee that altering a single bit in the input results in the modification of several bits in the output.
Construction: P-boxes are created by utilising permutation tables that precisely define the rearrangement of bits. The permutation is individually applied to every block of the data.
In the Data Encryption Standard (DES), a designated P-box is utilised throughout the initial and final permutation stages. This P-box rearranges the positions of the bits based on a predetermined permutation.

NOTE: This is just an example of 16 bit P-Box. But it depends on your encryption block size whether to keep it 16-bit, 32-bit, or 64-bit. Here 0th bit from the plain-text block will be replaced by 12th bit from the plain-text itself.

P — BOX (For reference Only. It may change based on algorithm and its block size)

Types of P-Boxes

There are 3 types of P-Boxes available in modern block cipher.

  1. Straight P-Box: In this type of p-box, the number of inputs and output is the same. If inputs are n and outputs are m, then m=n.
  2. Expansion P-Box: An expansion p-box is a p-box with n inputs and m outputs where m>n, i.e., the number of outputs is more than the number of inputs. In this type of p-box, the values get repeated as for one input there is a possibility for more than one output.
  3. Compression P-Box: A compression p-box is a p-box with n inputs and m outputs where m<n, i.e., the number of outputs is less than the number of inputs. In this type of p-box, few bits are dropped as not all input bits are considered for output.

Invertibility of P-Boxes

The invertibility property holds true only for straight P-Boxes but not for expansion and compression P-Boxes.

  • In Compression P-Boxes, an input can be dropped while it is being encrypted, and the method used for decryption can’t figure out what the dropped bit was.
  • In Expansion P-Boxes, an input may be mapped to more than one output during encryption, so during decryption, the algorithm would not be able to guess the input as several inputs are mapped to the output.

In summary, S-boxes introduce non-linearity by substituting blocks of bits, while P-boxes introduce confusion and diffusion by permuting the positions of bits in the data block. Both S-boxes and P-boxes are essential components in designing secure and efficient block ciphers. The specific design and properties of these boxes depend on the cryptographic algorithm in use.

--

--

Maitri Hingu

Research Scholar & Assistant Professor in Department of ICT at Veer Narmad South Gujarat University, Surat.