mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 07:16:17 -04:00
Added Total Motor, fixed bug in printout
This commit is contained in:
parent
32625dc0b0
commit
820bd2f867
2 changed files with 46 additions and 15 deletions
|
@ -61,6 +61,8 @@ export class ColossusComputer {
|
||||||
|
|
||||||
this.rotorPtrs = {};
|
this.rotorPtrs = {};
|
||||||
|
|
||||||
|
this.totalmotor = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -98,13 +100,17 @@ export class ColossusComputer {
|
||||||
var slowRef = "00";
|
var slowRef = "00";
|
||||||
if (fast !== "") fastRef = this.leftPad(this.rotorPtrs[fast],2);
|
if (fast !== "") fastRef = this.leftPad(this.rotorPtrs[fast],2);
|
||||||
if (slow !== "") slowRef = this.leftPad(this.rotorPtrs[slow],2);
|
if (slow !== "") slowRef = this.leftPad(this.rotorPtrs[slow],2);
|
||||||
result.printout += fastRef + " " + slowRef + " : ";
|
var printline = '';
|
||||||
for (let c=0;c<5;c++) {
|
for (let c=0;c<5;c++) {
|
||||||
if (this.allCounters[c] > this.settotal) {
|
if (this.allCounters[c] > this.settotal) {
|
||||||
result.printout += String.fromCharCode(c+97) + this.allCounters[c]+" ";
|
printline += String.fromCharCode(c+97) + this.allCounters[c]+" ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (printline !== "") {
|
||||||
|
result.printout += fastRef + " " + slowRef + " : ";
|
||||||
|
result.printout += printline;
|
||||||
result.printout += "\n";
|
result.printout += "\n";
|
||||||
|
}
|
||||||
|
|
||||||
// Step fast rotor if required
|
// Step fast rotor if required
|
||||||
if (fast != '') {
|
if (fast != '') {
|
||||||
|
@ -193,17 +199,17 @@ export class ColossusComputer {
|
||||||
//console.log(this.Mptr);
|
//console.log(this.Mptr);
|
||||||
//console.log(this.rings.M[2]);
|
//console.log(this.rings.M[2]);
|
||||||
const basicmotor = this.rings.M[2][this.Mptr[0]-1];
|
const basicmotor = this.rings.M[2][this.Mptr[0]-1];
|
||||||
let totalmotor = basicmotor;
|
this.totalmotor = basicmotor;
|
||||||
|
|
||||||
if (x2sw || s1sw) {
|
if (x2sw || s1sw) {
|
||||||
if (basicmotor===0 && lim===1) {
|
if (basicmotor===0 && lim===1) {
|
||||||
totalmotor = 0;
|
this.totalmotor = 0;
|
||||||
} else {
|
} else {
|
||||||
totalmotor = 1;
|
this.totalmotor = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//console.log('BM='+basicmotor+', TM='+totalmotor);
|
//console.log('BM='+basicmotor+', TM='+this.totalmotor);
|
||||||
|
|
||||||
// Step Chi rotors
|
// Step Chi rotors
|
||||||
for (let r=0; r<5; r++) {
|
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 (this.Xptr[r] > ROTOR_SIZES["X"+(r+1)]) this.Xptr[r] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (totalmotor) {
|
if (this.totalmotor) {
|
||||||
//console.log('step Psi');
|
//console.log('step Psi');
|
||||||
// Step Psi rotors
|
// Step Psi rotors
|
||||||
for (let r=0; r<5; r++) {
|
for (let r=0; r<5; r++) {
|
||||||
|
@ -346,11 +352,14 @@ export class ColossusComputer {
|
||||||
for (let c=0;c<5;c++) {
|
for (let c=0;c<5;c++) {
|
||||||
if (this.qbusswitches.condNegateAll) cnt[c] = !cnt[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 (cnt[c]==1) this.allCounters[c]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Addition of impulses Q bus section
|
* Addition of impulses Q bus section
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -87,7 +87,7 @@ class Colossus extends Operation {
|
||||||
{
|
{
|
||||||
name: "Program to run",
|
name: "Program to run",
|
||||||
type: "option",
|
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",
|
name: "K Rack: Conditional",
|
||||||
|
@ -241,7 +241,8 @@ class Colossus extends Operation {
|
||||||
{
|
{
|
||||||
name: "Add-Equals",
|
name: "Add-Equals",
|
||||||
type: "editableOptionShort",
|
type: "editableOptionShort",
|
||||||
value: SWITCHES
|
value: SWITCHES,
|
||||||
|
defaultIndex: 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Add-Counter1",
|
name: "Add-Counter1",
|
||||||
|
@ -253,7 +254,9 @@ class Colossus extends Operation {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Total Motor",
|
name: "Total Motor",
|
||||||
type: "boolean"
|
type: "editableOptionShort",
|
||||||
|
value: SWITCHES,
|
||||||
|
defaultIndex: 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Master Control Panel",
|
name: "Master Control Panel",
|
||||||
|
@ -411,8 +414,27 @@ class Colossus extends Operation {
|
||||||
*/
|
*/
|
||||||
selectProgram(progname, args) {
|
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
|
// 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
|
// Clear any other counters
|
||||||
args[15] = ""; // Conditional R1
|
args[15] = ""; // Conditional R1
|
||||||
args[22] = ""; // Conditional R2
|
args[22] = ""; // Conditional R2
|
||||||
|
@ -428,7 +450,7 @@ class Colossus extends Operation {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4=3=/1=2 : Find X4 & X5 where X1 & X2 are known
|
// 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
|
// Set Conditional R1 : Match NOT ..?.. into counter 1
|
||||||
args[9] = ".";
|
args[9] = ".";
|
||||||
args[10] = ".";
|
args[10] = ".";
|
||||||
|
@ -454,7 +476,7 @@ class Colossus extends Operation {
|
||||||
}
|
}
|
||||||
|
|
||||||
// /,5,U : Count number of matches of /, 5 & U to find X3
|
// /,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
|
// Set Conditional R1 : Match / char, ITA2 = ..... into counter 1
|
||||||
args[9] = ".";
|
args[9] = ".";
|
||||||
args[10] = ".";
|
args[10] = ".";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue