void Evenodd_decoding(int[] restarts){
  int i, j, stripe, k;
  int rs_disk1=-1;
  int rs_disk2=-1;
  int rs_nbr=0;
  for (i=0; i < data_disk_nbr + 2; i++) {
    if (restarts[i] == 1) {
      rs_disk1=i;
      rs_nbr++;
      break;
    }
  }
  if (rs_disk1 != -1) {
    for (i=rs_disk1 + 1; i < data_disk_nbr + 2; i++) {
      if (restarts[i] == 1) {
        rs_disk2=i;
        rs_nbr++;
        break;
      }
    }
  }
  if (rs_disk1 != -1) {
    Arrays.fill(check_data[rs_disk1],(char)0);
  }
  if (rs_disk2 != -1) {
    Arrays.fill(check_data[rs_disk2],(char)0);
  }
  if (rs_disk1 >= data_disk_nbr) {
    if (restarts[data_disk_nbr] == 1) {
      STAR_encoding_row();
    }
    if (restarts[data_disk_nbr + 1] == 1) {
      STAR_encoding_diag1();
    }
  }
  if (rs_disk1 < data_disk_nbr && rs_nbr == 1) {
    for (i=0; i < stripe_unit_size; i++) {
      for (j=0; j <= data_disk_nbr; j++) {
        if (j != rs_disk1) {
          check_data[rs_disk1][i]^=check_data[j][i];
        }
      }
    }
  }
  if (rs_nbr == 2 && rs_disk1 < data_disk_nbr && rs_disk2 >= data_disk_nbr) {
    if (rs_disk2 == data_disk_nbr + 1) {
      for (i=0; i < stripe_unit_size; i++) {
        for (j=0; j <= data_disk_nbr; j++) {
          if (j != rs_disk1)           check_data[rs_disk1][i]^=check_data[j][i];
        }
      }
      STAR_encoding_diag1();
    }
    if (rs_disk2 == data_disk_nbr) {
      char[] tmp;
      tmp=new char[p * block_size];
      char[] tmp_for_s;
      tmp_for_s=new char[block_size];
      for (stripe=0; stripe < block_nbr + 1; stripe++) {
        for (i=0; i < data_disk_nbr; i++) {
          for (j=0; j < block_size; j++) {
            k=(stripe - i + p) % p;
            if (k < block_nbr)             tmp[stripe * block_size + j]^=check_data[i][k * block_size + j];
          }
        }
      }
      stripe=(rs_disk1 + p - 1) % p;
      for (i=0; i < block_size; i++) {
        if (stripe == p - 1)         tmp_for_s[i]=tmp[stripe * block_size + i];
 else         tmp_for_s[i]=(char)(tmp[stripe * block_size + i] ^ check_data[data_disk_nbr + 1][stripe * block_size + i]);
      }
      for (i=0; i < block_nbr; i++) {
        for (j=0; j < block_size; j++) {
          tmp[i * block_size + j]^=(tmp_for_s[j] ^ check_data[data_disk_nbr + 1][i * block_size + j]);
        }
      }
      for (j=0; j < block_size; j++)       tmp[block_nbr * block_size + j]^=tmp_for_s[j];
      for (i=0; i < p; i++) {
        j=(i + p - rs_disk1) % p;
        if (j < p - 1) {
          System.arraycopy(tmp,i * block_size,check_data[rs_disk1],j * block_size,block_size);
        }
      }
      STAR_encoding_row();
    }
  }
  if (rs_nbr == 2 && rs_disk1 < data_disk_nbr && rs_disk2 < data_disk_nbr) {
    char[] tmp;
    tmp=new char[p * block_size];
    char[] tmp_for_s;
    tmp_for_s=new char[block_size];
    for (i=0; i < block_nbr; i++) {
      for (j=0; j < block_size; j++) {
        tmp_for_s[j]^=check_data[data_disk_nbr][i * block_size + j];
        tmp_for_s[j]^=check_data[data_disk_nbr + 1][i * block_size + j];
      }
    }
    for (stripe=0; stripe < block_nbr + 1; stripe++) {
      for (i=0; i < data_disk_nbr; i++) {
        k=(stripe - i + p) % p;
        if (k < block_nbr)         for (j=0; j < block_size; j++) {
          tmp[stripe * block_size + j]^=check_data[i][k * block_size + j];
        }
      }
    }
    for (i=0; i < block_nbr; i++) {
      for (j=0; j < block_size; j++) {
        tmp[i * block_size + j]^=(check_data[data_disk_nbr + 1][i * block_size + j] ^ tmp_for_s[j]);
      }
    }
    for (j=0; j < block_size; j++)     tmp[block_nbr * block_size + j]^=tmp_for_s[j];
    stripe=(rs_disk1 + p - 1) % p;
    System.arraycopy(tmp,stripe * block_size,tmp_for_s,0,block_size);
    while (true) {
      k=(stripe - rs_disk2 + p) % p;
      if (k == block_nbr)       break;
      System.arraycopy(tmp_for_s,0,check_data[rs_disk2],k * block_size,block_size);
      for (j=0; j < block_size; j++) {
        for (i=0; i <= data_disk_nbr; i++)         if (i != rs_disk1)         check_data[rs_disk1][k * block_size + j]^=check_data[i][k * block_size + j];
      }
      stripe=(k + rs_disk1 + p) % p;
      for (j=0; j < block_size; j++) {
        tmp_for_s[j]=(char)(check_data[rs_disk1][k * block_size + j] ^ tmp[stripe * block_size + j]);
      }
    }
  }
}

