From dfc8f517f2746fe4469552e6ccd84c90f88e198c Mon Sep 17 00:00:00 2001 From: VirtualColossus Date: Wed, 27 Nov 2019 12:48:09 +0000 Subject: [PATCH 01/10] Added Colossus operation --- src/core/lib/Colossus.mjs | 426 +++++++++++++++++++++++++ src/core/lib/Lorenz.mjs | 155 +++++++++ src/core/operations/Colossus.mjs | 517 +++++++++++++++++++++++++++++++ 3 files changed, 1098 insertions(+) create mode 100644 src/core/lib/Colossus.mjs create mode 100644 src/core/lib/Lorenz.mjs create mode 100644 src/core/operations/Colossus.mjs diff --git a/src/core/lib/Colossus.mjs b/src/core/lib/Colossus.mjs new file mode 100644 index 00000000..d25d3285 --- /dev/null +++ b/src/core/lib/Colossus.mjs @@ -0,0 +1,426 @@ +/** + * Colossus - an emulation of the world's first electronic computer + * + * @author VirtualColossus + * @copyright Crown Copyright 2019 + * @license Apache-2.0 + */ +import OperationError from "../errors/OperationError.mjs"; +import Utils from "../Utils.mjs"; +import {INIT_PATTERNS, ITA2_TABLE, ROTOR_SIZES} from "../lib/Lorenz.mjs"; + +/** + * Colossus simulator class. + */ +export class ColossusComputer { + /** + * Construct a Colossus. + * + * @param {string} ciphertext + * @param {string} pattern - named pattern of Chi, Mu and Psi wheels + * @param {Object} qbusin - which data inputs are being sent to q bus - each can be null, plain or delta + * @param {Object[]} qbusswitches - Q bus calculation switches, multiple rows + * @param {Object} control - control switches which specify stepping modes + * @param {Object} starts - rotor start positions + */ + constructor(ciphertext, pattern, qbusin, qbusswitches, control, starts, settotal, limit) { + + this.ITAlookup = ITA2_TABLE; + this.REVERSE_ITAlookup = {}; + for (const letter in this.ITAlookup) { + const code = this.ITAlookup[letter]; + this.REVERSE_ITAlookup[code] = letter; + } + + this.initThyratrons(pattern); + + this.ciphertext = ciphertext; + this.qbusin = qbusin; + this.qbusswitches = qbusswitches; + this.control = control; + this.starts = starts; + this.settotal = settotal; + this.limitations = limit; + + + this.allCounters = [0, 0, 0, 0, 0]; + + this.Zbits = [0, 0, 0, 0, 0]; // Z input is the cipher tape + this.ZbitsOneBack = [0, 0, 0, 0, 0]; // for delta + this.Qbits = [0, 0, 0, 0, 0]; // input generated for placing onto the Q-bus (the logic processor) + + this.Xbits = [0, 0, 0, 0, 0]; // X is the Chi wheel bits + this.Xptr = [0, 0, 0, 0, 0]; // pointers to the current X bits (Chi wheels) + this.XbitsOneBack = [0, 0, 0, 0, 0]; // the X bits one back (for delta) + + this.Sbits = [0, 0, 0, 0, 0]; // S is the Psi wheel bits + this.Sptr = [0, 0, 0, 0, 0]; // pointers to the current S bits (Psi wheels) + this.SbitsOneBack = [0, 0, 0, 0, 0]; // the S bits one back (for delta) + + this.Mptr = [0, 0]; + + this.rotorPtrs = {}; + + } + + /** + * Begin a run + * @returns {object} - + */ + run() { + + let result = { + printout: "" + }; + + // loop until our start positions are back to the beginning + this.rotorPtrs = {X1: this.starts.X1, X2: this.starts.X2, X3: this.starts.X3, X4: this.starts.X4, X5: this.starts.X5, M61: this.starts.M61, M37: this.starts.M37, S1: this.starts.S1, S2: this.starts.S2, S3: this.starts.S3, S4: this.starts.S4, S5: this.starts.S5}; + //this.rotorPtrs = this.starts; + let runcount = 1; + + const fast = this.control.fast; + const slow = this.control.slow; + + // Print Headers + result.printout += fast + " " + slow + "\n"; + + do { + + this.allCounters = [0, 0, 0, 0, 0]; + this.ZbitsOneBack = [0, 0, 0, 0, 0]; + this.XbitsOneBack = [0, 0, 0, 0, 0]; + + // Run full tape loop and process counters + this.runTape(); + + // Only print result if larger than set total + var fastRef = "00"; + var slowRef = "00"; + if (fast !== "") fastRef = this.leftPad(this.rotorPtrs[fast],2); + if (slow !== "") slowRef = this.leftPad(this.rotorPtrs[slow],2); + result.printout += fastRef + " " + slowRef + " : "; + for (let c=0;c<5;c++) { + if (this.allCounters[c] > this.settotal) { + result.printout += String.fromCharCode(c+97) + this.allCounters[c]+" "; + } + } + result.printout += "\n"; + + // Step fast rotor if required + if (fast != '') { + this.rotorPtrs[fast]++; + if (this.rotorPtrs[fast] > ROTOR_SIZES[fast]) this.rotorPtrs[fast] = 1; + } + + // Step slow rotor if fast rotor has returned to initial start position + if (slow != '' && this.rotorPtrs[fast] === this.starts[fast]) { + this.rotorPtrs[slow]++; + if (this.rotorPtrs[slow] > ROTOR_SIZES[slow]) this.rotorPtrs[slow] = 1; + } + + runcount++; + + } while (JSON.stringify(this.rotorPtrs) !== JSON.stringify(this.starts)); + + result.counters = this.allCounters; + result.runcount = runcount; + + return result; + }; + + /** + * Run tape loop + */ + runTape() { + + let charZin = ""; + + this.Xptr = [this.rotorPtrs.X1, this.rotorPtrs.X2, this.rotorPtrs.X3, this.rotorPtrs.X4, this.rotorPtrs.X5]; + this.Mptr = [this.rotorPtrs.M37, this.rotorPtrs.M61]; + this.Sptr = [this.rotorPtrs.S1, this.rotorPtrs.S2, this.rotorPtrs.S3, this.rotorPtrs.S4, this.rotorPtrs.S5]; + //console.log(this.Xptr); + + // Run full loop of all character on the input tape (Z) + for (let i=0; i ROTOR_SIZES["S"+(r+1)]) this.Sptr[r] = 1; + } + } + + // Move M37 rotor if M61 set + if (this.rings.M[1][this.Mptr[1]-1]==1) this.Mptr[0]++; + if (this.Mptr[0] > ROTOR_SIZES.M37) this.Mptr[0]=1; + + // Always move M61 rotor + this.Mptr[1]++; + if (this.Mptr[1] > ROTOR_SIZES.M61) this.Mptr[1]=1; + + } + + /** + * Get Q bus inputs + */ + getQbusInputs(charZin) { + // Zbits - the bits from the current character from the cipher tape. + this.Zbits = this.ITAlookup[charZin].split(""); + //console.log('Zbits = '+this.Zbits); + if (this.qbusin.Z == 'Z') { + // direct Z + this.Qbits = this.Zbits; + //console.log('direct Z: Qbits = '+this.Qbits); + } else if(this.qbusin.Z == 'ΔZ') { + // delta Z, the Bitwise XOR of this character Zbits + last character Zbits + for(let b=0;b<5;b++) { + this.Qbits[b] = this.Zbits[b] ^ this.ZbitsOneBack[b]; + } + + //console.log('delta Z: Qbits = '+this.Qbits); + } + this.ZbitsOneBack = this.Zbits.slice(); // copy value of object, not reference + + //console.log('Zin::Q bus now '+this.Qbits+'['+this.REVERSE_ITAlookup[this.Qbits.join("")]+']'); + + // Xbits - the current Chi wheel bits + //console.log(this.rings.X); + //console.log('Xptr = '+this.Xptr); + + for (let b=0;b<5;b++) { + this.Xbits[b] = this.rings.X[b+1][this.Xptr[b]-1]; + } + if (this.qbusin.Chi != "") { + //console.log('X Bits '+this.Xbits+'['+this.REVERSE_ITAlookup[this.Xbits.join("")]+']'); + //console.log('X Char = ' + this.REVERSE_ITAlookup[this.Xbits.join("")]); + if (this.qbusin.Chi == "Χ") { + // direct X added to Qbits + for (let b=0;b<5;b++) { + this.Qbits[b] = this.Qbits[b] ^ this.Xbits[b]; + } + //console.log('direct X: Qbits = '+this.Qbits); + } else if(this.qbusin.Chi == "ΔΧ") { + // delta X + for(let b=0;b<5;b++) { + this.Qbits[b] = this.Qbits[b] ^ this.Xbits[b]; + this.Qbits[b] = this.Qbits[b] ^ this.XbitsOneBack[b]; + } + //console.log('delta X: Xbits = '+this.Xbits+' Xbits-1 = '+this.XbitsOneBack); + //console.log('delta X: Qbits = '+this.Qbits); + } + } + this.XbitsOneBack = this.Xbits.slice(); + //console.log('setting XbitsOneBack to '+this.Xbits); + + //console.log('Zin+Xin::Q bus now '+this.Qbits+'['+this.REVERSE_ITAlookup[this.Qbits.join("")]+']'); + + // Sbits - the current Psi wheel bits + //console.log(this.rings.S); + //console.log('Sptr = '+this.Sptr); + for (let b=0;b<5;b++) { + this.Sbits[b] = this.rings.S[b+1][this.Sptr[b]-1]; + } + if (this.qbusin.Psi != "") { + //console.log('S Bits '+this.Sbits+'['+this.REVERSE_ITAlookup[this.Sbits.join("")]+']'); + //console.log('S Char = ' + this.REVERSE_ITAlookup[this.Sbits.join("")]); + if(this.qbusin.Psi == "Ψ") { + // direct S added to Qbits + for (let b=0;b<5;b++) { + this.Qbits[b] = this.Qbits[b] ^ this.Sbits[b]; + } + //console.log('direct S: Qbits = '+this.Qbits); + } else if(this.qbusin.Psi == "ΔΨ") { + // delta S + for (let b=0;b<5;b++) { + this.Qbits[b] = this.Qbits[b] ^ this.Sbits[b]; + this.Qbits[b] = this.Qbits[b] ^ this.SbitsOneBack[b]; + } + //console.log('delta S: Qbits = '+this.Qbits); + } + } + this.SbitsOneBack = this.Sbits.slice(); + + //console.log('Q bus now '+this.Qbits+'['+this.REVERSE_ITAlookup[this.Qbits.join("")]+']'); + } + + /** + * Conditional impulse Q bus section + */ + runQbusProcessingConditional() { + let cnt = [-1, -1, -1, -1, -1]; + const numrows = this.qbusswitches.condition.length; + + for (let r=0;r= 0 && Qswitch[s] != this.Qbits[s]) result = false; + } + // Check for NOT switch + if (row.Negate) result = !result; + + // AND each row to get final result + if (cnt[cPnt] == -1) { + cnt[cPnt] = result; + } else if (result==0) { + cnt[cPnt] = 0; + } + } + } + + // Negate the whole column, this allows A OR B by doing NOT(NOT A AND NOT B) + for (let c=0;c<5;c++) { + if (this.qbusswitches.condNegateAll) cnt[c] = !cnt[c]; + + if (cnt[c]==1) this.allCounters[c]++; + } + + } + + /** + * Addition of impulses Q bus section + */ + runQbusProcessingAddition() { + let row = this.qbusswitches.addition[0]; + const Qswitch = row.Qswitches.slice(); + if (row.C1) { + let addition = 0; + for (let s=0;s<5;s++) { + // XOR addition + if (Qswitch[s]) { + addition = addition ^ this.Qbits[s]; + } + } + const equals = (row.Equals==""?-1:(row.Equals=="."?0:1)); + if (addition == equals) { + this.allCounters[0]++; + } + } + //console.log("counter1="+this.allCounters[0]); + } + + /** + * Initialise thyratron rings + * These hold the pattern of 1s & 0s for each rotor on banks of thyraton GT1C valves which act as a one-bit store. + */ + initThyratrons(pattern) { + this.rings = { + X: { + 1: INIT_PATTERNS[pattern].X[1].slice().reverse(), + 2: INIT_PATTERNS[pattern].X[2].slice().reverse(), + 3: INIT_PATTERNS[pattern].X[3].slice().reverse(), + 4: INIT_PATTERNS[pattern].X[4].slice().reverse(), + 5: INIT_PATTERNS[pattern].X[5].slice().reverse() + }, + M: { + 1: INIT_PATTERNS[pattern].M[1].slice().reverse(), + 2: INIT_PATTERNS[pattern].M[2].slice().reverse(), + }, + S: { + 1: INIT_PATTERNS[pattern].S[1].slice().reverse(), + 2: INIT_PATTERNS[pattern].S[2].slice().reverse(), + 3: INIT_PATTERNS[pattern].S[3].slice().reverse(), + 4: INIT_PATTERNS[pattern].S[4].slice().reverse(), + 5: INIT_PATTERNS[pattern].S[5].slice().reverse() + } + }; + } + + /** + * Left Pad number + */ + leftPad(number, targetLength) { + let output = number + ""; + while (output.length < targetLength) { + output = "0" + output; + } + return output; + } + + /** + * Read argument bus switches X & . and convert to 1 & 0 + */ + readBusSwitches(row) { + let output = [-1, -1, -1, -1, -1]; + for (let c=0;c<5;c++) { + if (row[c]===".") output[c] = 0; + if (row[c]==="x") output[c] = 1; + } + return output; + } + +} diff --git a/src/core/lib/Lorenz.mjs b/src/core/lib/Lorenz.mjs new file mode 100644 index 00000000..e69946fa --- /dev/null +++ b/src/core/lib/Lorenz.mjs @@ -0,0 +1,155 @@ +/** + * Resources required by the Lorenz SZ40/42 and Colossus + * + * @author VirtualColossus + * @copyright Crown Copyright 2019 + * @license Apache-2.0 + */ +import OperationError from "../errors/OperationError.mjs"; + +export const SWITCHES = [ + {name: "Up (.)", value: "."}, + {name: "Centre", value: ""}, + {name: "Down (x)", value: "x"} +]; + +export const ITA2_TABLE = { + "A": "11000", + "B": "10011", + "C": "01110", + "D": "10010", + "E": "10000", + "F": "10110", + "G": "01011", + "H": "00101", + "I": "01100", + "J": "11010", + "K": "11110", + "L": "01001", + "M": "00111", + "N": "00110", + "O": "00011", + "P": "01101", + "Q": "11101", + "R": "01010", + "S": "10100", + "T": "00001", + "U": "11100", + "V": "01111", + "W": "11001", + "X": "10111", + "Y": "10101", + "Z": "10001", + "3": "00010", + "4": "01000", + "9": "00100", + "/": "00000", + " ": "00100", + ".": "00100", + "8": "11111", + "5": "11011", + "-": "11111", + "+": "11011" +}; + +export const ROTOR_SIZES = { + S1: 43, + S2: 47, + S3: 51, + S4: 53, + S5: 59, + M37: 37, + M61: 61, + X1: 41, + X2: 31, + X3: 29, + X4: 26, + X5: 23 +}; + +/** + * Initial rotor patterns + */ +export const INIT_PATTERNS = { + "No Pattern": { + "X": { + 1: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + 4: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + 5: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + }, + "S": { + 1: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + 2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + 3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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 0] + }, + "M": { + 1: [1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1], + 2: [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1] + } + } +}; \ No newline at end of file diff --git a/src/core/operations/Colossus.mjs b/src/core/operations/Colossus.mjs new file mode 100644 index 00000000..09160f38 --- /dev/null +++ b/src/core/operations/Colossus.mjs @@ -0,0 +1,517 @@ +/** + * Emulation of Colossus. + * + * @author VirtualColossus [martin@virtualcolossus.co.uk] + * @copyright Crown Copyright 2019 + * @license Apache-2.0 + */ + +import Operation from "../Operation"; +import OperationError from "../errors/OperationError.mjs"; +import { ColossusComputer } from "../lib/Colossus.mjs"; +import { SWITCHES } from "../lib/Lorenz.mjs"; + +/** + * Colossus operation + */ +class Colossus extends Operation { + + /** + * Lorenz constructor + */ + constructor() { + super(); + this.name = "Colossus"; + this.module = "Bletchley"; + this.description = "Colossus ... "; + this.infoURL = "https://wikipedia.org/wiki/Colossus_computer"; + this.inputType = "string"; + this.outputType = "JSON"; + this.presentType = "html"; + this.args = [ + { + name: "Input", + type: "label" + }, + { + name: "Pattern", + type: "option", + value: ["KH Pattern", "ZMUG Pattern", "BREAM Pattern"] + }, + { + name: "QBusZ", + type: "option", + value: ["", "Z", "ΔZ"] + }, + { + name: "QBusΧ", + type: "option", + value: ["", "Χ", "ΔΧ"] + }, + { + name: "QBusΨ", + type: "option", + value: ["", "Ψ", "ΔΨ"] + }, + { + name: "Limitation", + type: "option", + value: ["None", "Χ2", "Χ2 + P5", "X2 + Ψ1", "X2 + Ψ1 + P5"] + }, + { + name: "K Rack Option", + type: "argSelector", + "value": [ + { + name: "Select Program", + on: [7], + off: [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40] + }, + { + name: "Top Section - Conditional", + on: [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30], + off: [7, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40] + }, + { + name: "Bottom Section - Addition", + on: [31, 32, 33, 34, 35, 36, 37, 38, 39, 40], + off: [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30] + }, + { + name: "Advanced", + on: [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40], + off: [7] + } + ] + }, + { + name: "Program to run", + type: "option", + value: ["", "1+2=. (1+2 Break In, Find X1,X2)", "4=3=/1=2 (Given X1,X2 find X4,X5)", "/,5,U (Count chars to find X3)"] + }, + { + name: "K Rack: Conditional", + type: "label" + }, + { + name: "R1-Q1", + type: "editableOptionShort", + value: SWITCHES, + defaultIndex: 1 + }, + { + name: "R1-Q2", + type: "editableOptionShort", + value: SWITCHES, + defaultIndex: 1 + }, + { + name: "R1-Q3", + type: "editableOptionShort", + value: SWITCHES, + defaultIndex: 1 + }, + { + name: "R1-Q4", + type: "editableOptionShort", + value: SWITCHES, + defaultIndex: 1 + }, + { + name: "R1-Q5", + type: "editableOptionShort", + value: SWITCHES, + defaultIndex: 1 + }, + { + name: "R1-Negate", + type: "boolean" + }, + { + name: "R1-Counter", + type: "option", + value: ["", "1", "2", "3", "4", "5"] + }, + { + name: "R2-Q1", + type: "editableOptionShort", + value: SWITCHES, + defaultIndex: 1 + }, + { + name: "R2-Q2", + type: "editableOptionShort", + value: SWITCHES, + defaultIndex: 1 + }, + { + name: "R2-Q3", + type: "editableOptionShort", + value: SWITCHES, + defaultIndex: 1 + }, + { + name: "R2-Q4", + type: "editableOptionShort", + value: SWITCHES, + defaultIndex: 1 + }, + { + name: "R2-Q5", + type: "editableOptionShort", + value: SWITCHES, + defaultIndex: 1 + }, + { + name: "R2-Negate", + type: "boolean" + }, + { + name: "R2-Counter", + type: "option", + value: ["", "1", "2", "3", "4", "5"] + }, + { + name: "R3-Q1", + type: "editableOptionShort", + value: SWITCHES, + defaultIndex: 1 + }, + { + name: "R3-Q2", + type: "editableOptionShort", + value: SWITCHES, + defaultIndex: 1 + }, + { + name: "R3-Q3", + type: "editableOptionShort", + value: SWITCHES, + defaultIndex: 1 + }, + { + name: "R3-Q4", + type: "editableOptionShort", + value: SWITCHES, + defaultIndex: 1 + }, + { + name: "R3-Q5", + type: "editableOptionShort", + value: SWITCHES, + defaultIndex: 1 + }, + { + name: "R3-Negate", + type: "boolean" + }, + { + name: "R3-Counter", + type: "option", + value: ["", "1", "2", "3", "4", "5"] + }, + { + name: "Negate All", + type: "boolean" + }, + { + name: "K Rack: Addition", + type: "label" + }, + { + name: "Add-Q1", + type: "boolean" + }, + { + name: "Add-Q2", + type: "boolean" + }, + { + name: "Add-Q3", + type: "boolean" + }, + { + name: "Add-Q4", + type: "boolean" + }, + { + name: "Add-Q5", + type: "boolean" + }, + { + name: "Add-Equals", + type: "editableOptionShort", + value: SWITCHES + }, + { + name: "Add-Counter1", + type: "boolean" + }, + { + name: "Add Negate All", + type: "boolean" + }, + { + name: "Total Motor", + type: "boolean" + }, + { + name: "Master Control Panel", + type: "label" + }, + { + name: "Set Total", + type: "number", + value: 0 + }, + { + name: "Fast Step", + type: "option", + value: ["", "X1", "X2", "X3", "X4", "X5", "M37", "M61", "S1", "S2", "S3", "S4", "S5"] + }, + { + name: "Slow Step", + type: "option", + value: ["", "X1", "X2", "X3", "X4", "X5", "M37", "M61", "S1", "S2", "S3", "S4", "S5"] + }, + { + name: "Start X1", + type: "number", + value: 1 + }, + { + name: "Start X2", + type: "number", + value: 1 + }, + { + name: "Start X3", + type: "number", + value: 1 + }, + { + name: "Start X4", + type: "number", + value: 1 + }, + { + name: "Start X5", + type: "number", + value: 1 + }, + { + name: "Start M61", + type: "number", + value: 1 + }, + { + name: "Start M37", + type: "number", + value: 1 + }, + { + name: "Start S1", + type: "number", + value: 1 + }, + { + name: "Start S2", + type: "number", + value: 1 + }, + { + name: "Start S3", + type: "number", + value: 1 + }, + { + name: "Start S4", + type: "number", + value: 1 + }, + { + name: "Start S5", + type: "number", + value: 1 + } + ]; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {Object} + */ + run(input, args) { + + const pattern = args[1]; + const qbusin = { + "Z": args[2], + "Chi": args[3], + "Psi": args[4], + }; + + const limitation = args[5]; + let lm = [false,false,false]; + if (limitation.includes("Χ2")) lm[0] = true; + if (limitation.includes("Ψ1")) lm[1] = true; + if (limitation.includes("P5")) lm[2] = true; + const limit = { + X2: lm[0], S1: lm[1], P5: lm[2] + }; + + const KRackOpt = args[6]; + const setProgram = args[7]; + + if (KRackOpt === "Select Program" && setProgram !== "") { + args = this.selectProgram(setProgram, args); + } + + // Q1,Q2,Q3,Q4,Q5,negate,counter1 + const qbusswitches = { + condition: [ + {Qswitches: [args[9], args[10], args[11], args[12], args[13]], Negate: args[14], Counter: args[15]}, + {Qswitches: [args[16], args[17], args[18], args[19], args[20]], Negate: args[21], Counter: args[22]}, + {Qswitches: [args[23], args[24], args[25], args[26], args[27]], Negate: args[28], Counter: args[29]} + ], + condNegateAll: args[30], + addition: [ + {Qswitches: [args[32], args[33], args[34], args[35], args[36]], Equals: args[37], C1: args[38]} + ], + addNegateAll: args[39], + totalMotor: args[40] + }; + + const settotal = args[42]; + + // null|fast|slow for each of S1-5,M1-2,X1-5 + const control = { + fast: args[43], + slow: args[44] + }; + + // Start positions + const starts = { + X1: args[45], X2: args[46], X3: args[47], X4: args[48], X5: args[49], + M61: args[50], M37: args[51], + S1: args[52], S2: args[53], S3: args[54], S4: args[55], S5: args[56] + }; + + const colossus = new ColossusComputer(input, pattern, qbusin, qbusswitches, control, starts, settotal, limit); + const result = colossus.run(); + + console.log(result); + + return result; + + } + + /** + * Select Program + */ + selectProgram(progname, args) { + + // Bill Tutte's 1+2 Break In + if(progname == "1+2=. (1+2 Break In, Find X1,X2)") { + // Clear any other counters + args[15] = ""; // Conditional R1 + args[22] = ""; // Conditional R2 + args[29] = ""; // Conditional R3 + // Set Add Q1+Q2=. into Counter 1 + args[32] = true; + args[33] = true; + args[34] = false; + args[35] = false; + args[36] = false; + args[37] = "."; + args[38] = true; + } + + // 4=3=/1=2 : Find X4 & X5 where X1 & X2 are known + if(progname == "4=3=/1=2 (Given X1,X2 find X4,X5)") { + // Set Conditional R1 : Match NOT ..?.. into counter 1 + args[9] = "."; + args[10] = "."; + args[11] = ""; + args[12] = "."; + args[13] = "."; + args[14] = true; + args[15] = "1"; + // Set Conditional R2 : AND Match NOT xx?xx into counter 1 + args[16] = "x"; + args[17] = "x"; + args[18] = ""; + args[19] = "x"; + args[20] = "x"; + args[21] = true; + args[22] = "1"; + // clear Conditional R3 + args[29] = ""; + // Negate result, giving NOT(NOT Q1 AND NOT Q2) which is equivalent to Q1 OR Q2 + args[30] = true; + // Clear Addition row counter + args[38] = false; + } + + // /,5,U : Count number of matches of /, 5 & U to find X3 + if(progname == "/,5,U (Count chars to find X3)") { + // Set Conditional R1 : Match / char, ITA2 = ..... into counter 1 + args[9] = "."; + args[10] = "."; + args[11] = "."; + args[12] = "."; + args[13] = "."; + args[14] = false; + args[15] = "1"; + // Set Conditional R2 : Match 5 char, ITA2 = xx.xx into counter 2 + args[16] = "x"; + args[17] = "x"; + args[18] = "."; + args[19] = "x"; + args[20] = "x"; + args[21] = false; + args[22] = "2"; + // Set Conditional R3 : Match U char, ITA2 = xxx.. into counter 3 + args[23] = "x"; + args[24] = "x"; + args[25] = "x"; + args[26] = "."; + args[27] = "."; + args[28] = false; + args[29] = "3"; + // Clear Negate result + args[30] = false; + // Clear Addition row counter + args[38] = false; + } + + return args; + } + + /** + * Displays Colossus results in an HTML table + * + * @param {Object} output + * @param {Object[]} output.counters + * @returns {html} + */ + present(output) { + console.log("output="+ typeof(output)); + console.log("counters="+ typeof(output.counters)); + + let html = "Colossus Printer\n\n"; + html += output.printout + "\n\n"; + html += "Colossus Counters\n\n"; + html += "\n"; + html += ""; + for (const ct of output.counters) { + html += `\n`; + } + html += ""; + html += "
C1 C2 C3 C4 C5
${ct}
"; + return html; + } + +} + +export default Colossus; From 32625dc0b0a1692d25a21a1496b4d9973b1383ab Mon Sep 17 00:00:00 2001 From: VirtualColossus Date: Wed, 27 Nov 2019 12:49:35 +0000 Subject: [PATCH 02/10] Added label type ingredient --- src/web/HTMLIngredient.mjs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/web/HTMLIngredient.mjs b/src/web/HTMLIngredient.mjs index fd496f2a..18503dff 100755 --- a/src/web/HTMLIngredient.mjs +++ b/src/web/HTMLIngredient.mjs @@ -293,6 +293,16 @@ class HTMLIngredient { this.manager.addDynamicListener(".arg-selector", "change", this.argSelectorChange, this); break; + case "label": + html += `
+ + +
`; + break; default: break; } From 820bd2f8679c4f142b33484436c4b5a213769bea Mon Sep 17 00:00:00 2001 From: VirtualColossus Date: Wed, 27 Nov 2019 13:38:28 +0000 Subject: [PATCH 03/10] Added Total Motor, fixed bug in printout --- src/core/lib/Colossus.mjs | 27 ++++++++++++++++--------- src/core/operations/Colossus.mjs | 34 ++++++++++++++++++++++++++------ 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/core/lib/Colossus.mjs b/src/core/lib/Colossus.mjs index d25d3285..da6829e7 100644 --- a/src/core/lib/Colossus.mjs +++ b/src/core/lib/Colossus.mjs @@ -61,6 +61,8 @@ export class ColossusComputer { this.rotorPtrs = {}; + this.totalmotor = 0; + } /** @@ -98,13 +100,17 @@ export class ColossusComputer { var slowRef = "00"; if (fast !== "") fastRef = this.leftPad(this.rotorPtrs[fast],2); if (slow !== "") slowRef = this.leftPad(this.rotorPtrs[slow],2); - result.printout += fastRef + " " + slowRef + " : "; + var printline = ''; for (let c=0;c<5;c++) { if (this.allCounters[c] > this.settotal) { - result.printout += String.fromCharCode(c+97) + this.allCounters[c]+" "; + printline += String.fromCharCode(c+97) + this.allCounters[c]+" "; } } - result.printout += "\n"; + if (printline !== "") { + result.printout += fastRef + " " + slowRef + " : "; + result.printout += printline; + result.printout += "\n"; + } // Step fast rotor if required if (fast != '') { @@ -193,17 +199,17 @@ export class ColossusComputer { //console.log(this.Mptr); //console.log(this.rings.M[2]); const basicmotor = this.rings.M[2][this.Mptr[0]-1]; - let totalmotor = basicmotor; + this.totalmotor = basicmotor; if (x2sw || s1sw) { if (basicmotor===0 && lim===1) { - totalmotor = 0; + this.totalmotor = 0; } else { - totalmotor = 1; + this.totalmotor = 1; } } - //console.log('BM='+basicmotor+', TM='+totalmotor); + //console.log('BM='+basicmotor+', TM='+this.totalmotor); // Step Chi rotors for (let r=0; r<5; r++) { @@ -211,7 +217,7 @@ export class ColossusComputer { if (this.Xptr[r] > ROTOR_SIZES["X"+(r+1)]) this.Xptr[r] = 1; } - if (totalmotor) { + if (this.totalmotor) { //console.log('step Psi'); // Step Psi rotors for (let r=0; r<5; r++) { @@ -346,7 +352,10 @@ export class ColossusComputer { for (let c=0;c<5;c++) { if (this.qbusswitches.condNegateAll) cnt[c] = !cnt[c]; - if (cnt[c]==1) this.allCounters[c]++; + if (this.qbusswitches.totalMotor === "" || (this.qbusswitches.totalMotor === "x" && this.totalmotor == 0) || (this.qbusswitches.totalMotor === "." && this.totalmotor == 1)) { + if (cnt[c]==1) this.allCounters[c]++; + } + } } diff --git a/src/core/operations/Colossus.mjs b/src/core/operations/Colossus.mjs index 09160f38..46f0451e 100644 --- a/src/core/operations/Colossus.mjs +++ b/src/core/operations/Colossus.mjs @@ -87,7 +87,7 @@ class Colossus extends Operation { { name: "Program to run", type: "option", - value: ["", "1+2=. (1+2 Break In, Find X1,X2)", "4=3=/1=2 (Given X1,X2 find X4,X5)", "/,5,U (Count chars to find X3)"] + value: ["", "Letter Count", "1+2=. (1+2 Break In, Find X1,X2)", "4=3=/1=2 (Given X1,X2 find X4,X5)", "/,5,U (Count chars to find X3)"] }, { name: "K Rack: Conditional", @@ -241,7 +241,8 @@ class Colossus extends Operation { { name: "Add-Equals", type: "editableOptionShort", - value: SWITCHES + value: SWITCHES, + defaultIndex: 1 }, { name: "Add-Counter1", @@ -253,7 +254,9 @@ class Colossus extends Operation { }, { name: "Total Motor", - type: "boolean" + type: "editableOptionShort", + value: SWITCHES, + defaultIndex: 1 }, { name: "Master Control Panel", @@ -411,8 +414,27 @@ class Colossus extends Operation { */ selectProgram(progname, args) { + // Basic Letter Count + if (progname == "Letter Count") { + // Set Conditional R1 : count every character into counter 1 + args[9] = ""; + args[10] = ""; + args[11] = ""; + args[12] = ""; + args[13] = ""; + args[14] = false; + args[15] = "1"; + // clear Conditional R2 & R3 + args[22] = ""; + args[29] = ""; + // Clear Negate result + args[30] = false; + // Clear Addition row counter + args[38] = false; + } + // Bill Tutte's 1+2 Break In - if(progname == "1+2=. (1+2 Break In, Find X1,X2)") { + if (progname == "1+2=. (1+2 Break In, Find X1,X2)") { // Clear any other counters args[15] = ""; // Conditional R1 args[22] = ""; // Conditional R2 @@ -428,7 +450,7 @@ class Colossus extends Operation { } // 4=3=/1=2 : Find X4 & X5 where X1 & X2 are known - if(progname == "4=3=/1=2 (Given X1,X2 find X4,X5)") { + if (progname == "4=3=/1=2 (Given X1,X2 find X4,X5)") { // Set Conditional R1 : Match NOT ..?.. into counter 1 args[9] = "."; args[10] = "."; @@ -454,7 +476,7 @@ class Colossus extends Operation { } // /,5,U : Count number of matches of /, 5 & U to find X3 - if(progname == "/,5,U (Count chars to find X3)") { + if (progname == "/,5,U (Count chars to find X3)") { // Set Conditional R1 : Match / char, ITA2 = ..... into counter 1 args[9] = "."; args[10] = "."; From 61ab9a904f06dd5f527b9b3566b7dd7d81e6c1b9 Mon Sep 17 00:00:00 2001 From: VirtualColossus Date: Thu, 28 Nov 2019 13:22:51 +0000 Subject: [PATCH 04/10] Added argument validation --- src/core/lib/Colossus.mjs | 140 +++++++++++++++---------------- src/core/lib/Lorenz.mjs | 3 +- src/core/operations/Colossus.mjs | 57 +++++++++---- 3 files changed, 111 insertions(+), 89 deletions(-) diff --git a/src/core/lib/Colossus.mjs b/src/core/lib/Colossus.mjs index da6829e7..acb8d6fc 100644 --- a/src/core/lib/Colossus.mjs +++ b/src/core/lib/Colossus.mjs @@ -5,8 +5,6 @@ * @copyright Crown Copyright 2019 * @license Apache-2.0 */ -import OperationError from "../errors/OperationError.mjs"; -import Utils from "../Utils.mjs"; import {INIT_PATTERNS, ITA2_TABLE, ROTOR_SIZES} from "../lib/Lorenz.mjs"; /** @@ -26,10 +24,10 @@ export class ColossusComputer { constructor(ciphertext, pattern, qbusin, qbusswitches, control, starts, settotal, limit) { this.ITAlookup = ITA2_TABLE; - this.REVERSE_ITAlookup = {}; + this.ReverseITAlookup = {}; for (const letter in this.ITAlookup) { const code = this.ITAlookup[letter]; - this.REVERSE_ITAlookup[code] = letter; + this.ReverseITAlookup[code] = letter; } this.initThyratrons(pattern); @@ -71,13 +69,13 @@ export class ColossusComputer { */ run() { - let result = { + const result = { printout: "" }; // loop until our start positions are back to the beginning this.rotorPtrs = {X1: this.starts.X1, X2: this.starts.X2, X3: this.starts.X3, X4: this.starts.X4, X5: this.starts.X5, M61: this.starts.M61, M37: this.starts.M37, S1: this.starts.S1, S2: this.starts.S2, S3: this.starts.S3, S4: this.starts.S4, S5: this.starts.S5}; - //this.rotorPtrs = this.starts; + // this.rotorPtrs = this.starts; let runcount = 1; const fast = this.control.fast; @@ -96,11 +94,11 @@ export class ColossusComputer { this.runTape(); // Only print result if larger than set total - var fastRef = "00"; - var slowRef = "00"; - if (fast !== "") fastRef = this.leftPad(this.rotorPtrs[fast],2); - if (slow !== "") slowRef = this.leftPad(this.rotorPtrs[slow],2); - var printline = ''; + let fastRef = "00"; + let slowRef = "00"; + if (fast !== "") fastRef = this.leftPad(this.rotorPtrs[fast], 2); + if (slow !== "") slowRef = this.leftPad(this.rotorPtrs[slow], 2); + let printline = ""; for (let c=0;c<5;c++) { if (this.allCounters[c] > this.settotal) { printline += String.fromCharCode(c+97) + this.allCounters[c]+" "; @@ -110,16 +108,16 @@ export class ColossusComputer { result.printout += fastRef + " " + slowRef + " : "; result.printout += printline; result.printout += "\n"; - } + } // Step fast rotor if required - if (fast != '') { + if (fast !== "") { this.rotorPtrs[fast]++; if (this.rotorPtrs[fast] > ROTOR_SIZES[fast]) this.rotorPtrs[fast] = 1; } - + // Step slow rotor if fast rotor has returned to initial start position - if (slow != '' && this.rotorPtrs[fast] === this.starts[fast]) { + if (slow !== "" && this.rotorPtrs[fast] === this.starts[fast]) { this.rotorPtrs[slow]++; if (this.rotorPtrs[slow] > ROTOR_SIZES[slow]) this.rotorPtrs[slow] = 1; } @@ -132,7 +130,7 @@ export class ColossusComputer { result.runcount = runcount; return result; - }; + } /** * Run tape loop @@ -144,13 +142,13 @@ export class ColossusComputer { this.Xptr = [this.rotorPtrs.X1, this.rotorPtrs.X2, this.rotorPtrs.X3, this.rotorPtrs.X4, this.rotorPtrs.X5]; this.Mptr = [this.rotorPtrs.M37, this.rotorPtrs.M61]; this.Sptr = [this.rotorPtrs.S1, this.rotorPtrs.S2, this.rotorPtrs.S3, this.rotorPtrs.S4, this.rotorPtrs.S5]; - //console.log(this.Xptr); + // console.log(this.Xptr); // Run full loop of all character on the input tape (Z) for (let i=0; i ROTOR_SIZES["S"+(r+1)]) this.Sptr[r] = 1; } } - + // Move M37 rotor if M61 set - if (this.rings.M[1][this.Mptr[1]-1]==1) this.Mptr[0]++; + if (this.rings.M[1][this.Mptr[1]-1]===1) this.Mptr[0]++; if (this.Mptr[0] > ROTOR_SIZES.M37) this.Mptr[0]=1; // Always move M61 rotor @@ -242,107 +240,107 @@ export class ColossusComputer { getQbusInputs(charZin) { // Zbits - the bits from the current character from the cipher tape. this.Zbits = this.ITAlookup[charZin].split(""); - //console.log('Zbits = '+this.Zbits); - if (this.qbusin.Z == 'Z') { + // console.log('Zbits = '+this.Zbits); + if (this.qbusin.Z === "Z") { // direct Z this.Qbits = this.Zbits; - //console.log('direct Z: Qbits = '+this.Qbits); - } else if(this.qbusin.Z == 'ΔZ') { + // console.log('direct Z: Qbits = '+this.Qbits); + } else if (this.qbusin.Z === "ΔZ") { // delta Z, the Bitwise XOR of this character Zbits + last character Zbits - for(let b=0;b<5;b++) { + for (let b=0;b<5;b++) { this.Qbits[b] = this.Zbits[b] ^ this.ZbitsOneBack[b]; } - //console.log('delta Z: Qbits = '+this.Qbits); + // console.log('delta Z: Qbits = '+this.Qbits); } this.ZbitsOneBack = this.Zbits.slice(); // copy value of object, not reference - //console.log('Zin::Q bus now '+this.Qbits+'['+this.REVERSE_ITAlookup[this.Qbits.join("")]+']'); + // console.log('Zin::Q bus now '+this.Qbits+'['+this.ReverseITAlookup[this.Qbits.join("")]+']'); // Xbits - the current Chi wheel bits - //console.log(this.rings.X); - //console.log('Xptr = '+this.Xptr); + // console.log(this.rings.X); + // console.log('Xptr = '+this.Xptr); for (let b=0;b<5;b++) { this.Xbits[b] = this.rings.X[b+1][this.Xptr[b]-1]; } - if (this.qbusin.Chi != "") { - //console.log('X Bits '+this.Xbits+'['+this.REVERSE_ITAlookup[this.Xbits.join("")]+']'); - //console.log('X Char = ' + this.REVERSE_ITAlookup[this.Xbits.join("")]); - if (this.qbusin.Chi == "Χ") { + if (this.qbusin.Chi !== "") { + // console.log('X Bits '+this.Xbits+'['+this.ReverseITAlookup[this.Xbits.join("")]+']'); + // console.log('X Char = ' + this.ReverseITAlookup[this.Xbits.join("")]); + if (this.qbusin.Chi === "Χ") { // direct X added to Qbits for (let b=0;b<5;b++) { this.Qbits[b] = this.Qbits[b] ^ this.Xbits[b]; } - //console.log('direct X: Qbits = '+this.Qbits); - } else if(this.qbusin.Chi == "ΔΧ") { + // console.log('direct X: Qbits = '+this.Qbits); + } else if (this.qbusin.Chi === "ΔΧ") { // delta X - for(let b=0;b<5;b++) { + for (let b=0;b<5;b++) { this.Qbits[b] = this.Qbits[b] ^ this.Xbits[b]; this.Qbits[b] = this.Qbits[b] ^ this.XbitsOneBack[b]; } - //console.log('delta X: Xbits = '+this.Xbits+' Xbits-1 = '+this.XbitsOneBack); - //console.log('delta X: Qbits = '+this.Qbits); + // console.log('delta X: Xbits = '+this.Xbits+' Xbits-1 = '+this.XbitsOneBack); + // console.log('delta X: Qbits = '+this.Qbits); } } this.XbitsOneBack = this.Xbits.slice(); - //console.log('setting XbitsOneBack to '+this.Xbits); + // console.log('setting XbitsOneBack to '+this.Xbits); - //console.log('Zin+Xin::Q bus now '+this.Qbits+'['+this.REVERSE_ITAlookup[this.Qbits.join("")]+']'); + // console.log('Zin+Xin::Q bus now '+this.Qbits+'['+this.ReverseITAlookup[this.Qbits.join("")]+']'); // Sbits - the current Psi wheel bits - //console.log(this.rings.S); - //console.log('Sptr = '+this.Sptr); + // console.log(this.rings.S); + // console.log('Sptr = '+this.Sptr); for (let b=0;b<5;b++) { this.Sbits[b] = this.rings.S[b+1][this.Sptr[b]-1]; } - if (this.qbusin.Psi != "") { - //console.log('S Bits '+this.Sbits+'['+this.REVERSE_ITAlookup[this.Sbits.join("")]+']'); - //console.log('S Char = ' + this.REVERSE_ITAlookup[this.Sbits.join("")]); - if(this.qbusin.Psi == "Ψ") { + if (this.qbusin.Psi !== "") { + // console.log('S Bits '+this.Sbits+'['+this.ReverseITAlookup[this.Sbits.join("")]+']'); + // console.log('S Char = ' + this.ReverseITAlookup[this.Sbits.join("")]); + if (this.qbusin.Psi === "Ψ") { // direct S added to Qbits for (let b=0;b<5;b++) { this.Qbits[b] = this.Qbits[b] ^ this.Sbits[b]; } - //console.log('direct S: Qbits = '+this.Qbits); - } else if(this.qbusin.Psi == "ΔΨ") { + // console.log('direct S: Qbits = '+this.Qbits); + } else if (this.qbusin.Psi === "ΔΨ") { // delta S for (let b=0;b<5;b++) { this.Qbits[b] = this.Qbits[b] ^ this.Sbits[b]; this.Qbits[b] = this.Qbits[b] ^ this.SbitsOneBack[b]; } - //console.log('delta S: Qbits = '+this.Qbits); + // console.log('delta S: Qbits = '+this.Qbits); } } this.SbitsOneBack = this.Sbits.slice(); - //console.log('Q bus now '+this.Qbits+'['+this.REVERSE_ITAlookup[this.Qbits.join("")]+']'); + // console.log('Q bus now '+this.Qbits+'['+this.ReverseITAlookup[this.Qbits.join("")]+']'); } /** * Conditional impulse Q bus section */ runQbusProcessingConditional() { - let cnt = [-1, -1, -1, -1, -1]; + const cnt = [-1, -1, -1, -1, -1]; const numrows = this.qbusswitches.condition.length; for (let r=0;r= 0 && Qswitch[s] != this.Qbits[s]) result = false; + if (Qswitch[s] >= 0 && Qswitch[s] !== this.Qbits[s]) result = false; } // Check for NOT switch if (row.Negate) result = !result; // AND each row to get final result - if (cnt[cPnt] == -1) { + if (cnt[cPnt] === -1) { cnt[cPnt] = result; - } else if (result==0) { + } else if (result === 0) { cnt[cPnt] = 0; } } @@ -352,10 +350,10 @@ export class ColossusComputer { for (let c=0;c<5;c++) { if (this.qbusswitches.condNegateAll) cnt[c] = !cnt[c]; - if (this.qbusswitches.totalMotor === "" || (this.qbusswitches.totalMotor === "x" && this.totalmotor == 0) || (this.qbusswitches.totalMotor === "." && this.totalmotor == 1)) { - if (cnt[c]==1) this.allCounters[c]++; + if (this.qbusswitches.totalMotor === "" || (this.qbusswitches.totalMotor === "x" && this.totalmotor === 0) || (this.qbusswitches.totalMotor === "." && this.totalmotor === 1)) { + if (cnt[c]===1) this.allCounters[c]++; } - + } } @@ -364,7 +362,7 @@ export class ColossusComputer { * Addition of impulses Q bus section */ runQbusProcessingAddition() { - let row = this.qbusswitches.addition[0]; + const row = this.qbusswitches.addition[0]; const Qswitch = row.Qswitches.slice(); if (row.C1) { let addition = 0; @@ -374,12 +372,12 @@ export class ColossusComputer { addition = addition ^ this.Qbits[s]; } } - const equals = (row.Equals==""?-1:(row.Equals=="."?0:1)); - if (addition == equals) { + const equals = (row.Equals===""?-1:(row.Equals==="."?0:1)); + if (addition === equals) { this.allCounters[0]++; } } - //console.log("counter1="+this.allCounters[0]); + // console.log("counter1="+this.allCounters[0]); } /** @@ -424,7 +422,7 @@ export class ColossusComputer { * Read argument bus switches X & . and convert to 1 & 0 */ readBusSwitches(row) { - let output = [-1, -1, -1, -1, -1]; + const output = [-1, -1, -1, -1, -1]; for (let c=0;c<5;c++) { if (row[c]===".") output[c] = 0; if (row[c]==="x") output[c] = 1; diff --git a/src/core/lib/Lorenz.mjs b/src/core/lib/Lorenz.mjs index e69946fa..fa4350e0 100644 --- a/src/core/lib/Lorenz.mjs +++ b/src/core/lib/Lorenz.mjs @@ -5,7 +5,6 @@ * @copyright Crown Copyright 2019 * @license Apache-2.0 */ -import OperationError from "../errors/OperationError.mjs"; export const SWITCHES = [ {name: "Up (.)", value: "."}, @@ -152,4 +151,4 @@ export const INIT_PATTERNS = { 2: [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1] } } -}; \ No newline at end of file +}; diff --git a/src/core/operations/Colossus.mjs b/src/core/operations/Colossus.mjs index 46f0451e..60c7f14c 100644 --- a/src/core/operations/Colossus.mjs +++ b/src/core/operations/Colossus.mjs @@ -278,27 +278,27 @@ class Colossus extends Operation { value: ["", "X1", "X2", "X3", "X4", "X5", "M37", "M61", "S1", "S2", "S3", "S4", "S5"] }, { - name: "Start X1", + name: "Start Χ1", type: "number", value: 1 }, { - name: "Start X2", + name: "Start Χ2", type: "number", value: 1 }, { - name: "Start X3", + name: "Start Χ3", type: "number", value: 1 }, { - name: "Start X4", + name: "Start Χ4", type: "number", value: 1 }, { - name: "Start X5", + name: "Start Χ5", type: "number", value: 1 }, @@ -313,27 +313,27 @@ class Colossus extends Operation { value: 1 }, { - name: "Start S1", + name: "Start Ψ1", type: "number", value: 1 }, { - name: "Start S2", + name: "Start Ψ2", type: "number", value: 1 }, { - name: "Start S3", + name: "Start Ψ3", type: "number", value: 1 }, { - name: "Start S4", + name: "Start Ψ4", type: "number", value: 1 }, { - name: "Start S5", + name: "Start Ψ5", type: "number", value: 1 } @@ -355,7 +355,7 @@ class Colossus extends Operation { }; const limitation = args[5]; - let lm = [false,false,false]; + const lm = [false, false, false]; if (limitation.includes("Χ2")) lm[0] = true; if (limitation.includes("Ψ1")) lm[1] = true; if (limitation.includes("P5")) lm[2] = true; @@ -370,6 +370,16 @@ class Colossus extends Operation { args = this.selectProgram(setProgram, args); } + const re = new RegExp("^$|^[.x]$"); + for (let qr=0;qr<3;qr++) { + for (let a=0;a<5;a++) { + if (!re.test(args[((qr*7)+(a+9))])) throw new OperationError("Switch R"+(qr+1)+"-Q"+(a+1)+" can only be set to blank, . or x"); + } + } + + if (!re.test(args[37])) throw new OperationError("Switch Add-Equals can only be set to blank, . or x"); + if (!re.test(args[40])) throw new OperationError("Switch Total Motor can only be set to blank, . or x"); + // Q1,Q2,Q3,Q4,Q5,negate,counter1 const qbusswitches = { condition: [ @@ -385,7 +395,8 @@ class Colossus extends Operation { totalMotor: args[40] }; - const settotal = args[42]; + const settotal = parseInt(args[42], 10); + if (settotal < 0 || settotal > 9999) throw new OperationError("Set Total must be between 0000 and 9999"); // null|fast|slow for each of S1-5,M1-2,X1-5 const control = { @@ -394,6 +405,20 @@ class Colossus extends Operation { }; // Start positions + + if (args[52]<1 || args[52]>43) throw new OperationError("Ψ1 start must be between 1 and 43"); + if (args[53]<1 || args[53]>47) throw new OperationError("Ψ2 start must be between 1 and 47"); + if (args[54]<1 || args[54]>51) throw new OperationError("Ψ3 start must be between 1 and 51"); + if (args[55]<1 || args[55]>53) throw new OperationError("Ψ4 start must be between 1 and 53"); + if (args[56]<1 || args[57]>59) throw new OperationError("Ψ5 start must be between 1 and 59"); + if (args[51]<1 || args[51]>37) throw new OperationError("Μ37 start must be between 1 and 37"); + if (args[50]<1 || args[50]>61) throw new OperationError("Μ61 start must be between 1 and 61"); + if (args[45]<1 || args[45]>41) throw new OperationError("Χ1 start must be between 1 and 41"); + if (args[46]<1 || args[46]>31) throw new OperationError("Χ2 start must be between 1 and 31"); + if (args[47]<1 || args[47]>29) throw new OperationError("Χ3 start must be between 1 and 29"); + if (args[48]<1 || args[48]>26) throw new OperationError("Χ4 start must be between 1 and 26"); + if (args[49]<1 || args[49]>23) throw new OperationError("Χ5 start must be between 1 and 23"); + const starts = { X1: args[45], X2: args[46], X3: args[47], X4: args[48], X5: args[49], M61: args[50], M37: args[51], @@ -415,7 +440,7 @@ class Colossus extends Operation { selectProgram(progname, args) { // Basic Letter Count - if (progname == "Letter Count") { + if (progname === "Letter Count") { // Set Conditional R1 : count every character into counter 1 args[9] = ""; args[10] = ""; @@ -434,7 +459,7 @@ class Colossus extends Operation { } // Bill Tutte's 1+2 Break In - if (progname == "1+2=. (1+2 Break In, Find X1,X2)") { + if (progname === "1+2=. (1+2 Break In, Find X1,X2)") { // Clear any other counters args[15] = ""; // Conditional R1 args[22] = ""; // Conditional R2 @@ -450,7 +475,7 @@ class Colossus extends Operation { } // 4=3=/1=2 : Find X4 & X5 where X1 & X2 are known - if (progname == "4=3=/1=2 (Given X1,X2 find X4,X5)") { + if (progname === "4=3=/1=2 (Given X1,X2 find X4,X5)") { // Set Conditional R1 : Match NOT ..?.. into counter 1 args[9] = "."; args[10] = "."; @@ -476,7 +501,7 @@ class Colossus extends Operation { } // /,5,U : Count number of matches of /, 5 & U to find X3 - if (progname == "/,5,U (Count chars to find X3)") { + if (progname === "/,5,U (Count chars to find X3)") { // Set Conditional R1 : Match / char, ITA2 = ..... into counter 1 args[9] = "."; args[10] = "."; From 57ee3f305dd63025c5cb30c79bb93090c6b65649 Mon Sep 17 00:00:00 2001 From: VirtualColossus Date: Thu, 28 Nov 2019 13:56:02 +0000 Subject: [PATCH 05/10] Fixed issue in counter --- src/core/lib/Colossus.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/lib/Colossus.mjs b/src/core/lib/Colossus.mjs index acb8d6fc..93ff8de5 100644 --- a/src/core/lib/Colossus.mjs +++ b/src/core/lib/Colossus.mjs @@ -339,7 +339,7 @@ export class ColossusComputer { // AND each row to get final result if (cnt[cPnt] === -1) { - cnt[cPnt] = result; + cnt[cPnt] = (result?1:0); } else if (result === 0) { cnt[cPnt] = 0; } From c32fec6b53758f9b33a479e31ea4b9feca7f3414 Mon Sep 17 00:00:00 2001 From: VirtualColossus Date: Sat, 30 Nov 2019 10:25:24 +0000 Subject: [PATCH 06/10] Various fixes for conditional calcs --- src/core/lib/Colossus.mjs | 12 ++++++------ src/core/lib/Lorenz.mjs | 2 ++ src/core/operations/Colossus.mjs | 16 +++++++++++++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/core/lib/Colossus.mjs b/src/core/lib/Colossus.mjs index 93ff8de5..59dc6d02 100644 --- a/src/core/lib/Colossus.mjs +++ b/src/core/lib/Colossus.mjs @@ -332,26 +332,26 @@ export class ColossusComputer { const Qswitch = this.readBusSwitches(row.Qswitches); // Match switches to bit pattern for (let s=0;s<5;s++) { - if (Qswitch[s] >= 0 && Qswitch[s] !== this.Qbits[s]) result = false; + if (Qswitch[s] >= 0 && Qswitch[s] !== parseInt(this.Qbits[s],10)) result = false; } // Check for NOT switch if (row.Negate) result = !result; // AND each row to get final result if (cnt[cPnt] === -1) { - cnt[cPnt] = (result?1:0); - } else if (result === 0) { - cnt[cPnt] = 0; + cnt[cPnt] = result; + } else if (!result) { + cnt[cPnt] = false; } } } // Negate the whole column, this allows A OR B by doing NOT(NOT A AND NOT B) for (let c=0;c<5;c++) { - if (this.qbusswitches.condNegateAll) cnt[c] = !cnt[c]; + if (this.qbusswitches.condNegateAll && cnt[c] !== -1) cnt[c] = !cnt[c]; if (this.qbusswitches.totalMotor === "" || (this.qbusswitches.totalMotor === "x" && this.totalmotor === 0) || (this.qbusswitches.totalMotor === "." && this.totalmotor === 1)) { - if (cnt[c]===1) this.allCounters[c]++; + if (cnt[c] === true) this.allCounters[c]++; } } diff --git a/src/core/lib/Lorenz.mjs b/src/core/lib/Lorenz.mjs index fa4350e0..916b470c 100644 --- a/src/core/lib/Lorenz.mjs +++ b/src/core/lib/Lorenz.mjs @@ -12,6 +12,8 @@ export const SWITCHES = [ {name: "Down (x)", value: "x"} ]; +export const VALID_ITA2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ34589+-./"; + export const ITA2_TABLE = { "A": "11000", "B": "10011", diff --git a/src/core/operations/Colossus.mjs b/src/core/operations/Colossus.mjs index 60c7f14c..896252dd 100644 --- a/src/core/operations/Colossus.mjs +++ b/src/core/operations/Colossus.mjs @@ -9,7 +9,7 @@ import Operation from "../Operation"; import OperationError from "../errors/OperationError.mjs"; import { ColossusComputer } from "../lib/Colossus.mjs"; -import { SWITCHES } from "../lib/Lorenz.mjs"; +import { SWITCHES, VALID_ITA2 } from "../lib/Lorenz.mjs"; /** * Colossus operation @@ -87,7 +87,7 @@ class Colossus extends Operation { { name: "Program to run", type: "option", - value: ["", "Letter Count", "1+2=. (1+2 Break In, Find X1,X2)", "4=3=/1=2 (Given X1,X2 find X4,X5)", "/,5,U (Count chars to find X3)"] + value: ["", "Letter Count", "1+2=. (1+2 Break In, Find X1,X2)", "4=5=/1=2 (Given X1,X2 find X4,X5)", "/,5,U (Count chars to find X3)"] }, { name: "K Rack: Conditional", @@ -347,6 +347,16 @@ class Colossus extends Operation { */ run(input, args) { + input = input.toUpperCase(); + for (const character of input) { + if (VALID_ITA2.indexOf(character) === -1) { + let errltr = character; + if (errltr==="\n") errltr = "Carriage Return"; + if (errltr===" ") errltr = "Space"; + throw new OperationError("Invalid ITA2 character : "+errltr); + } + } + const pattern = args[1]; const qbusin = { "Z": args[2], @@ -475,7 +485,7 @@ class Colossus extends Operation { } // 4=3=/1=2 : Find X4 & X5 where X1 & X2 are known - if (progname === "4=3=/1=2 (Given X1,X2 find X4,X5)") { + if (progname === "4=5=/1=2 (Given X1,X2 find X4,X5)") { // Set Conditional R1 : Match NOT ..?.. into counter 1 args[9] = "."; args[10] = "."; From b88a35cd1447dfd2d4ee7c326c7d54067636e180 Mon Sep 17 00:00:00 2001 From: VirtualColossus Date: Wed, 4 Dec 2019 14:28:53 +0000 Subject: [PATCH 07/10] Added P5 limitation --- src/core/lib/Colossus.mjs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/core/lib/Colossus.mjs b/src/core/lib/Colossus.mjs index 93ff8de5..59ece9e5 100644 --- a/src/core/lib/Colossus.mjs +++ b/src/core/lib/Colossus.mjs @@ -60,6 +60,7 @@ export class ColossusComputer { this.rotorPtrs = {}; this.totalmotor = 0; + this.P5Zbit = [0, 0]; } @@ -165,6 +166,10 @@ export class ColossusComputer { */ this.runQbusProcessingAddition(); + // Store Z bit impulse 5 two back required for P5 limitation + this.P5Zbit[1] = this.P5Zbit[0]; + this.P5Zbit[0] = this.ITAlookup[charZin].split("")[4]; + // Step rotors this.stepThyratrons(); @@ -184,14 +189,32 @@ export class ColossusComputer { let S1bPtr = this.Sptr[0]-1; if (S1bPtr===0) S1bPtr = ROTOR_SIZES.S1; + // Get Chi rotor 5 two back to calculate plaintext (Z+Chi+Psi=Plain) + let X5bPtr=this.Xptr[4]-1; + if (X5bPtr==0) X5bPtr=ROTOR_SIZES.X5; + X5bPtr=X5bPtr-1; + if (X5bPtr==0) X5bPtr=ROTOR_SIZES.X5; + // Get Psi rotor 5 two back to calculate plaintext (Z+Chi+Psi=Plain) + let S5bPtr=this.Sptr[4]-1; + if (S5bPtr==0) S5bPtr=ROTOR_SIZES.S5; + S5bPtr=S5bPtr-1; + if (S5bPtr==0) S5bPtr=ROTOR_SIZES.S5; + const x2sw = this.limitations.X2; const s1sw = this.limitations.S1; + const p5sw = this.limitations.P5; // Limitation calculations let lim=1; if (x2sw) lim = this.rings.X[2][X2bPtr-1]; - if (s1sw) { - lim = lim ^ this.rings.S[1][S1bPtr-1]; + if (s1sw) lim = lim ^ this.rings.S[1][S1bPtr-1]; + + // P5 + if (p5sw) { + let p5lim = this.P5Zbit[1]; + p5lim = p5lim ^ this.rings.X[5][X5bPtr-1]; + p5lim = p5lim ^ this.rings.S[5][S5bPtr-1]; + lim = lim ^ p5lim; } // console.log(this.Mptr); From ccdd2af8be5e7b0ae4404872cd0a4970cc374806 Mon Sep 17 00:00:00 2001 From: VirtualColossus Date: Wed, 4 Dec 2019 22:43:22 +0000 Subject: [PATCH 08/10] Added tests, removed debug --- src/core/config/Categories.json | 3 +- src/core/lib/Colossus.mjs | 77 ++++++++++++-------------------- src/core/operations/Colossus.mjs | 9 +--- tests/operations/index.mjs | 1 + 4 files changed, 34 insertions(+), 56 deletions(-) diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json index f663e16d..d731815b 100755 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -110,7 +110,8 @@ "Bombe", "Multiple Bombe", "Typex", - "Lorenz" + "Lorenz", + "Colossus" ] }, { diff --git a/src/core/lib/Colossus.mjs b/src/core/lib/Colossus.mjs index 7fd67e2e..9301eb90 100644 --- a/src/core/lib/Colossus.mjs +++ b/src/core/lib/Colossus.mjs @@ -143,14 +143,11 @@ export class ColossusComputer { this.Xptr = [this.rotorPtrs.X1, this.rotorPtrs.X2, this.rotorPtrs.X3, this.rotorPtrs.X4, this.rotorPtrs.X5]; this.Mptr = [this.rotorPtrs.M37, this.rotorPtrs.M61]; this.Sptr = [this.rotorPtrs.S1, this.rotorPtrs.S2, this.rotorPtrs.S3, this.rotorPtrs.S4, this.rotorPtrs.S5]; - // console.log(this.Xptr); // Run full loop of all character on the input tape (Z) for (let i=0; i= 0 && Qswitch[s] !== parseInt(this.Qbits[s],10)) result = false; + if (Qswitch[s] >= 0 && Qswitch[s] !== parseInt(this.Qbits[s], 10)) result = false; } // Check for NOT switch if (row.Negate) result = !result; @@ -372,21 +339,21 @@ export class ColossusComputer { // Negate the whole column, this allows A OR B by doing NOT(NOT A AND NOT B) for (let c=0;c<5;c++) { if (this.qbusswitches.condNegateAll && cnt[c] !== -1) cnt[c] = !cnt[c]; - - if (this.qbusswitches.totalMotor === "" || (this.qbusswitches.totalMotor === "x" && this.totalmotor === 0) || (this.qbusswitches.totalMotor === "." && this.totalmotor === 1)) { - if (cnt[c] === true) this.allCounters[c]++; - } - } + return cnt; + } /** * Addition of impulses Q bus section */ - runQbusProcessingAddition() { + runQbusProcessingAddition(cnt) { const row = this.qbusswitches.addition[0]; const Qswitch = row.Qswitches.slice(); + + // To save making the arguments of this operation any larger, limiting addition counter to first one only + // Colossus could actually add into any of the five counters. if (row.C1) { let addition = 0; for (let s=0;s<5;s++) { @@ -397,10 +364,24 @@ export class ColossusComputer { } const equals = (row.Equals===""?-1:(row.Equals==="."?0:1)); if (addition === equals) { - this.allCounters[0]++; + // AND with conditional rows to get final result + if (cnt[0] === -1) cnt[0] = true; + } else { + cnt[0] = false; } } - // console.log("counter1="+this.allCounters[0]); + + // Final check, check for addition section negate + // then, if any column set, from top to bottom of rack, add to counter. + for (let c=0;c<5;c++) { + if (this.qbusswitches.addNegateAll && cnt[c] !== -1) cnt[c] = !cnt[c]; + + if (this.qbusswitches.totalMotor === "" || (this.qbusswitches.totalMotor === "x" && this.totalmotor === 0) || (this.qbusswitches.totalMotor === "." && this.totalmotor === 1)) { + if (cnt[c] === true) this.allCounters[c]++; + } + + } + } /** diff --git a/src/core/operations/Colossus.mjs b/src/core/operations/Colossus.mjs index 896252dd..260616b2 100644 --- a/src/core/operations/Colossus.mjs +++ b/src/core/operations/Colossus.mjs @@ -17,13 +17,13 @@ import { SWITCHES, VALID_ITA2 } from "../lib/Lorenz.mjs"; class Colossus extends Operation { /** - * Lorenz constructor + * Colossus constructor */ constructor() { super(); this.name = "Colossus"; this.module = "Bletchley"; - this.description = "Colossus ... "; + this.description = "Colossus is the name of the world's first electronic computer. Ten computers were designed by Tommy Flowers and built at the Post Office Research Labs at Dollis Hill in 1943 during World War 2. They assisted with the breaking of the German Lorenz cipher attachment, a machine created to encipher communications between Hitler and his generals on the front lines.

To learn more, Virtual Colossus, an online, browser based simulation of a Colossus computer is available at https://virtualcolossus.co.uk.

A more detailed description of this operation can be found here."; this.infoURL = "https://wikipedia.org/wiki/Colossus_computer"; this.inputType = "string"; this.outputType = "JSON"; @@ -438,8 +438,6 @@ class Colossus extends Operation { const colossus = new ColossusComputer(input, pattern, qbusin, qbusswitches, control, starts, settotal, limit); const result = colossus.run(); - console.log(result); - return result; } @@ -553,9 +551,6 @@ class Colossus extends Operation { * @returns {html} */ present(output) { - console.log("output="+ typeof(output)); - console.log("counters="+ typeof(output.counters)); - let html = "Colossus Printer\n\n"; html += output.printout + "\n\n"; html += "Colossus Counters\n\n"; diff --git a/tests/operations/index.mjs b/tests/operations/index.mjs index c54fa7ef..8c80ff99 100644 --- a/tests/operations/index.mjs +++ b/tests/operations/index.mjs @@ -93,6 +93,7 @@ import "./tests/DefangIP.mjs"; import "./tests/ParseUDP.mjs"; import "./tests/AvroToJSON.mjs"; import "./tests/Lorenz.mjs"; +import "./tests/Colossus.mjs"; // Cannot test operations that use the File type yet From 9f901188afdeb48395c2a83f43a9eeee1f06bfa2 Mon Sep 17 00:00:00 2001 From: VirtualColossus Date: Wed, 4 Dec 2019 23:02:20 +0000 Subject: [PATCH 09/10] Added Colossus test --- tests/operations/tests/Colossus.mjs | 91 +++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tests/operations/tests/Colossus.mjs diff --git a/tests/operations/tests/Colossus.mjs b/tests/operations/tests/Colossus.mjs new file mode 100644 index 00000000..f63fdf27 --- /dev/null +++ b/tests/operations/tests/Colossus.mjs @@ -0,0 +1,91 @@ +/** + * Colossus tests. + * @author VirtualColossus [martin@virtualcolossus.co.uk] + * @copyright Crown Copyright 2019 + * @license Apache-2.0 + */ +import TestRegister from "../../lib/TestRegister.mjs"; + +TestRegister.addTests([ + { + name: "Colossus Letter Count", + input: "CTBKJUVXHZ-H3L4QV+YEZUK+SXOZ/N", + expectedMatch: /00 00 : a30/, + recipeConfig: [ + { + "op": "Colossus", + "args": [ + "", + "KH Pattern", + "Z", "", "", + "None", "Select Program", "Letter Count", + "", + "", "", "", "", "", false, "", + "", "", "", "", "", false, "", + "", "", "", "", "", false, "", + false, + "", + false, false, false, false, false, + "", false, false, "", + "", + 0, "", "", + "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1" + ] + } + ] + }, + { + name: "Colossus 1+2=.", + input: "CTBKJUVXHZ-H3L4QV+YEZUK+SXOZ/NNLH+WBFSBMJM-E3LMTPYJ.ZJDYI3TZZFVRP+REWQYOQMU3FNW.T4WB3IEPCJ-A3LWVRSZZECNGQVUFHO.R/3VZRF.Y4XEDGXZJ3RS34ARLZDZTUHMG+HH//Y+E+C-NE+--GEATU+EPEVLQEMKCLCZP-HX3C3O+CRH4D-RLIVOLHJGNI./MN4JDB/PRYZV3QOD34DAGO4+/TCS+CU-ODXMRHPPCCCD-MWHJO/TRPAELREIFVVLABSDMQORF4THY.UQTITEPYXAZ3DPNI/I+.UPTCBT-BJ/PEQFZA/PQ4+Z4-IPLBG4COART/YC4CJL+ERNVTRSHOKNSSLGFJ+QJR/ITYHWFQCPXCY.Z.X/VKTAR.LBXQK4JI/P+YDEM/LPBLK.CX/..QHBSOAO-FHJORYVBHQEYTF3/I-WZ4J.EYCYTEMG3DY3W/4VSE3/XAR3JEX4/3/LI4V/IAVLTODE-4HPLWUWMC.YEJOVFZ+/4EAIJXUT+G/.KYQF4DSVSIPLWZE.XTZWD4E.EYI/.MBJ+SVX/GBW/4RTNSGT-TF-+-JO3UE/3ZVEQKYVCUR+-3OMC+YU+UGMBCOO4.GRHVG.3+ZFB4C3J+QWCR+DHKQ3XFTUKTBGVXEQ.PCU4XLW-G+RJODDYLIJVSXOJUGKTVNBGMPH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MWXKNOFXMS.RUK+A4NFJAFYEKE.AZWXJNCP3BTFOA+ZUL.RHTX-SV4LPY+VOCHEPQDFWQFIAKYG+U4YDK.EPZPTQGHGTJZTBGW4GVFSYG4XJ-C.WWPGRKXHTUFWR/VSCEZO.ZQKVJCDMFMXG+NG-BFVK.-+THEUAHA.UDPW.MDCIR/FHJXNDSRWPYBNV-CQU-.W/AVAEGJQ3IO.-.E/FCBFXDNDA3/YIUKM-QVR3CDYGHKRZGQJZYDOE43PKPKK/4JMU+U.VBSCPMFCQ.ZQMONNHQSGBUUEGHBNQ+KYV.NKEDDZ4I43GIXJSQWKKPISSXRZPH-.KQUEN3/+FWYATQUQXOXENY/MSWZFZMLFSZ4KMUPO/CIPCTSLGETRI.LLG/LJJ.TRR+QCYSXQEWZXMO.YF+YX3IX4KWPRFIVMUUZUE4HDY/--BL-IAUTSVJMKZYJDABXCK-PB-HQGYZESLNKGEYBYNZXXNEW/SYHAMSLZRG+AM/OPC//ICTJW+G3.WB+DAGFURHVRLHQA4AOV4ZZ/JUFMVEOYPBUDF3U3KJZN.EBTHGJAFAMZDUQEHGRANOUXXBNKXV4IUO+LYNT.LID.K4WMYCHBWSOKAZ3HHWO.SUT3CDWS+4R4D+EIYMOCPCIB+.4LRFDQZY+Y/VBIYXO3KT/K-PUOFP/Q3.+ZYXT3LAJHW+DGFZPYRTJYSTFVMLEWL-.S3FNSXX3PGB+.+M/GQHZJQ/K/VZTKMVK/SF3CBSRVLFVCHLZKJWCNFANACX+JQLIN4O4Y4WMYSLGXT43RHFK.+HIJ+4EJQBGPPOHGSB+C3KABZKXTU+P/WDFTWMAURUDLK+PWC4M4TQ.Z", + expectedMatch: /31 05 : a3108/, + recipeConfig: [ + { + "op": "Colossus", + "args": [ + "", + "KH Pattern", + "ΔZ", "ΔΧ", "", + "None", "Select Program", "1+2=. (1+2 Break In, Find X1,X2)", + "", + "", "", "", "", "", false, "", + "", "", "", "", "", false, "", + "", "", "", "", "", false, "", + false, + "", + false, false, false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QVR3CDYGHKRZGQJZYDOE43PKPKK/4JMU+U.VBSCPMFCQ.ZQMONNHQSGBUUEGHBNQ+KYV.NKEDDZ4I43GIXJSQWKKPISSXRZPH-.KQUEN3/+FWYATQUQXOXENY/MSWZFZMLFSZ4KMUPO/CIPCTSLGETRI.LLG/LJJ.TRR+QCYSXQEWZXMO.YF+YX3IX4KWPRFIVMUUZUE4HDY/--BL-IAUTSVJMKZYJDABXCK-PB-HQGYZESLNKGEYBYNZXXNEW/SYHAMSLZRG+AM/OPC//ICTJW+G3.WB+DAGFURHVRLHQA4AOV4ZZ/JUFMVEOYPBUDF3U3KJZN.EBTHGJAFAMZDUQEHGRANOUXXBNKXV4IUO+LYNT.LID.K4WMYCHBWSOKAZ3HHWO.SUT3CDWS+4R4D+EIYMOCPCIB+.4LRFDQZY+Y/VBIYXO3KT/K-PUOFP/Q3.+ZYXT3LAJHW+DGFZPYRTJYSTFVMLEWL-.S3FNSXX3PGB+.+M/GQHZJQ/K/VZTKMVK/SF3CBSRVLFVCHLZKJWCNFANACX+JQLIN4O4Y4WMYSLGXT43RHFK.+HIJ+4EJQBGPPOHGSB+C3KABZKXTU+P/WDFTWMAURUDLK+PWC4M4TQ.Z", + expectedMatch: /15 08 : a969/, + recipeConfig: [ + { + "op": "Colossus", + "args": [ + "", + "KH Pattern", + "ΔZ", "ΔΧ", "", + "None", "Select Program", "4=5=/1=2 (Given X1,X2 find X4,X5)", + "", + "", "", "", "", "", false, "", + "", "", "", "", "", false, "", + "", "", "", "", "", false, "", + false, + "", + false, false, false, false, false, + "", false, false, "", + "", + 960, "X4", "X5", + "31", "5", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1" + ] + } + ] + }, +]); From 24fd35e6af320ad32e4cef7d1c03b2de4502caf4 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Fri, 6 Mar 2020 13:05:08 +0000 Subject: [PATCH 10/10] Tidied up Colossus operation --- src/core/lib/Colossus.mjs | 30 +++++------------------------- src/core/lib/Lorenz.mjs | 2 +- src/core/operations/Colossus.mjs | 23 +++++++++++++---------- src/core/operations/Lorenz.mjs | 2 +- 4 files changed, 20 insertions(+), 37 deletions(-) diff --git a/src/core/lib/Colossus.mjs b/src/core/lib/Colossus.mjs index 9301eb90..5fb8e0cc 100644 --- a/src/core/lib/Colossus.mjs +++ b/src/core/lib/Colossus.mjs @@ -1,7 +1,7 @@ /** * Colossus - an emulation of the world's first electronic computer * - * @author VirtualColossus + * @author VirtualColossus [martin@virtualcolossus.co.uk] * @copyright Crown Copyright 2019 * @license Apache-2.0 */ @@ -22,7 +22,6 @@ export class ColossusComputer { * @param {Object} starts - rotor start positions */ constructor(ciphertext, pattern, qbusin, qbusswitches, control, starts, settotal, limit) { - this.ITAlookup = ITA2_TABLE; this.ReverseITAlookup = {}; for (const letter in this.ITAlookup) { @@ -61,15 +60,14 @@ export class ColossusComputer { this.totalmotor = 0; this.P5Zbit = [0, 0]; - } /** * Begin a run - * @returns {object} - + * + * @returns {object} */ run() { - const result = { printout: "" }; @@ -86,7 +84,6 @@ export class ColossusComputer { result.printout += fast + " " + slow + "\n"; do { - this.allCounters = [0, 0, 0, 0, 0]; this.ZbitsOneBack = [0, 0, 0, 0, 0]; this.XbitsOneBack = [0, 0, 0, 0, 0]; @@ -97,8 +94,8 @@ export class ColossusComputer { // Only print result if larger than set total let fastRef = "00"; let slowRef = "00"; - if (fast !== "") fastRef = this.leftPad(this.rotorPtrs[fast], 2); - if (slow !== "") slowRef = this.leftPad(this.rotorPtrs[slow], 2); + if (fast !== "") fastRef = this.rotorPtrs[fast].toString().padStart(2, "0"); + if (slow !== "") slowRef = this.rotorPtrs[slow].toString().padStart(2, "0"); let printline = ""; for (let c=0;c<5;c++) { if (this.allCounters[c] > this.settotal) { @@ -124,7 +121,6 @@ export class ColossusComputer { } runcount++; - } while (JSON.stringify(this.rotorPtrs) !== JSON.stringify(this.starts)); result.counters = this.allCounters; @@ -137,7 +133,6 @@ export class ColossusComputer { * Run tape loop */ runTape() { - let charZin = ""; this.Xptr = [this.rotorPtrs.X1, this.rotorPtrs.X2, this.rotorPtrs.X3, this.rotorPtrs.X4, this.rotorPtrs.X5]; @@ -171,7 +166,6 @@ export class ColossusComputer { this.stepThyratrons(); } - } /** @@ -246,7 +240,6 @@ export class ColossusComputer { // Always move M61 rotor this.Mptr[1]++; if (this.Mptr[1] > ROTOR_SIZES.M61) this.Mptr[1]=1; - } /** @@ -342,7 +335,6 @@ export class ColossusComputer { } return cnt; - } /** @@ -381,7 +373,6 @@ export class ColossusComputer { } } - } /** @@ -411,17 +402,6 @@ export class ColossusComputer { }; } - /** - * Left Pad number - */ - leftPad(number, targetLength) { - let output = number + ""; - while (output.length < targetLength) { - output = "0" + output; - } - return output; - } - /** * Read argument bus switches X & . and convert to 1 & 0 */ diff --git a/src/core/lib/Lorenz.mjs b/src/core/lib/Lorenz.mjs index 916b470c..1d336cef 100644 --- a/src/core/lib/Lorenz.mjs +++ b/src/core/lib/Lorenz.mjs @@ -1,7 +1,7 @@ /** * Resources required by the Lorenz SZ40/42 and Colossus * - * @author VirtualColossus + * @author VirtualColossus [martin@virtualcolossus.co.uk] * @copyright Crown Copyright 2019 * @license Apache-2.0 */ diff --git a/src/core/operations/Colossus.mjs b/src/core/operations/Colossus.mjs index 260616b2..6d92b000 100644 --- a/src/core/operations/Colossus.mjs +++ b/src/core/operations/Colossus.mjs @@ -23,7 +23,7 @@ class Colossus extends Operation { super(); this.name = "Colossus"; this.module = "Bletchley"; - this.description = "Colossus is the name of the world's first electronic computer. Ten computers were designed by Tommy Flowers and built at the Post Office Research Labs at Dollis Hill in 1943 during World War 2. They assisted with the breaking of the German Lorenz cipher attachment, a machine created to encipher communications between Hitler and his generals on the front lines.

To learn more, Virtual Colossus, an online, browser based simulation of a Colossus computer is available at https://virtualcolossus.co.uk.

A more detailed description of this operation can be found here."; + this.description = "Colossus is the name of the world's first electronic computer. Ten Colossi were designed by Tommy Flowers and built at the Post Office Research Labs at Dollis Hill in 1943 during World War 2. They assisted with the breaking of the German Lorenz cipher attachment, a machine created to encipher communications between Hitler and his generals on the front lines.

To learn more, Virtual Colossus, an online, browser based simulation of a Colossus computer is available at virtualcolossus.co.uk.

A more detailed description of this operation can be found here."; this.infoURL = "https://wikipedia.org/wiki/Colossus_computer"; this.inputType = "string"; this.outputType = "JSON"; @@ -61,7 +61,7 @@ class Colossus extends Operation { { name: "K Rack Option", type: "argSelector", - "value": [ + value: [ { name: "Select Program", on: [7], @@ -346,14 +346,13 @@ class Colossus extends Operation { * @returns {Object} */ run(input, args) { - input = input.toUpperCase(); for (const character of input) { if (VALID_ITA2.indexOf(character) === -1) { let errltr = character; - if (errltr==="\n") errltr = "Carriage Return"; - if (errltr===" ") errltr = "Space"; - throw new OperationError("Invalid ITA2 character : "+errltr); + if (errltr === "\n") errltr = "Carriage Return"; + if (errltr === " ") errltr = "Space"; + throw new OperationError("Invalid ITA2 character : " + errltr); } } @@ -383,7 +382,8 @@ class Colossus extends Operation { const re = new RegExp("^$|^[.x]$"); for (let qr=0;qr<3;qr++) { for (let a=0;a<5;a++) { - if (!re.test(args[((qr*7)+(a+9))])) throw new OperationError("Switch R"+(qr+1)+"-Q"+(a+1)+" can only be set to blank, . or x"); + if (!re.test(args[((qr*7)+(a+9))])) + throw new OperationError("Switch R"+(qr+1)+"-Q"+(a+1)+" can only be set to blank, . or x"); } } @@ -406,7 +406,8 @@ class Colossus extends Operation { }; const settotal = parseInt(args[42], 10); - if (settotal < 0 || settotal > 9999) throw new OperationError("Set Total must be between 0000 and 9999"); + if (settotal < 0 || settotal > 9999) + throw new OperationError("Set Total must be between 0000 and 9999"); // null|fast|slow for each of S1-5,M1-2,X1-5 const control = { @@ -415,7 +416,6 @@ class Colossus extends Operation { }; // Start positions - if (args[52]<1 || args[52]>43) throw new OperationError("Ψ1 start must be between 1 and 43"); if (args[53]<1 || args[53]>47) throw new OperationError("Ψ2 start must be between 1 and 47"); if (args[54]<1 || args[54]>51) throw new OperationError("Ψ3 start must be between 1 and 51"); @@ -439,11 +439,14 @@ class Colossus extends Operation { const result = colossus.run(); return result; - } /** * Select Program + * + * @param {string} progname + * @param {Object[]} args + * @returns {Object[]} */ selectProgram(progname, args) { diff --git a/src/core/operations/Lorenz.mjs b/src/core/operations/Lorenz.mjs index adff5ded..e1446543 100644 --- a/src/core/operations/Lorenz.mjs +++ b/src/core/operations/Lorenz.mjs @@ -22,7 +22,7 @@ class Lorenz extends Operation { this.name = "Lorenz"; this.module = "Bletchley"; - this.description = "The Lorenz SZ40/42 cipher attachment was a WW2 German rotor cipher machine with twelve rotors which attached in-line between remote teleprinters.

It used the Vernam cipher with two groups of five rotors (named the psi(ψ) wheels and chi(χ) wheels at Bletchley Park) to create two pseudorandom streams of five bits, encoded in ITA2, which were XOR added to the plaintext. Two other rotors, dubbed the mu(μ) or motor wheels, could hold up the stepping of the psi wheels meaning they stepped intermittently.

Each rotor has a different number of cams/lugs around their circumference which could be set active or inactive changing the key stream.

Three models of the Lorenz are emulated, SZ40, SZ42a and SZ42b and three example wheel patterns (the lug settings) are included (KH, ZMUG & BREAM) with the option to set a custom set using the letter 'x' for active or '.' for an inactive lug.

The input can either be plaintext or ITA2 when sending and ITA2 when receiving.

To learn more, Virtual Lorenz, an online, browser based simulation of the Lorenz SZ40/42 is available at https://lorenz.virtualcolossus.co.uk.

A more detailed description of this operation can be found here."; + this.description = "The Lorenz SZ40/42 cipher attachment was a WW2 German rotor cipher machine with twelve rotors which attached in-line between remote teleprinters.

It used the Vernam cipher with two groups of five rotors (named the psi(ψ) wheels and chi(χ) wheels at Bletchley Park) to create two pseudorandom streams of five bits, encoded in ITA2, which were XOR added to the plaintext. Two other rotors, dubbed the mu(μ) or motor wheels, could hold up the stepping of the psi wheels meaning they stepped intermittently.

Each rotor has a different number of cams/lugs around their circumference which could be set active or inactive changing the key stream.

Three models of the Lorenz are emulated, SZ40, SZ42a and SZ42b and three example wheel patterns (the lug settings) are included (KH, ZMUG & BREAM) with the option to set a custom set using the letter 'x' for active or '.' for an inactive lug.

The input can either be plaintext or ITA2 when sending and ITA2 when receiving.

To learn more, Virtual Lorenz, an online, browser based simulation of the Lorenz SZ40/42 is available at lorenz.virtualcolossus.co.uk.

A more detailed description of this operation can be found here."; this.infoURL = "https://wikipedia.org/wiki/Lorenz_cipher"; this.inputType = "string"; this.outputType = "string";