The Shuffling Technique

(Ema_1, Masking/Decryption) – The shuffling technique is a little more complex than the replacement technique, and the symbols remain the same, but after encryption are shuffled. Basically, the shuffling technique can be explained as follows.

For convention and simplicity, the length of the key and blocks is always 16 bytes. This time, in order to observe the substitution in the 16-byte block, we give the source a different value (from “a” to “p” ), namely a=0, b=1, c=2, d=3, e=4, f=5, g=6, h=7, i=8, j=9, k=10, l=11, m=12, n=13, o=14, and p=15.

The algorithm

  1. Reads the value of the first byte of the key (index 0)
  2. Swaps the element of the data source with index 0 with the element with index the value read in 1.
  3. Reads the value of the second byte of the key (index 1)
  4. Swaps the data source element at index 1 with the element with index the value read in 3 and so on until the last byte of the last block.

This technique moves the data in the data source out of place, resulting in shuffling. Shuffling is about 20% slower than substitution because it requires more operations on the arrays.

This technique is effective and fast, but it must be used in combination with the replace method, because if it is used alone, you know the symbols of the data source! A solution might be to compress the data source before shuffling.

Note that with this technique, all the bytes of the data source remain unchanged, but are shuffled.

Below is the same example applied to substitution.

KEY & DATA
INDEX
KEY
VALUES
DATA BEFORE
SHUFFLING
SHUFFLING
(MASKING)
DATA
RESULT
000006agdd
001007bhll
002015cpee
003000dgff
004002epbb
005009fjcc
006013gann
007008hbii
008004ibpp
009010jfkk
010003kfgg
011012lmaa
012014mloo
013011namm
014001olhh
015005pcjj
000001002003004005006007008009010011012013014015

Example of shuffling in masking/encrypting stage

1. key(0)=6; a → data(6), g → data(0)
2. key(1)=7; b → data(7), h → data(1)
3. key(2)=15; c → data(15), p → data(2)
4. key(3)=0; d → data(0), g → data(3)

With the shuffling technique we get the highlighted elements [d, l, e, f, b, c, n, i, p, k, g, a, o, m, h, j]). At the computational level, all we need to do is overwrite the elements of an array. Again, Reordering will return the source string.

Scroll to Top