function doCipher()
{
	// Type of Enigma to Use: M3/M4
	var enigma_type = document.getElementById('enigma_type').value;

	// Get current status of Wheel Order
	var wheel_r = parseFloat(document.getElementById('rightw_no').value);
	var wheel_m = parseFloat(document.getElementById('middlew_no').value);
	var wheel_l = parseFloat(document.getElementById('leftw_no').value);
	var wheel_g = document.getElementById('greek_no').value; // M4 Greek Wheek

	// Get current status of Wheel Ring Setting
	var ring_r = ENIGMA.plaintext.indexOf(document.getElementById('rightw_ring').value.toUpperCase());
	var ring_m = ENIGMA.plaintext.indexOf(document.getElementById('middlew_ring').value.toUpperCase());
	var ring_l = ENIGMA.plaintext.indexOf(document.getElementById('leftw_ring').value.toUpperCase());
	var ring_g = ENIGMA.plaintext.indexOf(document.getElementById('greek_ring').value.toUpperCase());

	// If using M4 Enigma
	if (enigma_type == "m4") {
		// Which reflector are we using? B thin (default) or C tbin
		var useReflector = document.getElementById('use_reflector_thin').value;
	} else {
		// Which reflector are we using? B (default) or C
		var useReflector = document.getElementById('use_reflector').value;
	}

	// Grouping of letters in blocks
	var grouping = document.getElementById('letter_grouping').value;

	// Are the selected rotors all different?
	if (wheel_r == wheel_m || wheel_r == wheel_l || wheel_m == wheel_l ) {
		alert("Wheel Numbers must be unique. Eg, I II III not II II II");
		document.getElementById('rightw_no').focus();
		return false;
	}

	// Get input letter
	var letterinput = document.getElementById('textin').value.toUpperCase();

	if (letterinput.search(/[A-Z]/gi)) {
		// If input is not a letter [A-Z], then return false and do nothing
		// except clear and focus the letter input field
		document.getElementById('textin').value = "";
		document.getElementById('textin').focus();
		return false;
	}

	// Rotate Wheels
	var wheel_position = rotateCogs(wheel_r,wheel_m,wheel_l);

	// Wheel Starting Position
	var start_r = wheel_position[0];
	var start_m = wheel_position[1];
	var start_l = wheel_position[2];
	var start_g = ENIGMA.plaintext.indexOf(document.getElementById('greek_set').value.toUpperCase()); // M4 does not rotate

	// Input
	var input = ENIGMA.plaintext.indexOf(letterinput);

	run_debug(0, input);

	// First Pass - Plugboard
	var number = swapPlugs(input);

	run_debug(0, number);

	// Passes through ETW which acts as a static converter from plugboard wires to wheels
	// So:  Plugboard --> ETW --> Right Wheel
	// A -->  A  --> A

	// First Pass - R Wheel
	number = mapLetter(number,ring_r,start_r,wheel_r, 1);

	run_debug(0, number);

	// First Pass - M Wheel
	number = mapLetter(number,ring_m,start_m,wheel_m, 1);

	run_debug(0, number);

	// First Pass - L Wheel
	number = mapLetter(number,ring_l,start_l,wheel_l, 1);

	run_debug(0, number);

	// If using M4 Enigma
	if (enigma_type == "m4") {
		// First Pass - Greek Wheel
		number = mapLetter(number,ring_g,start_g,wheel_g, 1);
	}

	// Reflector
	var let = ENIGMA.arrReflector[useReflector].charAt(number);
	number = ENIGMA.plaintext.indexOf(let);

	run_debug(0, number);

	// If using M4 Enigma
	if (enigma_type == "m4") {
		// Second Pass - Greek Wheel
		number = mapLetter(number,ring_g,start_g,wheel_g, 2);
	}

	// Second Pass - L Wheel
	number = mapLetter(number,ring_l,start_l,wheel_l, 2);

	run_debug(0, number);

	// Second Pass - M Wheel
	number = mapLetter(number,ring_m,start_m,wheel_m, 2);

	run_debug(0, number);

	// Second Pass - R Wheel
	number = mapLetter(number,ring_r,start_r,wheel_r, 2);

	run_debug(0, number);

	// Passes through ETW again

	// Second Pass - Plugboard
	number = swapPlugs(number);

	run_debug(1, number);

	// Convert value to corresponding letter
	var output = ENIGMA.plaintext.charAt(number);

	// Clean number
	number = "";

	// Build Message Strings for Input and Output

	// Get current string values
	var msg_in = document.getElementById('msg_in').value;
	var msg_out = document.getElementById('msg_out').value;

	if (ENIGMA.counter == grouping) {
		// Space out message in/out as letter blocks of X length (grouping)
		msg_in = msg_in + " ";
		msg_out = msg_out + " ";
		ENIGMA.counter = 0;
	}

	// Increment counter
	ENIGMA.counter ++;

	// Spit out new string values
	document.getElementById('msg_in').value = msg_in + letterinput;
	document.getElementById('msg_out').value = msg_out + output;

	// Show output letter in lightbox.
	lightUp(output);

	// Clear and focus letter input field
	document.getElementById('textin').value = "";
	document.getElementById('textin').focus();

	return true;
}
/* FUNCTION --------------------------------------------------------
	Run the whole Enigma machine process.
	The functions above are called from this routine.
   ----------------------------------------------------------------- */
