i tried to fix the problem multiple time but i didn't get the proble that produces the exception which is "--------------------Configuration: -------------------- E
xception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 56
at testing.compressionPBox(testing.java:61)
at testing.parityDrop(testing.java:39)
at testing.roundKeyGenerator(testing.java:23)
at testing.main(testing.java:14)"
simply my program creates an array of 64 length ,then fill it by value from 1 to 64 then use the method roundKeyGenerator(roundArray) ; to executes the method ,when the method executes it creates an array of 56 length then use parityDrop method to return an array of length 56 form the initial array which has length of 64 ,but how to creates and drop some indexes !! simply i creates a predefined table which when i call the table method by index from initially start from 0 the method takes this index and sees what is the value of table_cell[index]=value_X then return value_x to the caller metod and put vaule_X as an index of the intailArray which has the size 64 and takes its value ,then stores it in the returned array depending where did its pointer stop and i think the pointers is the problem i think the second array of 56 length exceed the limit then the exception produced.
static int [] roundArray=new int [64];
public static void main(String [] arg)
{
for(int i=0;i<roundArray.length;i++)
roundArray[i]=i+1;
roundKeyGenerator(roundArray) ;
}
public static int [] roundKeyGenerator(int [] k) //takes an int array of length 64 repesents the key in binary representation
{
int [] key=new int [56];
key=parityDrop(k);
return key;
}
public static int [] parityDrop(int [] key)//takes an int array of length 64 repesents the key and return the key in an arrayof length 56
{
int index;
int [] result=new int[56];
for(int i=0;i<key.length;i++)
{
index=compressionPBox(i);//return cell value from straightPBoxTable
result [i]= key[index-1];
}
return result;
}
public static int compressionPBox(int i){
int cell[] =new int [56];
cell[0] =57 ;cell[1] =49 ;cell[2]=41 ;cell[3] =33 ;cell[4] =25 ;cell[5] =17 ;cell[6] =9 ;cell[7] =1;
cell[8] =58 ;cell[9] =50 ;cell[10]=42 ;cell[11]=34 ;cell[12]=26 ;cell[13]=18 ;cell[14]=10 ;cell[15]=2;
cell[16]=59 ;cell[17]=51 ;cell[18]=43 ;cell[19]=35 ;cell[20]=27 ;cell[21]=19 ;cell[22]=11 ;cell[23]=3;
cell[24]=60 ;cell[25]=52 ;cell[26]=44 ;cell[27]=36 ;cell[28]=63 ;cell[29]=55 ;cell[30]=47 ;cell[31]=39;
cell[32]=31 ;cell[33]=23 ;cell[34]=15 ;cell[35]=7 ;cell[36]=62 ;cell[37]=54 ;cell[38]=46 ;cell[39]=38;
cell[40]=30 ;cell[41]=22 ;cell[42]=14 ;cell[43]=6 ;cell[44]=61 ;cell[45]=53 ;cell[46]=45 ;cell[47]=37;
cell[48]=29 ;cell[49]=21 ;cell[50]=13 ;cell[51]=5 ;cell[52]=28 ;cell[53]=20 ;cell[54]=12 ;cell[55]=4;
return cell[i];
}// predefined permutation rule