From 220053c0444c6dfbcc785e61fe6188a5f937566a Mon Sep 17 00:00:00 2001 From: s2224834 <46319860+s2224834@users.noreply.github.com> Date: Thu, 7 Feb 2019 18:10:16 +0000 Subject: [PATCH] Typex: add ring setting --- src/core/lib/Typex.mjs | 9 ++++----- src/core/operations/Typex.mjs | 37 +++++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/core/lib/Typex.mjs b/src/core/lib/Typex.mjs index df6e646b..b4cf297c 100644 --- a/src/core/lib/Typex.mjs +++ b/src/core/lib/Typex.mjs @@ -148,14 +148,13 @@ export class Rotor extends Enigma.Rotor { * @param {string} wiring - A 26 character string of the wiring order. * @param {string} steps - A 0..26 character string of stepping points. * @param {bool} reversed - Whether to reverse the rotor. + * @param {char} ringSetting - Ring setting of the rotor. * @param {char} initialPosition - The initial position of the rotor. */ - constructor(wiring, steps, reversed, initialPos) { - let initialPosMod = initialPos; + constructor(wiring, steps, reversed, ringSetting, initialPos) { let wiringMod = wiring; if (reversed) { - initialPosMod = Enigma.i2a(Utils.mod(26 - Enigma.a2i(initialPos), 26)); - const outMap = new Array(26).fill(); + const outMap = new Array(26); for (let i=0; i<26; i++) { // wiring[i] is the original output // Enigma.LETTERS[i] is the original input @@ -165,7 +164,7 @@ export class Rotor extends Enigma.Rotor { } wiringMod = outMap.join(""); } - super(wiringMod, steps, "A", initialPosMod); + super(wiringMod, steps, ringSetting, initialPos); } } diff --git a/src/core/operations/Typex.mjs b/src/core/operations/Typex.mjs index 79468645..504cb891 100644 --- a/src/core/operations/Typex.mjs +++ b/src/core/operations/Typex.mjs @@ -39,6 +39,11 @@ class Typex extends Operation { type: "boolean", value: false }, + { + name: "1st rotor ring setting", + type: "option", + value: LETTERS + }, { name: "1st rotor initial value", type: "option", @@ -55,6 +60,11 @@ class Typex extends Operation { type: "boolean", value: false }, + { + name: "2nd rotor ring setting", + type: "option", + value: LETTERS + }, { name: "2nd rotor initial value", type: "option", @@ -71,6 +81,11 @@ class Typex extends Operation { type: "boolean", value: false }, + { + name: "3rd rotor ring setting", + type: "option", + value: LETTERS + }, { name: "3rd rotor initial value", type: "option", @@ -87,6 +102,11 @@ class Typex extends Operation { type: "boolean", value: false }, + { + name: "4th rotor ring setting", + type: "option", + value: LETTERS + }, { name: "4th rotor initial value", type: "option", @@ -103,6 +123,11 @@ class Typex extends Operation { type: "boolean", value: false }, + { + name: "5th rotor ring setting", + type: "option", + value: LETTERS + }, { name: "5th rotor initial value", type: "option", @@ -156,14 +181,14 @@ class Typex extends Operation { * @returns {string} */ run(input, args) { - const reflectorstr = args[15]; - const plugboardstr = args[16]; - const typexKeyboard = args[17]; - const removeOther = args[18]; + const reflectorstr = args[20]; + const plugboardstr = args[21]; + const typexKeyboard = args[22]; + const removeOther = args[23]; const rotors = []; for (let i=0; i<5; i++) { - const [rotorwiring, rotorsteps] = this.parseRotorStr(args[i*3]); - rotors.push(new Rotor(rotorwiring, rotorsteps, args[i*3 + 1], args[i*3+2])); + const [rotorwiring, rotorsteps] = this.parseRotorStr(args[i*4]); + rotors.push(new Rotor(rotorwiring, rotorsteps, args[i*4 + 1], args[i*4+2], args[i*4+3])); } const reflector = new Reflector(reflectorstr); let plugboardstrMod = plugboardstr;