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} 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);
}
}

View File

@ -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;