mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Added operation description note and modified comment formatting
This commit is contained in:
parent
3c68ad1302
commit
88947b9d42
3 changed files with 193 additions and 188 deletions
|
@ -1,15 +1,14 @@
|
||||||
/**
|
/**
|
||||||
Emulation of the SIGABA machine
|
* Emulation of the SIGABA machine
|
||||||
|
*
|
||||||
@author hettysymes
|
* @author hettysymes
|
||||||
@copyright hettysymes 2020
|
* @copyright hettysymes 2020
|
||||||
@license Apache-2.0
|
* @license Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
A set of randomised example SIGABA cipher/control rotors (these rotors are interchangeable). Cipher and control rotors can be referred to as C and R rotors respectively.
|
* A set of randomised example SIGABA cipher/control rotors (these rotors are interchangeable). Cipher and control rotors can be referred to as C and R rotors respectively.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const CR_ROTORS = [
|
export const CR_ROTORS = [
|
||||||
{name: "Example 1", value: "SRGWANHPJZFXVIDQCEUKBYOLMT"},
|
{name: "Example 1", value: "SRGWANHPJZFXVIDQCEUKBYOLMT"},
|
||||||
{name: "Example 2", value: "THQEFSAZVKJYULBODCPXNIMWRG"},
|
{name: "Example 2", value: "THQEFSAZVKJYULBODCPXNIMWRG"},
|
||||||
|
@ -24,9 +23,8 @@ export const CR_ROTORS = [
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
A set of randomised example SIGABA index rotors (may be referred to as I rotors).
|
* A set of randomised example SIGABA index rotors (may be referred to as I rotors).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const I_ROTORS = [
|
export const I_ROTORS = [
|
||||||
{name: "Example 1", value: "6201348957"},
|
{name: "Example 1", value: "6201348957"},
|
||||||
{name: "Example 2", value: "6147253089"},
|
{name: "Example 2", value: "6147253089"},
|
||||||
|
@ -38,10 +36,10 @@ export const I_ROTORS = [
|
||||||
export const NUMBERS = "0123456789".split("");
|
export const NUMBERS = "0123456789".split("");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Converts a letter to uppercase (if it already isn't)
|
* Converts a letter to uppercase (if it already isn't)
|
||||||
|
*
|
||||||
@param {char} letter - letter to convert to upper case
|
* @param {char} letter - letter to convert to uppercase
|
||||||
@returns {char}
|
* @returns {char}
|
||||||
*/
|
*/
|
||||||
export function convToUpperCase(letter) {
|
export function convToUpperCase(letter) {
|
||||||
const charCode = letter.charCodeAt();
|
const charCode = letter.charCodeAt();
|
||||||
|
@ -52,15 +50,16 @@ export function convToUpperCase(letter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The SIGABA machine consisting of the 3 rotor banks: cipher, control and index banks.
|
* The SIGABA machine consisting of the 3 rotor banks: cipher, control and index banks.
|
||||||
*/
|
*/
|
||||||
export class SigabaMachine {
|
export class SigabaMachine {
|
||||||
/**
|
|
||||||
SigabaMachine constructor
|
|
||||||
|
|
||||||
@param {Object[]} cipherRotors - list of CRRotors
|
/**
|
||||||
@param {Object[]} controlRotors - list of CRRotors
|
* SigabaMachine constructor
|
||||||
@param {object[]} indexRotors - list of IRotors
|
*
|
||||||
|
* @param {Object[]} cipherRotors - list of CRRotors
|
||||||
|
* @param {Object[]} controlRotors - list of CRRotors
|
||||||
|
* @param {object[]} indexRotors - list of IRotors
|
||||||
*/
|
*/
|
||||||
constructor(cipherRotors, controlRotors, indexRotors) {
|
constructor(cipherRotors, controlRotors, indexRotors) {
|
||||||
this.cipherBank = new CipherBank(cipherRotors);
|
this.cipherBank = new CipherBank(cipherRotors);
|
||||||
|
@ -69,7 +68,7 @@ export class SigabaMachine {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Steps all the correct rotors in the machine.
|
* Steps all the correct rotors in the machine.
|
||||||
*/
|
*/
|
||||||
step() {
|
step() {
|
||||||
const controlOut = this.controlBank.goThroughControl();
|
const controlOut = this.controlBank.goThroughControl();
|
||||||
|
@ -78,10 +77,10 @@ export class SigabaMachine {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Encrypts a letter. A space is converted to a "Z" before encryption, and a "Z" is converted to an "X". This allows spaces to be encrypted.
|
* Encrypts a letter. A space is converted to a "Z" before encryption, and a "Z" is converted to an "X". This allows spaces to be encrypted.
|
||||||
|
*
|
||||||
@param {char} letter - letter to encrypt
|
* @param {char} letter - letter to encrypt
|
||||||
@returns {char}
|
* @returns {char}
|
||||||
*/
|
*/
|
||||||
encryptLetter(letter) {
|
encryptLetter(letter) {
|
||||||
letter = convToUpperCase(letter);
|
letter = convToUpperCase(letter);
|
||||||
|
@ -96,10 +95,10 @@ export class SigabaMachine {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Decrypts a letter. A letter decrypted as a "Z" is converted to a space before it is output, since spaces are converted to "Z"s before encryption.
|
* Decrypts a letter. A letter decrypted as a "Z" is converted to a space before it is output, since spaces are converted to "Z"s before encryption.
|
||||||
|
*
|
||||||
@param {char} letter - letter to decrypt
|
* @param {char} letter - letter to decrypt
|
||||||
@returns {char}
|
* @returns {char}
|
||||||
*/
|
*/
|
||||||
decryptLetter(letter) {
|
decryptLetter(letter) {
|
||||||
letter = convToUpperCase(letter);
|
letter = convToUpperCase(letter);
|
||||||
|
@ -112,10 +111,10 @@ export class SigabaMachine {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Encrypts a message of one or more letters
|
* Encrypts a message of one or more letters
|
||||||
|
*
|
||||||
@param {string} msg - message to encrypt
|
* @param {string} msg - message to encrypt
|
||||||
@returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
encrypt(msg) {
|
encrypt(msg) {
|
||||||
let ciphertext = "";
|
let ciphertext = "";
|
||||||
|
@ -126,10 +125,10 @@ export class SigabaMachine {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Decrypts a message of one or more letters
|
* Decrypts a message of one or more letters
|
||||||
|
*
|
||||||
@param {string} msg - message to decrypt
|
* @param {string} msg - message to decrypt
|
||||||
@returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
decrypt(msg) {
|
decrypt(msg) {
|
||||||
let plaintext = "";
|
let plaintext = "";
|
||||||
|
@ -142,23 +141,24 @@ export class SigabaMachine {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The cipher rotor bank consists of 5 cipher rotors in either a forward or reversed orientation.
|
* The cipher rotor bank consists of 5 cipher rotors in either a forward or reversed orientation.
|
||||||
*/
|
*/
|
||||||
export class CipherBank {
|
export class CipherBank {
|
||||||
/**
|
|
||||||
CipherBank constructor
|
|
||||||
|
|
||||||
@param {Object[]} rotors - list of CRRotors
|
/**
|
||||||
|
* CipherBank constructor
|
||||||
|
*
|
||||||
|
* @param {Object[]} rotors - list of CRRotors
|
||||||
*/
|
*/
|
||||||
constructor(rotors) {
|
constructor(rotors) {
|
||||||
this.rotors = rotors;
|
this.rotors = rotors;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Encrypts a letter through the cipher rotors (signal goes from left-to-right)
|
* Encrypts a letter through the cipher rotors (signal goes from left-to-right)
|
||||||
|
*
|
||||||
@param {char} inputPos - the input position of the signal (letter to be encrypted)
|
* @param {char} inputPos - the input position of the signal (letter to be encrypted)
|
||||||
@returns {char}
|
* @returns {char}
|
||||||
*/
|
*/
|
||||||
encrypt(inputPos) {
|
encrypt(inputPos) {
|
||||||
for (const rotor of this.rotors) {
|
for (const rotor of this.rotors) {
|
||||||
|
@ -168,10 +168,10 @@ export class CipherBank {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Decrypts a letter through the cipher rotors (signal goes from right-to-left)
|
* Decrypts a letter through the cipher rotors (signal goes from right-to-left)
|
||||||
|
*
|
||||||
@param {char} inputPos - the input position of the signal (letter to be decrypted)
|
* @param {char} inputPos - the input position of the signal (letter to be decrypted)
|
||||||
@returns {char}
|
* @returns {char}
|
||||||
*/
|
*/
|
||||||
decrypt(inputPos) {
|
decrypt(inputPos) {
|
||||||
const revOrderedRotors = [...this.rotors].reverse();
|
const revOrderedRotors = [...this.rotors].reverse();
|
||||||
|
@ -182,9 +182,9 @@ export class CipherBank {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Step the cipher rotors forward according to the inputs from the index rotors
|
* Step the cipher rotors forward according to the inputs from the index rotors
|
||||||
|
*
|
||||||
@param {number[]} indexInputs - the inputs from the index rotors
|
* @param {number[]} indexInputs - the inputs from the index rotors
|
||||||
*/
|
*/
|
||||||
step(indexInputs) {
|
step(indexInputs) {
|
||||||
const logicDict = {0: [0, 9], 1: [7, 8], 2: [5, 6], 3: [3, 4], 4: [1, 2]};
|
const logicDict = {0: [0, 9], 1: [7, 8], 2: [5, 6], 3: [3, 4], 4: [1, 2]};
|
||||||
|
@ -206,23 +206,24 @@ export class CipherBank {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The control rotor bank consists of 5 control rotors in either a forward or reversed orientation. Signals to the control rotor bank always go from right-to-left.
|
* The control rotor bank consists of 5 control rotors in either a forward or reversed orientation. Signals to the control rotor bank always go from right-to-left.
|
||||||
*/
|
*/
|
||||||
export class ControlBank {
|
export class ControlBank {
|
||||||
/**
|
|
||||||
ControlBank constructor. The rotors have been reversed as signals go from right-to-left through the control rotors.
|
|
||||||
|
|
||||||
@param {Object[]} rotors - list of CRRotors
|
/**
|
||||||
|
* ControlBank constructor. The rotors have been reversed as signals go from right-to-left through the control rotors.
|
||||||
|
*
|
||||||
|
* @param {Object[]} rotors - list of CRRotors
|
||||||
*/
|
*/
|
||||||
constructor(rotors) {
|
constructor(rotors) {
|
||||||
this.rotors = [...rotors].reverse();
|
this.rotors = [...rotors].reverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Encrypts a letter.
|
* Encrypts a letter.
|
||||||
|
*
|
||||||
@param {char} inputPos - the input position of the signal
|
* @param {char} inputPos - the input position of the signal
|
||||||
@returns {char}
|
* @returns {char}
|
||||||
*/
|
*/
|
||||||
crypt(inputPos) {
|
crypt(inputPos) {
|
||||||
for (const rotor of this.rotors) {
|
for (const rotor of this.rotors) {
|
||||||
|
@ -232,9 +233,9 @@ export class ControlBank {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Gets the outputs of the control rotors. The inputs to the control rotors are always "F", "G", "H" and "I".
|
* Gets the outputs of the control rotors. The inputs to the control rotors are always "F", "G", "H" and "I".
|
||||||
|
*
|
||||||
@returns {number[]}
|
* @returns {number[]}
|
||||||
*/
|
*/
|
||||||
getOutputs() {
|
getOutputs() {
|
||||||
const outputs = [this.crypt("F"), this.crypt("G"), this.crypt("H"), this.crypt("I")];
|
const outputs = [this.crypt("F"), this.crypt("G"), this.crypt("H"), this.crypt("I")];
|
||||||
|
@ -253,7 +254,7 @@ export class ControlBank {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Steps the control rotors. Only 3 of the control rotors step: one after every encryption, one after every 26, and one after every 26 squared.
|
* Steps the control rotors. Only 3 of the control rotors step: one after every encryption, one after every 26, and one after every 26 squared.
|
||||||
*/
|
*/
|
||||||
step() {
|
step() {
|
||||||
const MRotor = this.rotors[1], FRotor = this.rotors[2], SRotor = this.rotors[3];
|
const MRotor = this.rotors[1], FRotor = this.rotors[2], SRotor = this.rotors[3];
|
||||||
|
@ -268,9 +269,9 @@ export class ControlBank {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The goThroughControl function combines getting the outputs from the control rotor bank and then stepping them.
|
* The goThroughControl function combines getting the outputs from the control rotor bank and then stepping them.
|
||||||
|
*
|
||||||
@returns {number[]}
|
* @returns {number[]}
|
||||||
*/
|
*/
|
||||||
goThroughControl() {
|
goThroughControl() {
|
||||||
const outputs = this.getOutputs();
|
const outputs = this.getOutputs();
|
||||||
|
@ -281,23 +282,24 @@ export class ControlBank {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The index rotor bank consists of 5 index rotors all placed in the forwards orientation.
|
* The index rotor bank consists of 5 index rotors all placed in the forwards orientation.
|
||||||
*/
|
*/
|
||||||
export class IndexBank {
|
export class IndexBank {
|
||||||
/**
|
|
||||||
IndexBank constructor
|
|
||||||
|
|
||||||
@param {Object[]} rotors - list of IRotors
|
/**
|
||||||
|
* IndexBank constructor
|
||||||
|
*
|
||||||
|
* @param {Object[]} rotors - list of IRotors
|
||||||
*/
|
*/
|
||||||
constructor(rotors) {
|
constructor(rotors) {
|
||||||
this.rotors = rotors;
|
this.rotors = rotors;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Encrypts a number.
|
* Encrypts a number.
|
||||||
|
*
|
||||||
@param {number} inputPos - the input position of the signal
|
* @param {number} inputPos - the input position of the signal
|
||||||
@returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
crypt(inputPos) {
|
crypt(inputPos) {
|
||||||
for (const rotor of this.rotors) {
|
for (const rotor of this.rotors) {
|
||||||
|
@ -307,10 +309,10 @@ export class IndexBank {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The goThroughIndex function takes the inputs from the control rotor bank and returns the list of outputs after encryption through the index rotors.
|
* The goThroughIndex function takes the inputs from the control rotor bank and returns the list of outputs after encryption through the index rotors.
|
||||||
|
*
|
||||||
@param {number[]} - inputs from the control rotors
|
* @param {number[]} controlInputs - inputs from the control rotors
|
||||||
@returns {number[]}
|
* @returns {number[]}
|
||||||
*/
|
*/
|
||||||
goThroughIndex(controlInputs) {
|
goThroughIndex(controlInputs) {
|
||||||
const outputs = [];
|
const outputs = [];
|
||||||
|
@ -323,15 +325,16 @@ export class IndexBank {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Rotor class
|
* Rotor class
|
||||||
*/
|
*/
|
||||||
export class Rotor {
|
export class Rotor {
|
||||||
/**
|
|
||||||
Rotor constructor
|
|
||||||
|
|
||||||
@param {number[]} wireSetting - the wirings within the rotor: mapping from left-to-right, the index of the number in the list maps onto the number at that index
|
/**
|
||||||
@param {bool} rev - true if the rotor is reversed, false if it isn't
|
* Rotor constructor
|
||||||
@param {number} key - the starting position or state of the rotor
|
*
|
||||||
|
* @param {number[]} wireSetting - the wirings within the rotor: mapping from left-to-right, the index of the number in the list maps onto the number at that index
|
||||||
|
* @param {bool} rev - true if the rotor is reversed, false if it isn't
|
||||||
|
* @param {number} key - the starting position or state of the rotor
|
||||||
*/
|
*/
|
||||||
constructor(wireSetting, key, rev) {
|
constructor(wireSetting, key, rev) {
|
||||||
this.state = key;
|
this.state = key;
|
||||||
|
@ -340,11 +343,11 @@ export class Rotor {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Get the number mapping from the wireSetting (only different from wireSetting if rotor is reversed)
|
* Get the number mapping from the wireSetting (only different from wireSetting if rotor is reversed)
|
||||||
|
*
|
||||||
@param {number[]} wireSetting - the wirings within the rotors
|
* @param {number[]} wireSetting - the wirings within the rotors
|
||||||
@param {bool} rev - true if reversed, false if not
|
* @param {bool} rev - true if reversed, false if not
|
||||||
@returns {number[]}
|
* @returns {number[]}
|
||||||
*/
|
*/
|
||||||
getNumMapping(wireSetting, rev) {
|
getNumMapping(wireSetting, rev) {
|
||||||
if (rev===false) {
|
if (rev===false) {
|
||||||
|
@ -360,10 +363,10 @@ export class Rotor {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Get the position mapping (how the position numbers map onto the numbers of the rotor)
|
* Get the position mapping (how the position numbers map onto the numbers of the rotor)
|
||||||
|
*
|
||||||
@param {bool} rev - true if reversed, false if not
|
* @param {bool} rev - true if reversed, false if not
|
||||||
@returns {number[]}
|
* @returns {number[]}
|
||||||
*/
|
*/
|
||||||
getPosMapping(rev) {
|
getPosMapping(rev) {
|
||||||
const length = this.numMapping.length;
|
const length = this.numMapping.length;
|
||||||
|
@ -389,11 +392,11 @@ export class Rotor {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Encrypt/decrypt data. This process is identical to the rotors of cipher machines such as Enigma or Typex.
|
* Encrypt/decrypt data. This process is identical to the rotors of cipher machines such as Enigma or Typex.
|
||||||
|
*
|
||||||
@param {number} inputPos - the input position of the signal (the data to encrypt/decrypt)
|
* @param {number} inputPos - the input position of the signal (the data to encrypt/decrypt)
|
||||||
@param {string} direction - one of "leftToRight" and "rightToLeft", states the direction in which the signal passes through the rotor
|
* @param {string} direction - one of "leftToRight" and "rightToLeft", states the direction in which the signal passes through the rotor
|
||||||
@returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
cryptNum(inputPos, direction) {
|
cryptNum(inputPos, direction) {
|
||||||
const inpNum = this.posMapping[inputPos];
|
const inpNum = this.posMapping[inputPos];
|
||||||
|
@ -408,7 +411,7 @@ export class Rotor {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Steps the rotor. The number at position 0 will be moved to position 1 etc.
|
* Steps the rotor. The number at position 0 will be moved to position 1 etc.
|
||||||
*/
|
*/
|
||||||
step() {
|
step() {
|
||||||
const lastNum = this.posMapping.pop();
|
const lastNum = this.posMapping.pop();
|
||||||
|
@ -419,16 +422,16 @@ export class Rotor {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
A CRRotor is a cipher (C) or control (R) rotor. These rotors are identical and interchangeable. A C or R rotor consists of 26 contacts, one for each letter, and may be put into either a forwards of reversed orientation.
|
* A CRRotor is a cipher (C) or control (R) rotor. These rotors are identical and interchangeable. A C or R rotor consists of 26 contacts, one for each letter, and may be put into either a forwards of reversed orientation.
|
||||||
*/
|
*/
|
||||||
export class CRRotor extends Rotor {
|
export class CRRotor extends Rotor {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
CRRotor constructor
|
* CRRotor constructor
|
||||||
|
*
|
||||||
@param {string} wireSetting - the rotor wirings (string of letters)
|
* @param {string} wireSetting - the rotor wirings (string of letters)
|
||||||
@param {char} key - initial state of rotor
|
* @param {char} key - initial state of rotor
|
||||||
@param {bool} rev - true if reversed, false if not
|
* @param {bool} rev - true if reversed, false if not
|
||||||
*/
|
*/
|
||||||
constructor(wireSetting, key, rev=false) {
|
constructor(wireSetting, key, rev=false) {
|
||||||
wireSetting = wireSetting.split("").map(CRRotor.letterToNum);
|
wireSetting = wireSetting.split("").map(CRRotor.letterToNum);
|
||||||
|
@ -436,31 +439,31 @@ export class CRRotor extends Rotor {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Static function which converts a letter into its number i.e. its offset from the letter "A"
|
* Static function which converts a letter into its number i.e. its offset from the letter "A"
|
||||||
|
*
|
||||||
@param {char} letter - letter to convert to number
|
* @param {char} letter - letter to convert to number
|
||||||
@returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
static letterToNum(letter) {
|
static letterToNum(letter) {
|
||||||
return letter.charCodeAt()-65;
|
return letter.charCodeAt()-65;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Static function which converts a number (a letter's offset from "A") into its letter
|
* Static function which converts a number (a letter's offset from "A") into its letter
|
||||||
|
*
|
||||||
@param {number} num - number to convert to letter
|
* @param {number} num - number to convert to letter
|
||||||
@returns {char}
|
* @returns {char}
|
||||||
*/
|
*/
|
||||||
static numToLetter(num) {
|
static numToLetter(num) {
|
||||||
return String.fromCharCode(num+65);
|
return String.fromCharCode(num+65);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Encrypts/decrypts a letter.
|
* Encrypts/decrypts a letter.
|
||||||
|
*
|
||||||
@param {char} inputPos - the input position of the signal ("A" refers to position 0 etc.)
|
* @param {char} inputPos - the input position of the signal ("A" refers to position 0 etc.)
|
||||||
@param {string} direction - one of "leftToRight" and "rightToLeft"
|
* @param {string} direction - one of "leftToRight" and "rightToLeft"
|
||||||
@returns {char}
|
* @returns {char}
|
||||||
*/
|
*/
|
||||||
crypt(inputPos, direction) {
|
crypt(inputPos, direction) {
|
||||||
inputPos = CRRotor.letterToNum(inputPos);
|
inputPos = CRRotor.letterToNum(inputPos);
|
||||||
|
@ -471,14 +474,15 @@ export class CRRotor extends Rotor {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
An IRotor is an index rotor, which consists of 10 contacts each numbered from 0 to 9. Unlike C and R rotors, they cannot be put in the reversed orientation. The index rotors do not step at any point during encryption or decryption.
|
* An IRotor is an index rotor, which consists of 10 contacts each numbered from 0 to 9. Unlike C and R rotors, they cannot be put in the reversed orientation. The index rotors do not step at any point during encryption or decryption.
|
||||||
*/
|
*/
|
||||||
export class IRotor extends Rotor {
|
export class IRotor extends Rotor {
|
||||||
/**
|
|
||||||
IRotor constructor
|
|
||||||
|
|
||||||
@param {string} wireSetting - the rotor wirings (string of numbers)
|
/**
|
||||||
@param {char} key - initial state of rotor
|
* IRotor constructor
|
||||||
|
*
|
||||||
|
* @param {string} wireSetting - the rotor wirings (string of numbers)
|
||||||
|
* @param {char} key - initial state of rotor
|
||||||
*/
|
*/
|
||||||
constructor(wireSetting, key) {
|
constructor(wireSetting, key) {
|
||||||
wireSetting = wireSetting.split("").map(Number);
|
wireSetting = wireSetting.split("").map(Number);
|
||||||
|
@ -486,10 +490,10 @@ export class IRotor extends Rotor {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Encrypts a number
|
* Encrypts a number
|
||||||
|
*
|
||||||
@param {number} inputPos - the input position of the signal
|
* @param {number} inputPos - the input position of the signal
|
||||||
@returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
crypt(inputPos) {
|
crypt(inputPos) {
|
||||||
return this.cryptNum(inputPos, "leftToRight");
|
return this.cryptNum(inputPos, "leftToRight");
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
/**
|
/**
|
||||||
Emulation of the SIGABA machine.
|
* Emulation of the SIGABA machine.
|
||||||
|
*
|
||||||
@author hettysymes
|
* @author hettysymes
|
||||||
@copyright hettysymes 2020
|
* @copyright hettysymes 2020
|
||||||
@license Apache-2.0
|
* @license Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
|
@ -11,18 +11,19 @@ import {LETTERS} from "../lib/Enigma.mjs";
|
||||||
import {NUMBERS, CR_ROTORS, I_ROTORS, SigabaMachine, CRRotor, IRotor} from "../lib/SIGABA.mjs";
|
import {NUMBERS, CR_ROTORS, I_ROTORS, SigabaMachine, CRRotor, IRotor} from "../lib/SIGABA.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Sigaba operation
|
* Sigaba operation
|
||||||
*/
|
*/
|
||||||
class Sigaba extends Operation {
|
class Sigaba extends Operation {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Sigaba constructor
|
* Sigaba constructor
|
||||||
*/
|
*/
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.name = "SIGABA";
|
this.name = "SIGABA";
|
||||||
this.module = "SIGABA";
|
this.module = "SIGABA";
|
||||||
this.description = "Encipher/decipher with the WW2 SIGABA machine. <br><br>SIGABA, otherwise known as ECM Mark II, was used by the United States for message encryption during WW2 up to the 1950s. It was developed in the 1930s by the US Army and Navy, and has up to this day never been broken. Consisting of 15 rotors: 5 cipher rotors and 10 rotors (5 control rotors and 5 index rotors) controlling the stepping of the cipher rotors, the rotor stepping for SIGABA is much more complex than other rotor machines of its time, such as Enigma. All example rotor wirings are random example sets.<br><br>To configure rotor wirings, for the cipher and control rotors enter a string of letters which map from A to Z, and for the index rotors enter a sequence of numbers which map from 0 to 9. Note that encryption is not the same as decryption, so first choose the desired mode.";
|
this.description = "Encipher/decipher with the WW2 SIGABA machine. <br><br>SIGABA, otherwise known as ECM Mark II, was used by the United States for message encryption during WW2 up to the 1950s. It was developed in the 1930s by the US Army and Navy, and has up to this day never been broken. Consisting of 15 rotors: 5 cipher rotors and 10 rotors (5 control rotors and 5 index rotors) controlling the stepping of the cipher rotors, the rotor stepping for SIGABA is much more complex than other rotor machines of its time, such as Enigma. All example rotor wirings are random example sets.<br><br>To configure rotor wirings, for the cipher and control rotors enter a string of letters which map from A to Z, and for the index rotors enter a sequence of numbers which map from 0 to 9. Note that encryption is not the same as decryption, so first choose the desired mode. <br><br> Note: Whilst this has been tested against other software emulators, it has not been tested against hardware.";
|
||||||
this.infoURL = "https://en.wikipedia.org/wiki/SIGABA";
|
this.infoURL = "https://en.wikipedia.org/wiki/SIGABA";
|
||||||
this.inputType = "string";
|
this.inputType = "string";
|
||||||
this.outputType = "string";
|
this.outputType = "string";
|
||||||
|
@ -251,9 +252,9 @@ class Sigaba extends Operation {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@param {string} input
|
* @param {string} input
|
||||||
@param {Object[]} args
|
* @param {Object[]} args
|
||||||
@returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const sigabaSwitch = args[40];
|
const sigabaSwitch = args[40];
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
/**
|
/**
|
||||||
SIGABA machine tests
|
* SIGABA machine tests
|
||||||
|
*
|
||||||
@author hettysymes
|
* @author hettysymes
|
||||||
@copyright hettysymes 2020
|
* @copyright hettysymes 2020
|
||||||
@license Apache-2.0
|
* @license Apache-2.0
|
||||||
*/
|
*/
|
||||||
import TestRegister from "../../lib/TestRegister.mjs";
|
import TestRegister from "../../lib/TestRegister.mjs";
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue