mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 23:06:16 -04:00
Merge branch 'master' of https://github.com/VirtualColossus/CyberChef
This commit is contained in:
commit
a387db6109
3 changed files with 21 additions and 9 deletions
|
@ -355,26 +355,26 @@ export class ColossusComputer {
|
||||||
const Qswitch = this.readBusSwitches(row.Qswitches);
|
const Qswitch = this.readBusSwitches(row.Qswitches);
|
||||||
// Match switches to bit pattern
|
// Match switches to bit pattern
|
||||||
for (let s=0;s<5;s++) {
|
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
|
// Check for NOT switch
|
||||||
if (row.Negate) result = !result;
|
if (row.Negate) result = !result;
|
||||||
|
|
||||||
// AND each row to get final result
|
// AND each row to get final result
|
||||||
if (cnt[cPnt] === -1) {
|
if (cnt[cPnt] === -1) {
|
||||||
cnt[cPnt] = (result?1:0);
|
cnt[cPnt] = result;
|
||||||
} else if (result === 0) {
|
} else if (!result) {
|
||||||
cnt[cPnt] = 0;
|
cnt[cPnt] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Negate the whole column, this allows A OR B by doing NOT(NOT A AND NOT B)
|
// Negate the whole column, this allows A OR B by doing NOT(NOT A AND NOT B)
|
||||||
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] !== -1) cnt[c] = !cnt[c];
|
||||||
|
|
||||||
if (this.qbusswitches.totalMotor === "" || (this.qbusswitches.totalMotor === "x" && this.totalmotor === 0) || (this.qbusswitches.totalMotor === "." && this.totalmotor === 1)) {
|
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]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@ export const SWITCHES = [
|
||||||
{name: "Down (x)", value: "x"}
|
{name: "Down (x)", value: "x"}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const VALID_ITA2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ34589+-./";
|
||||||
|
|
||||||
export const ITA2_TABLE = {
|
export const ITA2_TABLE = {
|
||||||
"A": "11000",
|
"A": "11000",
|
||||||
"B": "10011",
|
"B": "10011",
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError.mjs";
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
import { ColossusComputer } from "../lib/Colossus.mjs";
|
import { ColossusComputer } from "../lib/Colossus.mjs";
|
||||||
import { SWITCHES } from "../lib/Lorenz.mjs";
|
import { SWITCHES, VALID_ITA2 } from "../lib/Lorenz.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Colossus operation
|
* Colossus operation
|
||||||
|
@ -87,7 +87,7 @@ class Colossus extends Operation {
|
||||||
{
|
{
|
||||||
name: "Program to run",
|
name: "Program to run",
|
||||||
type: "option",
|
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",
|
name: "K Rack: Conditional",
|
||||||
|
@ -347,6 +347,16 @@ class Colossus extends Operation {
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
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 pattern = args[1];
|
||||||
const qbusin = {
|
const qbusin = {
|
||||||
"Z": args[2],
|
"Z": args[2],
|
||||||
|
@ -475,7 +485,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=5=/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] = ".";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue