I'm just trying to do the encrypt algorithm (DES) in java. So the algorithm is say that must divide the key that containing 56 bits into two parts of 28bits.
I have just try this to store the first and second half:
String firstPart="", secondPart="";
for(int i=0; i<PC1.length; i++){
for(int j=0; j<PC1.length-1; j++){
if(i<PC1.length/2)
firstPart+=PC56bit[i][j];
else
secondPart+=PC56bit[i][j];
}
}
Output:
firstPart = 1111000011001100101010101111
secondPart = 0101010101100110011110001111
The next step of the algorithm is to shift these two Strings (firstPart, secondPart) individually 16 times (with different shifting). So I just want to store these two string into a BigInteger array or any other types of array that make the process of shifting easier.
I tried with BigInteger and it doesn't doing it in a right way:
BigInteger C[] = new BigInteger[17], D[] = new BigInteger[17];
C[0] = new BigInteger(firstPart, 2);
D[0] = new BigInteger(secondPart, 2);
Output:
C[0] = 252496559
D[0] = 89548687
I don't know if my way of using BigInteger is true or not!
Is there any solves to my code? Or my way is wrong and there is a better way to do that?
Thanks.