Location: PHPKode > scripts > Enigma > enigma/core/wiring.class.php
<?
/**
 * This class represents the wiring of rotors, reflectors and the plugboard.
 *
 * Each wiring provides a monoalphabetical substitution e.g.:
 * <pre>
 * ABCDEFGHIJKLMNOPQRSTUVWXYZ
 * ||||||||||||||||||||||||||
 * EKMFLGDQVZNTOWYHXUSPAIBRCJ
 * </pre>
 * @author David Kargl <hide@address.com>
 * @version 1.0
 * @package Enigma
 * @subpackage Core
 */
class EnigmaWiring {

	/**
    * The connections of the pins.
    *
    * [0]=4 means pin 0 on side A leads to pin 4 on side B, [1]=10 means pin 1 on side A leads to pin 10 on side B, ...<br>
    * Size is ENIGMA_ALPHABET_SIZE.
    * @var array integer
    */
	private $wiring = null;

    /**
     * Constructor connects the pins according to the list in $wiring.
     *
     * example string EKMFLGDQVZNTOWYHXUSPAIBRCJ leads to [0]=4, [1]=10, [2]=12, ...
     * @param string setup for the internal wiring
     * @uses enigma_l2p
     */
	public function __construct($wiring) {
		$this->wiring = array_map(enigma_l2p, str_split($wiring));
	}

    /**
     * Manually connect 2 pins.
     * @param integer pin 1 to connect
     * @param integer pin 2 to connect
     * @return void
     */
	public function connect($pin1, $pin2) {
		$this->wiring[$pin1] = $pin2;
	}

    /**
     * Get the connected pin.
     * @param integer start of the connection
     * @return integer the connected pin
     */
	public function connectsTo($pin) {
		return $this->wiring[$pin];
	}

    /**
     * Pass the given letter form side A to side B by following the connection of the pins.
     * @param integer pin that got activated
     * @return integer pin that gets activated
     */
	public function processLetter1stPass($pin) {
		return $this->wiring[$pin];
	}

    /**
     * Pass the given letter form side B to side A by following the connection of the pins.
     * @param integer pin that got activated
     * @return integer pin that gets activated
     */
	public function processLetter2ndPass($pin) {
		return array_search($pin, $this->wiring);
	}

}
?>
Return current item: Enigma