protected char[] build_keyed_alphabet(String k,int total,int offset)
	{
		char[] result=new char[total];
		String k_u=k.toUpperCase();
		boolean[] filled=new boolean[total];
		int cur_pos=0;
		for(int i=0;i<k_u.length();i++)
		{
			char cur_c=k_u.charAt(i);
			int pos=cur_c-'A';
			if(filled[pos])
				continue;
			filled[cur_c-'A']=true;
			result[cur_pos]=cur_c;
			cur_pos++;
		}
		for(int i=0;i<total;i++)
		{
			char cur_c=(char)('A'+i);
			if(filled[i])
				continue;
			result[cur_pos]=cur_c;
			filled[i]=true;
			cur_pos++;
		}
		//move by offset
		if(offset!=0)
		{
		 for(int i=0;i<result.length;i++)
		 {
			char temp=result[(i+offset)%total];
			result[(i+offset)%26]=result[i];
			result[i]=temp;
		 }
		}
		return result;
	}