void Evenodd_decoding ( int [ ] restarts ) { int i , j , stripe , k ; int rs_disk1 = - 1 ; int rs_disk2 = - 1 ; int rs_nbr = 0 ; for ( i = 0 ; i < data_disk_nbr + 2 ; i ++ ) { if ( restarts [ i ] == 1 ) { rs_disk1 = i ; rs_nbr ++ ; break ; } } if ( rs_disk1 != - 1 ) { for ( i = rs_disk1 + 1 ; i < data_disk_nbr + 2 ; i ++ ) { if ( restarts [ i ] == 1 ) { rs_disk2 = i ; rs_nbr ++ ; break ; } } } if ( rs_disk1 != - 1 ) { Arrays . fill ( check_data [ rs_disk1 ] , ( char ) 0 ) ; } if ( rs_disk2 != - 1 ) { Arrays . fill ( check_data [ rs_disk2 ] , ( char ) 0 ) ; } if ( rs_disk1 >= data_disk_nbr ) { if ( restarts [ data_disk_nbr ] == 1 ) { STAR_encoding_row ( ) ; } if ( restarts [ data_disk_nbr + 1 ] == 1 ) { STAR_encoding_diag1 ( ) ; } } if ( rs_disk1 < data_disk_nbr && rs_nbr == 1 ) { for ( i = 0 ; i < stripe_unit_size ; i ++ ) { for ( j = 0 ; j <= data_disk_nbr ; j ++ ) { if ( j != rs_disk1 ) { check_data [ rs_disk1 ] [ i ] ^= check_data [ j ] [ i ] ; } } } } if ( rs_nbr == 2 && rs_disk1 < data_disk_nbr && rs_disk2 >= data_disk_nbr ) { if ( rs_disk2 == data_disk_nbr + 1 ) { for ( i = 0 ; i < stripe_unit_size ; i ++ ) { for ( j = 0 ; j <= data_disk_nbr ; j ++ ) { if ( j != rs_disk1 ) check_data [ rs_disk1 ] [ i ] ^= check_data [ j ] [ i ] ; } } STAR_encoding_diag1 ( ) ; } if ( rs_disk2 == data_disk_nbr ) { char [ ] tmp ; tmp = new char [ p * block_size ] ; char [ ] tmp_for_s ; tmp_for_s = new char [ block_size ] ; for ( stripe = 0 ; stripe < block_nbr + 1 ; stripe ++ ) { for ( i = 0 ; i < data_disk_nbr ; i ++ ) { for ( j = 0 ; j < block_size ; j ++ ) { k = ( stripe - i + p ) % p ; if ( k < block_nbr ) tmp [ stripe * block_size + j ] ^= check_data [ i ] [ k * block_size + j ] ; } } } stripe = ( rs_disk1 + p - 1 ) % p ; for ( i = 0 ; i < block_size ; i ++ ) { if ( stripe == p - 1 ) tmp_for_s [ i ] = tmp [ stripe * block_size + i ] ; else tmp_for_s [ i ] = ( char ) ( tmp [ stripe * block_size + i ] ^ check_data [ data_disk_nbr + 1 ] [ stripe * block_size + i ] ) ; } for ( i = 0 ; i < block_nbr ; i ++ ) { for ( j = 0 ; j < block_size ; j ++ ) { tmp [ i * block_size + j ] ^= ( tmp_for_s [ j ] ^ check_data [ data_disk_nbr + 1 ] [ i * block_size + j ] ) ; } } for ( j = 0 ; j < block_size ; j ++ ) tmp [ block_nbr * block_size + j ] ^= tmp_for_s [ j ] ; for ( i = 0 ; i < p ; i ++ ) { j = ( i + p - rs_disk1 ) % p ; if ( j < p - 1 ) { System . arraycopy ( tmp , i * block_size , check_data [ rs_disk1 ] , j * block_size , block_size ) ; } } STAR_encoding_row ( ) ; } } if ( rs_nbr == 2 && rs_disk1 < data_disk_nbr && rs_disk2 < data_disk_nbr ) { char [ ] tmp ; tmp = new char [ p * block_size ] ; char [ ] tmp_for_s ; tmp_for_s = new char [ block_size ] ; for ( i = 0 ; i < block_nbr ; i ++ ) { for ( j = 0 ; j < block_size ; j ++ ) { tmp_for_s [ j ] ^= check_data [ data_disk_nbr ] [ i * block_size + j ] ; tmp_for_s [ j ] ^= check_data [ data_disk_nbr + 1 ] [ i * block_size + j ] ; } } for ( stripe = 0 ; stripe < block_nbr + 1 ; stripe ++ ) { for ( i = 0 ; i < data_disk_nbr ; i ++ ) { k = ( stripe - i + p ) % p ; if ( k < block_nbr ) for ( j = 0 ; j < block_size ; j ++ ) { tmp [ stripe * block_size + j ] ^= check_data [ i ] [ k * block_size + j ] ; } } } for ( i = 0 ; i < block_nbr ; i ++ ) { for ( j = 0 ; j < block_size ; j ++ ) { tmp [ i * block_size + j ] ^= ( check_data [ data_disk_nbr + 1 ] [ i * block_size + j ] ^ tmp_for_s [ j ] ) ; } } for ( j = 0 ; j < block_size ; j ++ ) tmp [ block_nbr * block_size + j ] ^= tmp_for_s [ j ] ; stripe = ( rs_disk1 + p - 1 ) % p ; System . arraycopy ( tmp , stripe * block_size , tmp_for_s , 0 , block_size ) ; while ( true ) { k = ( stripe - rs_disk2 + p ) % p ; if ( k == block_nbr ) break ; System . arraycopy ( tmp_for_s , 0 , check_data [ rs_disk2 ] , k * block_size , block_size ) ; for ( j = 0 ; j < block_size ; j ++ ) { for ( i = 0 ; i <= data_disk_nbr ; i ++ ) if ( i != rs_disk1 ) check_data [ rs_disk1 ] [ k * block_size + j ] ^= check_data [ i ] [ k * block_size + j ] ; } stripe = ( k + rs_disk1 + p ) % p ; for ( j = 0 ; j < block_size ; j ++ ) { tmp_for_s [ j ] = ( char ) ( check_data [ rs_disk1 ] [ k * block_size + j ] ^ tmp [ stripe * block_size + j ] ) ; } } } }
restore data like evenodd
