Typex: add ring setting

This commit is contained in:
s2224834 2019-02-07 18:10:16 +00:00
parent 1b1a3c261d
commit 220053c044
2 changed files with 35 additions and 11 deletions

View file

@ -148,14 +148,13 @@ export class Rotor extends Enigma.Rotor {
* @param {string} wiring - A 26 character string of the wiring order. * @param {string} wiring - A 26 character string of the wiring order.
* @param {string} steps - A 0..26 character string of stepping points. * @param {string} steps - A 0..26 character string of stepping points.
* @param {bool} reversed - Whether to reverse the rotor. * @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. * @param {char} initialPosition - The initial position of the rotor.
*/ */
constructor(wiring, steps, reversed, initialPos) { constructor(wiring, steps, reversed, ringSetting, initialPos) {
let initialPosMod = initialPos;
let wiringMod = wiring; let wiringMod = wiring;
if (reversed) { if (reversed) {
initialPosMod = Enigma.i2a(Utils.mod(26 - Enigma.a2i(initialPos), 26)); const outMap = new Array(26);
const outMap = new Array(26).fill();
for (let i=0; i<26; i++) { for (let i=0; i<26; i++) {
// wiring[i] is the original output // wiring[i] is the original output
// Enigma.LETTERS[i] is the original input // Enigma.LETTERS[i] is the original input
@ -165,7 +164,7 @@ export class Rotor extends Enigma.Rotor {
} }
wiringMod = outMap.join(""); wiringMod = outMap.join("");
} }
super(wiringMod, steps, "A", initialPosMod); super(wiringMod, steps, ringSetting, initialPos);
} }
} }

View file

@ -39,6 +39,11 @@ class Typex extends Operation {
type: "boolean", type: "boolean",
value: false value: false
}, },
{
name: "1st rotor ring setting",
type: "option",
value: LETTERS
},
{ {
name: "1st rotor initial value", name: "1st rotor initial value",
type: "option", type: "option",
@ -55,6 +60,11 @@ class Typex extends Operation {
type: "boolean", type: "boolean",
value: false value: false
}, },
{
name: "2nd rotor ring setting",
type: "option",
value: LETTERS
},
{ {
name: "2nd rotor initial value", name: "2nd rotor initial value",
type: "option", type: "option",
@ -71,6 +81,11 @@ class Typex extends Operation {
type: "boolean", type: "boolean",
value: false value: false
}, },
{
name: "3rd rotor ring setting",
type: "option",
value: LETTERS
},
{ {
name: "3rd rotor initial value", name: "3rd rotor initial value",
type: "option", type: "option",
@ -87,6 +102,11 @@ class Typex extends Operation {
type: "boolean", type: "boolean",
value: false value: false
}, },
{
name: "4th rotor ring setting",
type: "option",
value: LETTERS
},
{ {
name: "4th rotor initial value", name: "4th rotor initial value",
type: "option", type: "option",
@ -103,6 +123,11 @@ class Typex extends Operation {
type: "boolean", type: "boolean",
value: false value: false
}, },
{
name: "5th rotor ring setting",
type: "option",
value: LETTERS
},
{ {
name: "5th rotor initial value", name: "5th rotor initial value",
type: "option", type: "option",
@ -156,14 +181,14 @@ class Typex extends Operation {
* @returns {string} * @returns {string}
*/ */
run(input, args) { run(input, args) {
const reflectorstr = args[15]; const reflectorstr = args[20];
const plugboardstr = args[16]; const plugboardstr = args[21];
const typexKeyboard = args[17]; const typexKeyboard = args[22];
const removeOther = args[18]; const removeOther = args[23];
const rotors = []; const rotors = [];
for (let i=0; i<5; i++) { for (let i=0; i<5; i++) {
const [rotorwiring, rotorsteps] = this.parseRotorStr(args[i*3]); const [rotorwiring, rotorsteps] = this.parseRotorStr(args[i*4]);
rotors.push(new Rotor(rotorwiring, rotorsteps, args[i*3 + 1], args[i*3+2])); rotors.push(new Rotor(rotorwiring, rotorsteps, args[i*4 + 1], args[i*4+2], args[i*4+3]));
} }
const reflector = new Reflector(reflectorstr); const reflector = new Reflector(reflectorstr);
let plugboardstrMod = plugboardstr; let plugboardstrMod = plugboardstr;