/** * Emulation of the Typex machine. * * @author s2224834 * @author The National Museum of Computing - Bombe Rebuild Project * @copyright Crown Copyright 2019 * @license Apache-2.0 */ import OperationError from "../errors/OperationError"; import * as Enigma from "../lib/Enigma"; import Utils from "../Utils"; /** * A set of example Typex rotors. No Typex rotor wirings are publicly available, so these are * randomised. */ export const ROTORS = [ {name: "Example 1", value: "MCYLPQUVRXGSAOWNBJEZDTFKHI { return reversed[Enigma.a2i(x)]; }); try { super(wiring, "", "A", "A"); } catch (err) { throw new OperationError(err.message.replace("Rotor", "Plugboard")); } } /** * Transform a character through this rotor forwards. * * @param {number} c - The character. * @returns {number} */ transform(c) { return Utils.mod(this.map[Utils.mod(c + this.pos, 26)] - this.pos, 26); } /** * Transform a character through this rotor backwards. * * @param {number} c - The character. * @returns {number} */ revTransform(c) { return Utils.mod(this.revMap[Utils.mod(c + this.pos, 26)] - this.pos, 26); } }