public String encode(String plain)
	 {
		int[] key_num=Cadenus.generate_order(key);
	//	int last_digit=key_num[key_num.length-1];
		char[][] trans_block=Gromark.build_trans_block(key_num,key);
		char[] keyed_alphabet=build_keyed_alphabet(trans_block,key_num);
		//int primer=get_num(key_num);
		//int[] num_k=generate_num_k(plain,primer);
		
		String plain_u=plain.toUpperCase();
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<key_num.length;i++)
		{
			sb.append(key_num[i]);
		}		
		int key_len=key.length();
		int key_index=0;
		//int last=0;
		for(int i=0;i<plain.length();i+=key_len)
		{
			int end=i+key.length()>plain.length()?plain.length():i+key_len;
			//last=end-i;
			//String sub_str=plain.substring(i,end);
			int alphabet_index=Generic_Func.find_char(keyed_alphabet, key.charAt(key_index));
			sb.append(get_ct(plain_u,key_num,i,end,keyed_alphabet,alphabet_index));
			if(key_index==key.length()-1)
			{
				key_index=0;
			}
			else
			{
				key_index++;
			}
			if(end==plain.length())
			{
				sb.append(key_num[end-i-1]);
			}
			else
			{
			   update_num_k(key_num);
			}
			
		}
		//sb.append(key_num[last]);
		//Random r=new Random();
		//int key_len=1+r.nextInt(7);
		//sb.append(last_digit);
		return sb.toString();
	 }