FUNCTION
Run the whole Enigma machine process.
The functions above are called from this routine.
FUNCTION Run the whole Enigma machine process . The functions above are called from this routine .
function doCipher()
{
	var enigma_type = document.getElementById('enigma_type').value;
	var wheel_r = parseFloat(document.getElementById('rightw_no').value);
	var wheel_m = parseFloat(document.getElementById('middlew_no').value);
	var wheel_l = parseFloat(document.getElementById('leftw_no').value);
	var wheel_g = document.getElementById('greek_no').value; 
	var ring_r = ENIGMA.plaintext.indexOf(document.getElementById('rightw_ring').value.toUpperCase());
	var ring_m = ENIGMA.plaintext.indexOf(document.getElementById('middlew_ring').value.toUpperCase());
	var ring_l = ENIGMA.plaintext.indexOf(document.getElementById('leftw_ring').value.toUpperCase());
	var ring_g = ENIGMA.plaintext.indexOf(document.getElementById('greek_ring').value.toUpperCase());
	if (enigma_type == "m4") {
		var useReflector = document.getElementById('use_reflector_thin').value;
	} else {
		var useReflector = document.getElementById('use_reflector').value;
	}
	var grouping = document.getElementById('letter_grouping').value;
	if (wheel_r == wheel_m || wheel_r == wheel_l || wheel_m == wheel_l ) {
		alert("Wheel Numbers must be unique. Eg, I II III not II II II");
		document.getElementById('rightw_no').focus();
		return false;
	}
	var letterinput = document.getElementById('textin').value.toUpperCase();
	if (letterinput.search(/[A-Z]/gi)) {
		document.getElementById('textin').value = "";
		document.getElementById('textin').focus();
		return false;
	}
	var wheel_position = rotateCogs(wheel_r,wheel_m,wheel_l);
	var start_r = wheel_position[0];
	var start_m = wheel_position[1];
	var start_l = wheel_position[2];
	var start_g = ENIGMA.plaintext.indexOf(document.getElementById('greek_set').value.toUpperCase()); 
	var input = ENIGMA.plaintext.indexOf(letterinput);
	run_debug(0, input);
	var number = swapPlugs(input);
	run_debug(0, number);
	number = mapLetter(number,ring_r,start_r,wheel_r, 1);
	run_debug(0, number);
	number = mapLetter(number,ring_m,start_m,wheel_m, 1);
	run_debug(0, number);
	number = mapLetter(number,ring_l,start_l,wheel_l, 1);
	run_debug(0, number);
	if (enigma_type == "m4") {
		number = mapLetter(number,ring_g,start_g,wheel_g, 1);
	}
	var let = ENIGMA.arrReflector[useReflector].charAt(number);
	number = ENIGMA.plaintext.indexOf(let);
	run_debug(0, number);
	if (enigma_type == "m4") {
		number = mapLetter(number,ring_g,start_g,wheel_g, 2);
	}
	number = mapLetter(number,ring_l,start_l,wheel_l, 2);
	run_debug(0, number);
	number = mapLetter(number,ring_m,start_m,wheel_m, 2);
	run_debug(0, number);
	number = mapLetter(number,ring_r,start_r,wheel_r, 2);
	run_debug(0, number);
	number = swapPlugs(number);
	run_debug(1, number);
	var output = ENIGMA.plaintext.charAt(number);
	number = "";
	var msg_in = document.getElementById('msg_in').value;
	var msg_out = document.getElementById('msg_out').value;
	if (ENIGMA.counter == grouping) {
		msg_in = msg_in + " ";
		msg_out = msg_out + " ";
		ENIGMA.counter = 0;
	}
	ENIGMA.counter ++;
	document.getElementById('msg_in').value = msg_in + letterinput;
	document.getElementById('msg_out').value = msg_out + output;
	lightUp(output);
	document.getElementById('textin').value = "";
	document.getElementById('textin').focus();
	return true;
}
function doCipher ( ) { var enigma_type = document . getElementById ( 'enigma_type' ) . value ; var wheel_r = parseFloat ( document . getElementById ( 'rightw_no' ) . value ) ; var wheel_m = parseFloat ( document . getElementById ( 'middlew_no' ) . value ) ; var wheel_l = parseFloat ( document . getElementById ( 'leftw_no' ) . value ) ; var wheel_g = document . getElementById ( 'greek_no' ) . value ; var ring_r = ENIGMA . plaintext . indexOf ( document . getElementById ( 'rightw_ring' ) . value . toUpperCase ( ) ) ; var ring_m = ENIGMA . plaintext . indexOf ( document . getElementById ( 'middlew_ring' ) . value . toUpperCase ( ) ) ; var ring_l = ENIGMA . plaintext . indexOf ( document . getElementById ( 'leftw_ring' ) . value . toUpperCase ( ) ) ; var ring_g = ENIGMA . plaintext . indexOf ( document . getElementById ( 'greek_ring' ) . value . toUpperCase ( ) ) ; if ( enigma_type == "m4" ) { var useReflector = document . getElementById ( 'use_reflector_thin' ) . value ; } else { var useReflector = document . getElementById ( 'use_reflector' ) . value ; } var grouping = document . getElementById ( 'letter_grouping' ) . value ; if ( wheel_r == wheel_m || wheel_r == wheel_l || wheel_m == wheel_l ) { alert ( "Wheel Numbers must be unique. Eg, I II III not II II II" ) ; document . getElementById ( 'rightw_no' ) . focus ( ) ; return false ; } var letterinput = document . getElementById ( 'textin' ) . value . toUpperCase ( ) ; if ( letterinput . search ( / [A-Z] / gi ) ) { document . getElementById ( 'textin' ) . value = "" ; document . getElementById ( 'textin' ) . focus ( ) ; return false ; } var wheel_position = rotateCogs ( wheel_r , wheel_m , wheel_l ) ; var start_r = wheel_position [ 0 ] ; var start_m = wheel_position [ 1 ] ; var start_l = wheel_position [ 2 ] ; var start_g = ENIGMA . plaintext . indexOf ( document . getElementById ( 'greek_set' ) . value . toUpperCase ( ) ) ; var input = ENIGMA . plaintext . indexOf ( letterinput ) ; run_debug ( 0 , input ) ; var number = swapPlugs ( input ) ; run_debug ( 0 , number ) ; number = mapLetter ( number , ring_r , start_r , wheel_r , 1 ) ; run_debug ( 0 , number ) ; number = mapLetter ( number , ring_m , start_m , wheel_m , 1 ) ; run_debug ( 0 , number ) ; number = mapLetter ( number , ring_l , start_l , wheel_l , 1 ) ; run_debug ( 0 , number ) ; if ( enigma_type == "m4" ) { number = mapLetter ( number , ring_g , start_g , wheel_g , 1 ) ; } var let = ENIGMA . arrReflector [ useReflector ] . charAt ( number ) ; number = ENIGMA . plaintext . indexOf ( let ) ; run_debug ( 0 , number ) ; if ( enigma_type == "m4" ) { number = mapLetter ( number , ring_g , start_g , wheel_g , 2 ) ; } number = mapLetter ( number , ring_l , start_l , wheel_l , 2 ) ; run_debug ( 0 , number ) ; number = mapLetter ( number , ring_m , start_m , wheel_m , 2 ) ; run_debug ( 0 , number ) ; number = mapLetter ( number , ring_r , start_r , wheel_r , 2 ) ; run_debug ( 0 , number ) ; number = swapPlugs ( number ) ; run_debug ( 1 , number ) ; var output = ENIGMA . plaintext . charAt ( number ) ; number = "" ; var msg_in = document . getElementById ( 'msg_in' ) . value ; var msg_out = document . getElementById ( 'msg_out' ) . value ; if ( ENIGMA . counter == grouping ) { msg_in = msg_in + " " ; msg_out = msg_out + " " ; ENIGMA . counter = 0 ; } ENIGMA . counter ++ ; document . getElementById ( 'msg_in' ) . value = msg_in + letterinput ; document . getElementById ( 'msg_out' ) . value = msg_out + output ; lightUp ( output ) ; document . getElementById ( 'textin' ) . value = "" ; document . getElementById ( 'textin' ) . focus ( ) ; return true ; }
FUNCTION
Run the whole Enigma machine process.
FUNCTION Run the whole Enigma machine process .
// Type of Enigma to Use: M3/M4 // Get current status of Wheel Order // M4 Greek Wheek // Get current status of Wheel Ring Setting // If using M4 Enigma // Which reflector are we using? B thin (default) or C tbin // Which reflector are we using? B (default) or C // Grouping of letters in blocks // Are the selected rotors all different? // Get input letter // If input is not a letter [A-Z], then return false and do nothing // except clear and focus the letter input field // Rotate Wheels // Wheel Starting Position // M4 does not rotate // Input // First Pass - Plugboard // Passes through ETW which acts as a static converter from plugboard wires to wheels // So:  Plugboard --> ETW --> Right Wheel // A -->  A  --> A // First Pass - R Wheel // First Pass - M Wheel // First Pass - L Wheel // If using M4 Enigma // First Pass - Greek Wheel // Reflector // If using M4 Enigma // Second Pass - Greek Wheel // Second Pass - L Wheel // Second Pass - M Wheel // Second Pass - R Wheel // Passes through ETW again // Second Pass - Plugboard // Convert value to corresponding letter // Clean number // Build Message Strings for Input and Output // Get current string values // Space out message in/out as letter blocks of X length (grouping) // Increment counter // Spit out new string values // Show output letter in lightbox. // Clear and focus letter input field