mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-23 08:16:17 -04:00
Bombe: Add checking machine
This commit is contained in:
parent
78768e00d4
commit
21335e7d05
7 changed files with 178 additions and 66 deletions
|
@ -23,7 +23,7 @@ class Bombe extends Operation {
|
|||
|
||||
this.name = "Bombe";
|
||||
this.module = "Default";
|
||||
this.description = "Emulation of the Bombe machine used to attack Enigma.<br><br>To run this you need to have a 'crib', which is some known plaintext for a chunk of the target ciphertext, and know the rotors used. (See the 'Bombe (multiple runs)' operation if you don't know the rotors.) The machine will suggest possible configurations of the Enigma. Each suggestion has the rotor start positions (left to right) and one plugboard pair.<br><br>Choosing a crib: First, note that Enigma cannot encrypt a letter to itself, which allows you to rule out some positions for possible cribs. Secondly, the Bombe does not simulate the Enigma's middle rotor stepping. The longer your crib, the more likely a step happened within it, which will prevent the attack working. However, other than that, longer cribs are generally better. The attack produces a 'menu' which maps ciphertext letters to plaintext, and the goal is to produce 'loops': for example, with ciphertext ABC and crib CAB, we have the mappings A<->C, B<->A, and C<->B, which produces a loop A-B-C-A. The more loops, the better the crib. The operation will output this: if your menu has too few loops, a large number of incorrect outputs will be produced. Try a different crib. If the menu seems good but the right answer isn't produced, your crib may be wrong, or you may have overlapped the middle rotor stepping - try a different crib.<br><br>Output is not sufficient to fully decrypt the data. You will have to recover the rest of the plugboard settings by inspection. And the ring position is not taken into account: this affects when the middle rotor steps. If your output is correct for a bit, and then goes wrong, adjust the ring and start position on the right-hand rotor together until the output improves. If necessary, repeat for the middle rotor.";
|
||||
this.description = "Emulation of the Bombe machine used to attack Enigma.<br><br>To run this you need to have a 'crib', which is some known plaintext for a chunk of the target ciphertext, and know the rotors used. (See the 'Bombe (multiple runs)' operation if you don't know the rotors.) The machine will suggest possible configurations of the Enigma. Each suggestion has the rotor start positions (left to right) and known plugboard pairs.<br><br>Choosing a crib: First, note that Enigma cannot encrypt a letter to itself, which allows you to rule out some positions for possible cribs. Secondly, the Bombe does not simulate the Enigma's middle rotor stepping. The longer your crib, the more likely a step happened within it, which will prevent the attack working. However, other than that, longer cribs are generally better. The attack produces a 'menu' which maps ciphertext letters to plaintext, and the goal is to produce 'loops': for example, with ciphertext ABC and crib CAB, we have the mappings A<->C, B<->A, and C<->B, which produces a loop A-B-C-A. The more loops, the better the crib. The operation will output this: if your menu has too few loops, a large number of incorrect outputs will be produced. Try a different crib. If the menu seems good but the right answer isn't produced, your crib may be wrong, or you may have overlapped the middle rotor stepping - try a different crib.<br><br>Output is not sufficient to fully decrypt the data. You will have to recover the rest of the plugboard settings by inspection. And the ring position is not taken into account: this affects when the middle rotor steps. If your output is correct for a bit, and then goes wrong, adjust the ring and start position on the right-hand rotor together until the output improves. If necessary, repeat for the middle rotor.<br><br>By default this operation runs the checking machine, a manual process to verify the quality of Bombe stops, on each stop, discarding stops which fail. If you want to see how many times the hardware actually stops for a given input, disable the checking machine.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Bombe";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
|
@ -66,6 +66,11 @@ class Bombe extends Operation {
|
|||
name: "Crib offset",
|
||||
type: "number",
|
||||
value: 0
|
||||
},
|
||||
{
|
||||
name: "Use checking machine",
|
||||
type: "boolean",
|
||||
value: true
|
||||
}
|
||||
];
|
||||
}
|
||||
|
@ -90,6 +95,7 @@ class Bombe extends Operation {
|
|||
const reflectorstr = args[4];
|
||||
let crib = args[5];
|
||||
const offset = args[6];
|
||||
const check = args[7];
|
||||
const rotors = [];
|
||||
for (let i=0; i<4; i++) {
|
||||
if (i === 3 && args[i] === "") {
|
||||
|
@ -120,9 +126,9 @@ class Bombe extends Operation {
|
|||
} else {
|
||||
update = undefined;
|
||||
}
|
||||
const bombe = new BombeMachine(rotors, reflector, ciphertext, crib, update);
|
||||
const bombe = new BombeMachine(rotors, reflector, ciphertext, crib, check, update);
|
||||
const result = bombe.run();
|
||||
let msg = `Bombe run on menu with ${bombe.nLoops} loops (2+ desirable). Note: Rotor positions are listed left to right and start at the beginning of the crib, and ignore stepping and the ring setting. One stecker pair is determined. A decryption preview starting at the beginning of the crib and ignoring stepping is also provided. Results:\n`;
|
||||
let msg = `Bombe run on menu with ${bombe.nLoops} loops (2+ desirable). Note: Rotor positions are listed left to right and start at the beginning of the crib, and ignore stepping and the ring setting. Some plugboard settings are determined. A decryption preview starting at the beginning of the crib and ignoring stepping is also provided. Results:\n`;
|
||||
for (const [setting, stecker, decrypt] of result) {
|
||||
msg += `Stop: ${setting} (plugboard: ${stecker}): ${decrypt}\n`;
|
||||
}
|
||||
|
|
|
@ -163,6 +163,11 @@ class MultipleBombe extends Operation {
|
|||
name: "Crib offset",
|
||||
type: "number",
|
||||
value: 0
|
||||
},
|
||||
{
|
||||
name: "Use checking machine",
|
||||
type: "boolean",
|
||||
value: true
|
||||
}
|
||||
];
|
||||
}
|
||||
|
@ -211,7 +216,7 @@ class MultipleBombe extends Operation {
|
|||
const reflectorsStr = args[5];
|
||||
let crib = args[6];
|
||||
const offset = args[7];
|
||||
// TODO got this far
|
||||
const check = args[8];
|
||||
const rotors = [];
|
||||
const fourthRotors = [];
|
||||
const reflectors = [];
|
||||
|
@ -279,8 +284,8 @@ class MultipleBombe extends Operation {
|
|||
runRotors.push(rotor4);
|
||||
}
|
||||
if (bombe === undefined) {
|
||||
bombe = new BombeMachine(runRotors, reflector, ciphertext, crib);
|
||||
msg = `Bombe run on menu with ${bombe.nLoops} loops (2+ desirable). Note: Rotors and rotor positions are listed left to right, ignore stepping and the ring setting, and positions start at the beginning of the crib. One stecker pair is determined. A decryption preview starting at the beginning of the crib and ignoring stepping is also provided. Results:\n`;
|
||||
bombe = new BombeMachine(runRotors, reflector, ciphertext, crib, check);
|
||||
msg = `Bombe run on menu with ${bombe.nLoops} loops (2+ desirable). Note: Rotors and rotor positions are listed left to right, ignore stepping and the ring setting, and positions start at the beginning of the crib. Some plugboard settings are determined. A decryption preview starting at the beginning of the crib and ignoring stepping is also provided. Results:\n`;
|
||||
} else {
|
||||
bombe.changeRotors(runRotors, reflector);
|
||||
}
|
||||
|
@ -290,7 +295,7 @@ class MultipleBombe extends Operation {
|
|||
update(bombe.nLoops, nStops, nRuns / totalRuns);
|
||||
}
|
||||
if (result.length > 0) {
|
||||
msg += `Rotors: ${runRotors.join(", ")}\nReflector: ${reflector.pairs}\n`;
|
||||
msg += `\nRotors: ${runRotors.join(", ")}\nReflector: ${reflector.pairs}\n`;
|
||||
for (const [setting, stecker, decrypt] of result) {
|
||||
msg += `Stop: ${setting} (plugboard: ${stecker}): ${decrypt}\n`;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue