13,667,657 members
See more:
i'm studying DES but i have troubles with this part;;
can anyone tell me how this code work??
and why shift bits by 4 16 2 8??

```private void des( int[] inInts, int[] outInts, int[] keys )
{
int fval, work, right, leftt;
int round;
int keysi = 0;

leftt = inInts[0];
right = inInts[1];

work   = ((leftt >>>  4) ^ right) & 0x0f0f0f0f;
right ^= work;
leftt ^= (work << 4);

work   = ((leftt >>> 16) ^ right) & 0x0000ffff;
right ^= work;
leftt ^= (work << 16);

work   = ((right >>>  2) ^ leftt) & 0x33333333;
leftt ^= work;
right ^= (work << 2);

work   = ((right >>>  8) ^ leftt) & 0x00ff00ff;
leftt ^= work;
right ^= (work << 8);
right  = (right << 1) | ((right >>> 31) & 1);

work   = (leftt ^ right) & 0xaaaaaaaa;
leftt ^= work;
right ^= work;
leftt  = (leftt << 1) | ((leftt >>> 31) & 1);

for ( round = 0; round < 8; ++round )
{
work   = (right << 28) | (right >>> 4);
work  ^= keys[keysi++];
fval   = SP7[ work	       & 0x0000003f ];
fval  |= SP5[(work >>>  8) & 0x0000003f ];
fval  |= SP3[(work >>> 16) & 0x0000003f ];
fval  |= SP1[(work >>> 24) & 0x0000003f ];
work   = right ^ keys[keysi++];
fval  |= SP8[ work         & 0x0000003f ];
fval  |= SP6[(work >>>  8) & 0x0000003f ];
fval  |= SP4[(work >>> 16) & 0x0000003f ];
fval  |= SP2[(work >>> 24) & 0x0000003f ];
leftt ^= fval;
work   = (leftt << 28) | (leftt >>> 4);
work  ^= keys[keysi++];
fval   = SP7[ work	       & 0x0000003f ];
fval  |= SP5[(work >>>  8) & 0x0000003f ];
fval  |= SP3[(work >>> 16) & 0x0000003f ];
fval  |= SP1[(work >>> 24) & 0x0000003f ];
work   = leftt ^ keys[keysi++];
fval  |= SP8[ work	       & 0x0000003f ];
fval  |= SP6[(work >>>  8) & 0x0000003f ];
fval  |= SP4[(work >>> 16) & 0x0000003f ];
fval  |= SP2[(work >>> 24) & 0x0000003f ];
right ^= fval;
}

right  = (right << 31) | (right >>> 1);
work   = (leftt ^ right) & 0xaaaaaaaa;
leftt ^= work;
right ^= work;
leftt  = (leftt << 31) | (leftt >>> 1);
work   = ((leftt >>>  8) ^ right) & 0x00ff00ff;
right ^= work;
leftt ^= (work << 8);
work   = ((leftt >>>  2) ^ right) & 0x33333333;
right ^= work;
leftt ^= (work << 2);
work   = ((right >>> 16) ^ leftt) & 0x0000ffff;
leftt ^= work;
right ^= (work << 16);
work   = ((right >>>  4) ^ leftt) & 0x0f0f0f0f;
leftt ^= work;
right ^= (work << 4);
outInts[0] = right;
outInts[1] = leftt;
}```

What I have tried:

yeah i'm trying this part for 3 weeks. too difficult about permutation;; somebody help me T.T;;
Posted 2-May-18 21:08pm
Updated 2-May-18 22:52pm

## Solution 1

Do you have any idea how much work explaining code line by line is?
Every single line needs a paragraph of explanation! For example:
```int next = r.Next();
```

Create a new variable called "next" which can hold a integer value. From the previously declared Random instance "r", call the "Next" method to get a new random number, and assign it to the "next" variable.

Can you imagine how long it would take us to explain even a very short code fragment like your example, line by line?

No. It is not going to happen. If you have a specific problem, then ask a question about it. But think first - would you want to sit down for 45 minutes and type up a line-by-line description for no good reason?

So go back to Wiki and read the DES algorithm description again. Then read this: The DES Algorithm Illustrated[^] which explains DES pretty clearly.

Top Experts
Last 24hrsThis month
 OriginalGriff 294 ppolymorphe 170 Jochen Arndt 160 Richard MacCutchan 130 F-ES Sitecore 70
 OriginalGriff 4,296 ppolymorphe 1,807 Richard MacCutchan 1,720 Jochen Arndt 1,477 Dave Kreskowiak 853