_hasSteckerBoard) { // Can implement this later! $this->_steckerBoard=new Enigma_SteckerBoard; } for($i=0; $i<$this->_numSlots; $i++) { $this->_slots[$i]=new Enigma_RotorSlot; if($i>0) { //higher slots watch lower ones $this->_slots[$i-1]->registerTurnoverObserver($this->_slots[$i]); } } } public function setRotors($rotors) { if(!(is_array($rotors) && ($this->_numSlots==count($rotors)))) { throw new Exception("Rotors must be $this->_numSlots-element array"); } $i=0; foreach($rotors as $rotor) { if(!$rotor instanceof Enigma_Rotor_Abstract) { throw new Exception('Slots can only be loaded with Enigma_Rotor_* class'); } $this->_slots[$i]->loadRotor($rotor); $i++; } } public function setRotorStartPositions($positions) { if(!(is_array($positions) && ($this->_numSlots==count($positions)))) { throw new Exception("Rotor positions must be $this->_numSlots-element array"); } $i=0; foreach($positions as $position) { $this->_slots[$i]->setRotorOffset($position); $i++; } } public function setReflector(Enigma_Reflector_Abstract $reflector) { $this->_reflector=$reflector; } public function getOutputCharacterForInputCharacter ($inputCharacter) { if(!$this->_isFullyBuilt()) { throw new Exception('Device not fully built'); } //We'll trigger the mechanical phase here as we can't send a signal without doing so //(ok, strictly there's a hardware hack) $this->_slots[0]->incrementRotorOffset(); $char=$inputCharacter; //line up our coding stages and feed the signal through them: if($this->_hasSteckerBoard) { $char=$this->_steckerBoard->getOutputCharacterForInputCharacter($char); } //rotors inbound foreach($this->_slots as $slot) { $char=$slot->getOutputCharacterForInputCharacter($char); } // through the reflector: $char=$this->_reflector->getOutputCharacterForInputCharacter($char); //rotors outbound (current flows other way) for($i=$this->_numSlots-1;$i>=0;$i--) { $slot=$this->_slots[$i]; $char=$slot->getOutputCharacterForInputCharacterReverse($char); } //steckers are symmetrical if($this->_hasSteckerBoard) { $char=$this->_steckerBoard->getOutputCharacterForInputCharacter($char); } return($char); } /** * * @return Enigma_SteckerBoard */ public function getSteckerBoard() { return($this->_steckerBoard); } protected function _isFullyBuilt() { //for now, lie. return true; } }