(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
- Reads the value of the first byte of the key (index 0)
- Swaps the element of the data source with index 0 with the element with index the value read in 1.
- Reads the value of the second byte of the key (index 1)
- 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 | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
000 | 006 | a | g | d | d | ||||||||||||||
001 | 007 | b | h | l | l | ||||||||||||||
002 | 015 | c | p | e | e | ||||||||||||||
003 | 000 | d | g | f | f | ||||||||||||||
004 | 002 | e | p | b | b | ||||||||||||||
005 | 009 | f | j | c | c | ||||||||||||||
006 | 013 | g | a | n | n | ||||||||||||||
007 | 008 | h | b | i | i | ||||||||||||||
008 | 004 | i | b | p | p | ||||||||||||||
009 | 010 | j | f | k | k | ||||||||||||||
010 | 003 | k | f | g | g | ||||||||||||||
011 | 012 | l | m | a | a | ||||||||||||||
012 | 014 | m | l | o | o | ||||||||||||||
013 | 011 | n | a | m | m | ||||||||||||||
014 | 001 | o | l | h | h | ||||||||||||||
015 | 005 | p | c | j | j | ||||||||||||||
000 | 001 | 002 | 003 | 004 | 005 | 006 | 007 | 008 | 009 | 010 | 011 | 012 | 013 | 014 | 015 |
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.