var my_cipher_text="";
function ciphertxt()
{
document.form1.cipher.value="WUBEFIQLZURMVOFEHMYMWTIXCGTMPIFKRZUPMVOIRQMMWOZMPULMBNYVQQQMVMVJLEYMHFEFNZPSDLPPSDLPEVQMWCXYMDAVQEEFIQCAYTQOWCXYMWMSEMEFCFWYEYQETRLIQYCGMTWCWFBSMYFPLRXTQYEEXMRULUKSGWFPTLRQAERLUVPMVYQYCXTWFQLMTELSFJPQEHMOZCIWCIWFPZSLMAEZIQVLQMZVPPXAWCSMZMORVGVVQSZETRLQZPBJAZVQIYXEWWOICCGDWHQMMVOWSGNTJPFPPAYBIYBJUTWRLQKLLLMDPYVACDCFQNZPIFPPKSDVPTIDGXMQQVEBMQALKEZMGCVKUZKIZBZLIUAMMVZ";
}

////////
var my_search_word=new Array();
var word_index=new Array();

var my_wrd_arr=new Array();
var my_dif_arr=new Array();

function make_arr()
{
my_cipher_text=document.form1.cipher.value;

var arr_index=0;
var word_length=3;

for(var i=0;i<=my_cipher_text.length-word_length;i++)
	{
	my_search_word[arr_index]=my_cipher_text.substr(i,word_length);
		if(i==my_cipher_text.length-word_length)
			{
			i=0;word_length++;
			}
	arr_index++;
	if(word_length>5){break;}
	}

var count=0;
for(var i=0;i<my_search_word.length;i++)
	{count=0;
	word_index[i]=new Array();	
		for(j=0;j<my_search_word.length;j++)
		{
		if(my_search_word[i]==my_search_word[j])
			{
			word_index[i][count]=j;
			count++;
			}
		}
	}

}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function len_rep()
{
make_arr();

for(var i=0;i<word_index.length;i++)
	{if(word_index[i]!=null){
	 for(var j=0;j<word_index[i].length-1;j++)
	 	{		
		word_index[word_index[i][j+1]]=null;
		}
				}
	}
for(k=0;k<word_index.length;k++)
	{
	if((word_index[k]!=null)&&(word_index[k].length==1))
		{
		word_index[k]=null;
		}
	}
var wrd=0;
for(var i=0;i<word_index.length;i++)
	{
	if(word_index[i]!=null)
		{
		my_dif_arr[wrd]=new Array();
		my_wrd_arr[wrd]=my_search_word[i];
			for(var z=0;z<word_index[i].length-1;z++)
				{
				ind1=word_index[i][z];
				ind2=word_index[i][z+1];
				diff=ind2-ind1;
				my_dif_arr[wrd][z]=diff;
				
				}
		wrd++;
		}
	}
var layertext="";
layertext='<table width="0%" height="0%" border="0"><tr><td width="0%">';//ist table
layertext=layertext+'<TABLE  width="0%" BORDER="0"  CELLSPACING="0" CELLPADDING="0" ALIGN="LEFT" >';
layertext=layertext+'<tr><td width="0%" colspan="3"><font color="#99999a" face="arial" size="2" ><b>Vigenere Repeat Distance</b></font></td><td width="0%" colspan="19"><font color="#99999a" face="arial" size="2">Possible length of key &nbsp;(or factors)</font></td></tr>';
layertext=layertext+'<TR><TD width="0%"><font color="#99999a" face="arial" size="2">Repeated Sequence</font></TD><TD width="4%"><font color="#99999a" face="arial" size="2">&nbsp;Spacing</font></TD><TD width="0%">&nbsp; </TD>';
for(var i=2;i<21;i++)
{
if((i<10)&& i!=5)
layertext=layertext+'<td width="0%"><INPUT disabled TYPE="button" NAME="b2" size="3" VALUE="'+0+i+'" onClick="highest('+i+')"></TD>';
else if(i==5)
layertext=layertext+'<td width="0%"><INPUT  TYPE="button" NAME="b2" size="3" VALUE="'+0+i+'" onClick="highest('+i+')"></TD>';

else
layertext=layertext+'<td width="0%"><INPUT disabled TYPE="button" NAME="b2" size="3" VALUE="'+i+'" onClick="highest('+i+')"></TD>';
}
layertext=layertext+'</tr>';//end of first line of 2nd table

for(var j=0;j<my_wrd_arr.length;j++)
	{	
	for(var k=0;k<my_dif_arr[j].length;k++)
		{
			layertext=layertext+"<tr >";
			layertext=layertext+"<td width='0%' bgcolor='#cccccc'><font size='2' face='arial' color='#000000'>"+my_wrd_arr[j]+"</td>";
			layertext=layertext+"<td width='0%' bgcolor='#999999'><center><font size='2' face='arial' color='#000000'>"+my_dif_arr[j][k]+"</font></center></td>";
			layertext=layertext+"<td width='0%'>&nbsp;</td>";
			
			get_factor(my_dif_arr[j][k]);
			for(var t=2;t<21;t++)
			{	
			layertext=layertext+"<td width='0%'><div align='center'><font size='2' face='arial' color='#cccccc'>";
				for(var l=0;l<my_factor.length;l++)
					{
					
					if(my_factor[l]==t)
						{
						layertext=layertext+"x";//my_factor[l]
						}
					//else
						//{
						//layertext=layertext+"&nbsp;";
						//}
					}
			layertext=layertext+"</font></div></td>";
			}
		layertext=layertext+"</tr>";
		}
	

	}
	
layertext=layertext+"</table></font>";
layertext=layertext+'</td></tr></table>';//end of ist table
layertext=layertext+"<p align='justify'><font color='#cccccc' size='2' face='arial'>Shown above are the repetitions in our ciphertext and the spacing between them. E.g., the sequence EFI appears early in the ciphertext, and it is repeated 95 letters later. This implies that a 3-letter sequence has appeared in the plaintext has been encrypted using the same part of the key word, and has resulted in the same ciphertext, EFI.</p><p align='justify'>The factors of the spacings between different repetitions are indicated by crosses. For example, 95 is exactly divisible by just 5 and 19. The factors represent possible key lengths, because the EFI repetition after 95 spaces could be caused by a keyword of 19 letters repeated 5 times (19x5=95)  or it could be caused by a keyword of 5 spaces repeated 19 times (5x19=95).</p><p>To avoid coincidences (different plaintext sequences and different bits of the keyword giving the same ciphertext), we only consider repeated sequences of 3 letters or longer.</p><p align='justify'>The majority of spacings have a factor of 5, which suggests that the keyword contains five letters. Click on the column heading number 5 to proceed to the next step, and then scroll back to this part of the page again.</font></p>";

document.all["Layer11"].innerHTML=layertext	

}//end of function
var my_factor="";
function get_factor(num)
{
my_factor=null;
my_factor=new Array();
count=0;

if(num>20){c_num=num}
else{c_num=20}

for(var i=2;i<c_num;i++)
	{
	if(num%i==0)
		{
		my_factor[count]=i;count++;
		}
	
	}
	

}