(Ema_0, Unmasking/Decryption) – The replacement technique does exactly the opposite of the substitution technique. The substitution algorithm reads the contents of the key sequentially, performs XOR (^) with the contents of the block and overwrites it. This restores the values of the original data source.
If both techniques were performed in the masking stage and the replacing technique was performed first, the substitution must be performed last in the unmasking stage.
Below is the substitution technique (unmasking) applied to the previous replacement (masking) example.
KEY & DATA INDEX | KEY VALUES | DATA BEFORE SUBSTITUTION | SUBSTITUTION (MASKING) | DATA RESULT | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
000 | 033 | @ | a | a | |||||||||||||||
001 | 048 | R | b | b | |||||||||||||||
002 | 043 | H | c | c | |||||||||||||||
003 | 045 | I | d | d | |||||||||||||||
004 | 044 | I | e | e | |||||||||||||||
005 | 037 | C | f | f | |||||||||||||||
006 | 046 | I | g | g | |||||||||||||||
007 | 040 | @ | h | h | |||||||||||||||
008 | 041 | @ | i | i | |||||||||||||||
009 | 042 | @ | j | j | |||||||||||||||
010 | 036 | O | k | k | |||||||||||||||
011 | 034 | N | l | l | |||||||||||||||
012 | 038 | K | m | m | |||||||||||||||
013 | 039 | I | n | n | |||||||||||||||
014 | 035 | L | o | o | |||||||||||||||
015 | 047 | _ | p | p | |||||||||||||||
000 | 001 | 002 | 003 | 004 | 005 | 006 | 007 | 008 | 009 | 010 | 011 | 012 | 013 | 014 | 015 |
Example of substitution at the unmasking/decryption stage
ASCII decimal unsigned values:
@=64, R=82, H=72, I=73, I=73, C=67, I=73, @=64, @=64, @=64, O=79, N=78, K=75, I=73, L=76, _=95
The four first replacement:
1. @=64; key(0)=33; 64^33=97, a → data(0)
2. R=82; key(1)=48; 82^48=98, b → data(1)
3. H=72; key(2)=43; 72^43=99, c → data(2)
4. I=73; key(3)=45; 73^45=100, d → data(3)
and so on.
With the substitution technique we get the source string [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p] as output.