var A = new Array('TIKRDBPQUFNGWOZYCSJLHXEAMV','XZREOMHWGIJKSPQBCFYLTNVUAD','ZKBUQXYEHMDIOWGFVSJCRATNLP');var B = new Array('XFQEWJLUBSCTYKNGHDRAIZMVPO','YPQZDRIGJKLTFVENOCMUXWHASB','VCTKHPOILSBYJXMZEURWDQNFGA');var U = 'SXUWQVTORZPNYLHKEIAGCFDBMJ';var K = new Array('M','Q');var kNone = 0, kOriginal = 1, kFunction = 2;var theTimeout;var theVelocity;function CalcInverse(n){	var theString = A[n];	var theNewString = '';	var i;		for (i=0;i<26;i++)		theNewString = theNewString + NumToChar(theString.indexOf(NumToChar(i)));			B[n] = theNewString;}	// CalcInversefunction TestWheel(theString){	var i;	var theAlphabet = new Array(26);	if (theString.length == 26)	{		for (i=0;i<26;i++)		{			if (!CheckAlphabet(theString.charAt(i)))				return false;		}	// for		for (i=0;i<26;i++)			theAlphabet[i] = false;				for (i=0;i<26;i++)			theAlphabet[CharToNum(theString.charAt(i))] = true;					for (i=0;i<26;i++)		{			if (!theAlphabet[i])				return false;		}	// for				return true;	}	// if	return false;}	// TestWheelfunction TestWalze(theString){	if (!TestWheel(theString))		return false;			var i;			for (i=0;i<26;i++)	{		if (theString.charAt(CharToNum(theString.charAt(i))) != NumToChar(i))			return false;	}	// for		return true;}	// TestWalzefunction TestKerben(theString){	if (theString.length != 2)		return false;			if (!CheckAlphabet(theString.charAt(0))||!CheckAlphabet(theString.charAt(1)))		return false;	return true;}	// TestKerbenfunction ReadWheel(thePath,n){	var theBegin, theEnd, theString;	var thePosition = thePath.indexOf('R'+n+'=');	var theLength = thePath.length;	if (thePosition >= 0)	{		theBegin = thePosition+3;		theEnd = thePath.indexOf('&',theBegin);		if (theEnd < 0)			theEnd = theLength;				theString = thePath.substring(theBegin,theEnd);		if (TestWheel(theString))		{			A[n-1] = theString;			CalcInverse(n-1);		}	// if	}	// if	}	// ReadWheelfunction ReadWalze(thePath){	var theBegin, theEnd, theString;	var thePosition = thePath.indexOf('U=');	var theLength = thePath.length;	if (thePosition >= 0)	{				theBegin = thePosition+2;		theEnd = thePath.indexOf('&',theBegin);		if (theEnd < 0)			theEnd = theLength;							theString = thePath.substring(theBegin,theEnd);		if (TestWalze(theString))			U = theString;	}	// if	}	// ReadWalzefunction ReadKerben(thePath){	var theBegin, theEnd, theString;	var thePosition = thePath.indexOf('K=');	var theLength = thePath.length;	if (thePosition >= 0)	{				theBegin = thePosition+2;		theEnd = thePath.indexOf('&',theBegin);		if (theEnd < 0)			theEnd = theLength;							theString = thePath.substring(theBegin,theEnd);		if (theString.length != 2)			return;					if (!CheckAlphabet(theString.charAt(0))||!CheckAlphabet(theString.charAt(1)))			return;				K[0] = theString.charAt(0);					K[1] = theString.charAt(1);	}	// if	}	// ReadKerbenfunction GetVariables(){	var thePath = location.href;	var theQuestionMark = thePath.indexOf('?');	if (theQuestionMark < 0)		return;		thePath = thePath.substring(theQuestionMark+1,thePath.length);	thePath = thePath.toUpperCase();	var theLength = thePath.length;	var i;		for (i=1;i<=3;i++)		ReadWheel(thePath,i);	ReadWalze(thePath);		ReadKerben(thePath);	}	// GetVariablesGetVariables();function HandleOpen(theLink){	var thePath = location.href;	var theQuestionMark = thePath.indexOf('?');	if (theQuestionMark >= 0)		thePath = thePath.substring(theQuestionMark,thePath.length);	else		thePath = '';	self.open(theLink+thePath,'_self');	return false;}	// HandleOpenfunction GetReferrer(){	var thePath = document.referrer;	if (thePath != null)	{		var theQuestionMark = thePath.indexOf('?');		if (theQuestionMark < 0)			theQuestionMark = thePath.length;					var theSlash = thePath.lastIndexOf('/');				thePath = thePath.substring(theSlash+1,theQuestionMark);	}	// if	else		thePath = 'index.html';	return thePath;}	// GetReferrerfunction HandleOK(){	var i;	for (i=1;i<=3;i++)	{		if (!(TestWheel(document.eingabe.elements['r'+i].value)))		{			alert('Die Eingaben fuer das Rad '+i+' sind falsch!');			document.eingabe.elements['r'+i].select();			return;		}	// if	}	// for		if (!TestWalze(document.eingabe.walze.value))	{		alert('Die Eingaben fuer die Umkehrwalze sind falsch!');		document.eingabe.walze.select();		return;	}	// if		if (!TestKerben(document.eingabe.k1.value+document.eingabe.k2.value))	{		alert('Die Eingaben fuer die Kerben sind falsch!');		document.eingabe.k1.select();		return;		}	// if		open(GetReferrer()+'?r1='+document.eingabe.r1.value+'&r2='+document.eingabe.r2.value+'&r3='+document.eingabe.r3.value +'&u='+document.eingabe.walze.value+'&k='+document.eingabe.k1.value+document.eingabe.k2.value,'_self');}	// HandleOKfunction CharToNum(c){	if (c == 'A')		return 0;	else if (c == 'B')	return 1;	else if (c == 'C')	return 2;	else if (c == 'D')	return 3;	else if (c == 'E')	return 4;	else if (c == 'F')	return 5;	else if (c == 'G')	return 6;	else if (c == 'H')	return 7;	else if (c == 'I')	return 8;	else if (c == 'J')	return 9;	else if (c == 'K')	return 10;	else if (c == 'L')	return 11;	else if (c == 'M')	return 12;	else if (c == 'N')	return 13;	else if (c == 'O')	return 14;	else if (c == 'P')	return 15;	else if (c == 'Q')	return 16;	else if (c == 'R')	return 17;	else if (c == 'S')	return 18;	else if (c == 'T')	return 19;	else if (c == 'U')	return 20;	else if (c == 'V')	return 21;	else if (c == 'W')	return 22;	else if (c == 'X')	return 23;	else if (c == 'Y')	return 24;	else 				return 25;}	// CharToNumfunction NumToChar(n){	if (n == 0)			return 'A';	else if (n == 1)	return 'B';	else if (n == 2)	return 'C';	else if (n == 3)	return 'D';	else if (n == 4)	return 'E';	else if (n == 5)	return 'F';	else if (n == 6)	return 'G';	else if (n == 7)	return 'H';	else if (n == 8)	return 'I';	else if (n == 9)	return 'J';	else if (n == 10)	return 'K';	else if (n == 11)	return 'L';	else if (n == 12)	return 'M';	else if (n == 13)	return 'N';	else if (n == 14)	return 'O';	else if (n == 15)	return 'P';	else if (n == 16)	return 'Q';	else if (n == 17)	return 'R';	else if (n == 18)	return 'S';	else if (n == 19)	return 'T';	else if (n == 20)	return 'U';	else if (n == 21)	return 'V';	else if (n == 22)	return 'W';	else if (n == 23)	return 'X';	else if (n == 24)	return 'Y';	else				return 'Z';}	// NumToCharfunction HandleWheel(M,i,pos){	return (CharToNum(M.charAt((i-pos+26)%26))+pos)%26;}	// CipherCharfunction CheckAlphabet(c){	var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';		return (alphabet.indexOf(c,0) >= 0);}	// CheckAlphabetfunction HandleChangePosition(pos,changeWheels){	pos[0] = (pos[0] + 1)%26;	if (changeWheels != kNone)		ChangeWheel(1,pos[0],changeWheels);			if (pos[0] == CharToNum(K[0]))	{		pos[1] = (pos[1] + 1)%26;		if (pos[1] == CharToNum(K[1]))		{			pos[1] = (pos[1]+1)%26;			pos[2] = (pos[2] + 1)%26;			if (changeWheels != kNone)				ChangeWheel(3,pos[2],changeWheels);		}	// if		if (changeWheels != kNone)			ChangeWheel(2,pos[1],changeWheels);	}	// if	}	// HandleChangePositionfunction CipherText(plaintext,pos,changeWheels){	var x;	var ciphertext = '';	var i;		// erstes Rad dreht sofort	HandleChangePosition(pos,changeWheels);			for(i=0;i<plaintext.length;i++)	{				x = HandleWheel(A[0],CharToNum(plaintext.charAt(i)),pos[0]);		if (changeWheels == kFunction)		{			setTimeout('document.rad1.src = \'images/radl.gif\'',(theTimeout++)*theVelocity);			setTimeout('document.rad1.src = \'images/rad.gif\'',theTimeout*theVelocity);			SetChar(1,1,NumToChar(x));		}	// if		x = HandleWheel(A[1],x,pos[1]);		if (changeWheels == kFunction)		{			setTimeout('document.rad2.src = \'images/radl.gif\'',(theTimeout++)*theVelocity);			setTimeout('document.rad2.src = \'images/rad.gif\'',theTimeout*theVelocity);			SetChar(2,1,NumToChar(x));		}	// if		x = HandleWheel(A[2],x,pos[2]);		if (changeWheels == kFunction)		{			setTimeout('document.rad3.src = \'images/radl.gif\'',(theTimeout++)*theVelocity);			setTimeout('document.rad3.src = \'images/rad.gif\'',theTimeout*theVelocity);			SetChar(3,1,NumToChar(x));		}	// if				x = U.charAt(x);		if (changeWheels == kFunction)		{			setTimeout('document.walze.src = \'images/walze.gif\'',(theTimeout++)*theVelocity);			setTimeout('document.walze.src = \'images/rad.gif\'',theTimeout*theVelocity);			SetChar(3,2,x);		}	// if				x = HandleWheel(B[2],CharToNum(x),pos[2]);		if (changeWheels == kFunction)		{			setTimeout('document.rad3.src = \'images/radr.gif\'',(theTimeout++)*theVelocity);			setTimeout('document.rad3.src = \'images/rad.gif\'',theTimeout*theVelocity);			SetChar(2,2,NumToChar(x));		}	// if				x = HandleWheel(B[1],x,pos[1]);		if (changeWheels == kFunction)		{			setTimeout('document.rad2.src = \'images/radr.gif\'',(theTimeout++)*theVelocity);			setTimeout('document.rad2.src = \'images/rad.gif\'',theTimeout*theVelocity);			SetChar(1,2,NumToChar(x));		}	// if				x = HandleWheel(B[0],x,pos[0]); 		if (changeWheels == kFunction)		{			setTimeout('document.rad1.src = \'images/radr.gif\'',(theTimeout++)*theVelocity);			setTimeout('document.rad1.src = \'images/rad.gif\'',theTimeout*theVelocity);		}	// if				ciphertext = ciphertext+NumToChar(x);				if (changeWheels == kNone)		{			pos[0] = (pos[0] + 1)%26;			HandleChangePosition(pos,changeWheels);		}	// if					}	// for	return ciphertext;}	// CipherTextfunction Cipher(){	var pos = new Array(3);	var plaintext = document.eingabe.plaintext.value;	var ciphertext = '';	var header = '';	var i;			if ((plaintext.length == 0)&&(!document.eingabe.useheader.checked))		return;			document.eingabe.ciphertext.value = '';		plaintext = plaintext.toUpperCase();	for (i=0;i<plaintext.length;i++)	{		if (!CheckAlphabet(plaintext.charAt(i)))		{			alert('Bitte geben Sie im Klartext nur die Buchstaben A-Z ein!');			document.eingabe.plaintext.select();			return;		}	// if	}	// for		for (i=0;i<pos.length;i++)	{		pos[i] = document.eingabe.elements['pos'+i].selectedIndex;						header = header + NumToChar(document.eingabe.elements['varpos'+i].selectedIndex);	}	// for	if (document.eingabe.useheader.checked)	{			header = header + header;				header = header.toUpperCase();				ciphertext = CipherText(header,pos,kNone);			for (i=0;i<pos.length;i++)			pos[i] = document.eingabe.elements['varpos'+i].selectedIndex;		}	// if		document.eingabe.ciphertext.value = ciphertext + CipherText(plaintext,pos,kNone);	}	// Cipherfunction Decipher(){	var pos = new Array(3);	var ciphertext = document.eingabe.ciphertext.value;	var plaintext = '';	var header = '';	var i;	document.eingabe.plaintext.value = '';		ciphertext = ciphertext.toUpperCase();	for (i=0;i<ciphertext.length;i++)	{		if (!CheckAlphabet(ciphertext.charAt(i)))		{			alert('Bitte geben Sie im verschluesselten Text nur die Buchstaben A-Z ein!');			document.eingabe.ciphertext.select();			return;		}	// if	}	// for		for (i=0;i<pos.length;i++)		pos[i] = document.eingabe.elements['pos'+i].selectedIndex;					if (document.eingabe.useheader.checked)	{			if (ciphertext.length < 6)		{			alert('Bei Verschluesselung der variablen Position muss der Text mindestens 6 Zeichen lang sein');			document.eingabe.ciphertext.select();			return;					}	// if				header = CipherText(ciphertext.substring(0,6),pos,kNone);				for (i=0;i<pos.length;i++)		{			if (header.charAt(i) != header.charAt(i+pos.length))			{				alert('Die verschuesselte Nachricht ist beschaedigt!');				return;			}	// if		}	// for					for (i=0;i<pos.length;i++)		{			pos[i] = header.charAt(i);			pos[i] = CharToNum(pos[i].charAt(0));		}	// for				ciphertext = ciphertext.substring(6,ciphertext.length);	}	// if		document.eingabe.plaintext.value = plaintext + CipherText(ciphertext,pos,kNone);	}	// Decipherfunction HandleInput(theChar){	var cipherChar = CipherText(theChar,origpos,kOriginal);		cipherChar = cipherChar.toLowerCase();	document.images[""+cipherChar].src = "images/"+cipherChar+"l.gif";	setTimeout('ResetInput(\''+cipherChar+'\')',2500);		return false;	}	// HandleInputfunction ResetInput(theChar){	document.images[theChar].src = "images/"+theChar+".gif";	}	// ResetInputfunction ChangeWheel(n,pos,changeWheels){	var theChar = NumToChar(pos);	theChar = theChar.toLowerCase();	if (changeWheels == kOriginal)		document.images["r"+n].src = 'images/'+theChar+'r.gif';	else		document.eingabe.elements["inputr"+n].selectedIndex = pos;}	// ChangeWheelfunction ClickTop(n){	origpos[n-1] = (origpos[n-1]+1)%26;	ChangeWheel(n,origpos[n-1],kOriginal);		return false;}	// ClickTopfunction ClickBottom(n){	origpos[n-1] = (origpos[n-1]-1+26)%26;	ChangeWheel(n,origpos[n-1],kOriginal);		return false;}	// ClickBottomfunction ResetWheel(r){	document.images['rad'+r].src = 'images/rad.gif';}	// ResetWheelfunction SetOneChar(n,dir,theChar){	theChar = theChar.toLowerCase();	document.images[('r'+n)+dir].src = 'images/'+theChar+'r.gif';}	// SetOneCharfunction SetChar(n,dir,theChar){	setTimeout('SetOneChar('+n+','+dir+',\''+theChar+'\');',(theTimeout++)*theVelocity);	if (!document.eingabe.dontdelete.checked)		setTimeout('ResetChar('+n+','+dir+');',theTimeout*theVelocity);}	// SetCharfunction ResetChar(n,dir){	document.images[('r'+n)+dir].src = 'images/leer.gif';}	// ResetCharfunction HandleStart(){	theTimeout = 0;	theVelocity = 500+document.eingabe.velocity.selectedIndex*500;	document.r11.src = 'images/leer.gif';	document.r21.src = 'images/leer.gif';	document.r31.src = 'images/leer.gif';	document.r12.src = 'images/leer.gif';	document.r22.src = 'images/leer.gif';	document.r32.src = 'images/leer.gif';	document.output.src = 'images/leer.gif';		var theChar = NumToChar(document.eingabe.input.selectedIndex);	var wheelPos = new Array(0,0,0);	for (var i=0;i<3;i++)		wheelPos[i] = document.eingabe.elements["inputr"+(i+1)].selectedIndex;	var cipherChar = CipherText(theChar,wheelPos,kFunction);	cipherChar = cipherChar.toLowerCase();	setTimeout('document.output.src = \'images/\'+\''+cipherChar+'\'+\'l.gif\';',theTimeout*theVelocity);	// setTimeout('ResetInput(\''+cipherChar+'\')',2500);	}	// HandleStart