Hello, I got implementation of Data Encryption Standard implementation in java (internet code) but the only part that I cannot understand is the S-Box which shown below. I know how S-Box works but I don't understand this code especially &0x20 and stuffs like that. The S-Box takes a 6 bit word such as 110110 as input.
It takes the first and last bits (110110) as row and the inner bits (110110) as column. Can anyone explain how this code below achieve what the S-Box does. If I want to change the input as a 4-bits word, how does the code change to accomodate it?
private static byte S(int boxNumber, byte src) {
// The first and last bits determine which 16-value row to
// reference, so we transform the 6-bit input into an
// absolute index based on the following bit shuffle:
// abcdef => afbcde
src = (byte) (src&0x20 | ((src&0x01)<<4) | ((src&0x1E)>>1));
return S[boxNumber-1][src];
}
I have tried searching for notes on java shifting (bitwise) but cannot understand it clearly.
Thanks.