0

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.

Community
  • 1
  • 1
Sivar
  • 15
  • 6
  • You are correctly seeing the decimal form of the binary numbers you are inputting. What are you expecting? – Teepeemm Mar 06 '17 at 15:09
  • Why they are in decimal, I just want them to be stored as they are in binary! @Teepeemm – Sivar Mar 06 '17 at 15:20
  • @Sivar they're not in decimal; that's just how BigIntegers appear when they are printed. – Klitos Kyriacou Mar 06 '17 at 15:42
  • @KlitosKyriacou you mean that they are stored in the binary format in C[0] and D[0]? which means there is no need to convert that decimal which is printed to binary again? – Sivar Mar 06 '17 at 15:47
  • 1
    How they're stored isn't the programmer's concern. If you want to get a digit, then you can print the number to binary and get the digit from the string. – Teepeemm Mar 06 '17 at 16:01

0 Answers0