function Out4 = SBox(In6, n) % Out4 = SBox(In6, n) % Inputs: In6 = a 6 bit binary vector , and n = an S-box number (between 1 % and 8). % Output: Out4= the 4 bit vector resulting from applying the nth S-box % from Table 6.8 to the 6 bit vector In6. %First we create a 3-dimensional array SBoxes for the 8 S-boxes. The nth %S-box will be SBoxes(:,:,n). if n < 1|n>8|floor(n)= 8, Out4(1) = 1; total = total - 8; else Out4(1) = 0; end if total >= 4, Out4(2) = 1; total = total - 4; else Out4(2) = 0; end if total >= 2, Out4(3) = 1; total = total - 2; else Out4(3) = 0; end if total >= 1, Out4(4) = 1; else Out4(4) = 0; end