public String encode(String plain)
	  {
		  //Assume plain has a length which is multiply of 25
		  //Need to generate a key of length x, 25x=length of plain
	//	  if(!is_valid(plain))
		//	  return null;
		  //add 'X' till the length is a multiply of 25
		 // if(plain.endsWith("mess"))
		/*  if(plain.startsWith("thisiswhatdictionariesusedtolooklike"))
		 {
		    System.err.println("test");	  
		 }*/
		  String new_plain=add_comp(plain);
		//  int key_len=plain.length()/25;
		 // key=generate_key_len(key_len);
		  if (period!=key.length() || new_plain.length()/25!=period)
		  {
			  return null;
		  }
		  char[][] matrix=generate_matrix(key,new_plain);
		  int[] order=generate_order(key);
		  Integer[] order_i=new Integer[order.length];
		  for(int i=0;i<order.length;i++)
		  {
			  order_i[i]=Integer.valueOf(order[i]);
		  }
		  char[][] cipher_text=new char[25][period];
		  int cur_col=1;
		  while(cur_col<=period)
		  {
			 int col_index=Arrays.asList(order_i).indexOf(cur_col);
			 char k=key.charAt(col_index);
			 if(k=='V')
			 {
				 k='W';
			 }
			 int k_index=get_index(k);
			// int k_index=Arrays.asList(key_array).indexOf(k);
			 for(int i=0;i<25;i++)
			 {
				 cipher_text[i][cur_col-1]=matrix[k_index][col_index];
				 if(k_index==24)
				 {
					 k_index=0;
				 }
				 else
				 {
					 k_index++;
				 }
			 }
			 cur_col++;
		  }
		  StringBuilder sb=new StringBuilder();
		  for(int row=0;row<25;row++)
		  {
			  for(int col=0;col<period;col++)
			  {
				  sb.append(cipher_text[row][col]);
			  }
		  }
		  return sb.toString().toUpperCase();
		 // int[] order=Generic_Func.generate_random_perm(1, period);
		  
		  
	  }