mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 07:16:17 -04:00
Fixed grunt lint errors
This commit is contained in:
parent
5d01b06877
commit
938385c18b
2 changed files with 322 additions and 335 deletions
|
@ -85,10 +85,9 @@ export class SigabaMachine{
|
||||||
*/
|
*/
|
||||||
encryptLetter(letter) {
|
encryptLetter(letter) {
|
||||||
letter = convToUpperCase(letter);
|
letter = convToUpperCase(letter);
|
||||||
if (letter == " "){
|
if (letter === " ") {
|
||||||
letter = "Z";
|
letter = "Z";
|
||||||
}
|
} else if (letter === "Z") {
|
||||||
else if (letter == "Z") {
|
|
||||||
letter = "X";
|
letter = "X";
|
||||||
}
|
}
|
||||||
const encryptedLetter = this.cipherBank.encrypt(letter);
|
const encryptedLetter = this.cipherBank.encrypt(letter);
|
||||||
|
@ -105,7 +104,7 @@ export class SigabaMachine{
|
||||||
decryptLetter(letter) {
|
decryptLetter(letter) {
|
||||||
letter = convToUpperCase(letter);
|
letter = convToUpperCase(letter);
|
||||||
let decryptedLetter = this.cipherBank.decrypt(letter);
|
let decryptedLetter = this.cipherBank.decrypt(letter);
|
||||||
if (decryptedLetter == "Z"){
|
if (decryptedLetter === "Z") {
|
||||||
decryptedLetter = " ";
|
decryptedLetter = " ";
|
||||||
}
|
}
|
||||||
this.step();
|
this.step();
|
||||||
|
@ -162,7 +161,7 @@ export class CipherBank{
|
||||||
@returns {char}
|
@returns {char}
|
||||||
*/
|
*/
|
||||||
encrypt(inputPos) {
|
encrypt(inputPos) {
|
||||||
for (let rotor of this.rotors){
|
for (const rotor of this.rotors) {
|
||||||
inputPos = rotor.crypt(inputPos, "leftToRight");
|
inputPos = rotor.crypt(inputPos, "leftToRight");
|
||||||
}
|
}
|
||||||
return inputPos;
|
return inputPos;
|
||||||
|
@ -176,7 +175,7 @@ export class CipherBank{
|
||||||
*/
|
*/
|
||||||
decrypt(inputPos) {
|
decrypt(inputPos) {
|
||||||
const revOrderedRotors = [...this.rotors].reverse();
|
const revOrderedRotors = [...this.rotors].reverse();
|
||||||
for (let rotor of revOrderedRotors){
|
for (const rotor of revOrderedRotors) {
|
||||||
inputPos = rotor.crypt(inputPos, "rightToLeft");
|
inputPos = rotor.crypt(inputPos, "rightToLeft");
|
||||||
}
|
}
|
||||||
return inputPos;
|
return inputPos;
|
||||||
|
@ -189,7 +188,7 @@ export class CipherBank{
|
||||||
*/
|
*/
|
||||||
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]};
|
||||||
let rotorsToMove = [];
|
const rotorsToMove = [];
|
||||||
for (const key in logicDict) {
|
for (const key in logicDict) {
|
||||||
const item = logicDict[key];
|
const item = logicDict[key];
|
||||||
for (const i of indexInputs) {
|
for (const i of indexInputs) {
|
||||||
|
@ -199,7 +198,7 @@ export class CipherBank{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let rotor of rotorsToMove){
|
for (const rotor of rotorsToMove) {
|
||||||
rotor.step();
|
rotor.step();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -227,7 +226,7 @@ export class ControlBank{
|
||||||
@returns {char}
|
@returns {char}
|
||||||
*/
|
*/
|
||||||
crypt(inputPos) {
|
crypt(inputPos) {
|
||||||
for (let rotor of this.rotors){
|
for (const rotor of this.rotors) {
|
||||||
inputPos = rotor.crypt(inputPos, "rightToLeft");
|
inputPos = rotor.crypt(inputPos, "rightToLeft");
|
||||||
}
|
}
|
||||||
return inputPos;
|
return inputPos;
|
||||||
|
@ -241,10 +240,10 @@ export class ControlBank{
|
||||||
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")];
|
||||||
const logicDict = {1: "B", 2: "C", 3: "DE", 4: "FGH", 5: "IJK", 6: "LMNO", 7: "PQRST", 8: "UVWXYZ", 9: "A"};
|
const logicDict = {1: "B", 2: "C", 3: "DE", 4: "FGH", 5: "IJK", 6: "LMNO", 7: "PQRST", 8: "UVWXYZ", 9: "A"};
|
||||||
let numberOutputs = [];
|
const numberOutputs = [];
|
||||||
for (let key in logicDict){
|
for (const key in logicDict) {
|
||||||
const item = logicDict[key];
|
const item = logicDict[key];
|
||||||
for (let output of outputs){
|
for (const output of outputs) {
|
||||||
if (item.includes(output)) {
|
if (item.includes(output)) {
|
||||||
numberOutputs.push(key);
|
numberOutputs.push(key);
|
||||||
break;
|
break;
|
||||||
|
@ -261,10 +260,10 @@ export class ControlBank{
|
||||||
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];
|
||||||
this.numberOfMoves ++;
|
this.numberOfMoves ++;
|
||||||
FRotor.step();
|
FRotor.step();
|
||||||
if (this.numberOfMoves%26 == 0){
|
if (this.numberOfMoves%26 === 0) {
|
||||||
MRotor.step();
|
MRotor.step();
|
||||||
}
|
}
|
||||||
if (this.numberOfMoves%(26*26) == 0){
|
if (this.numberOfMoves%(26*26) === 0) {
|
||||||
SRotor.step();
|
SRotor.step();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -302,7 +301,7 @@ export class IndexBank{
|
||||||
@returns {number}
|
@returns {number}
|
||||||
*/
|
*/
|
||||||
crypt(inputPos) {
|
crypt(inputPos) {
|
||||||
for (let rotor of this.rotors){
|
for (const rotor of this.rotors) {
|
||||||
inputPos = rotor.crypt(inputPos);
|
inputPos = rotor.crypt(inputPos);
|
||||||
}
|
}
|
||||||
return inputPos;
|
return inputPos;
|
||||||
|
@ -315,7 +314,7 @@ export class IndexBank{
|
||||||
@returns {number[]}
|
@returns {number[]}
|
||||||
*/
|
*/
|
||||||
goThroughIndex(controlInputs) {
|
goThroughIndex(controlInputs) {
|
||||||
let outputs = [];
|
const outputs = [];
|
||||||
for (const inp of controlInputs) {
|
for (const inp of controlInputs) {
|
||||||
outputs.push(this.crypt(inp));
|
outputs.push(this.crypt(inp));
|
||||||
}
|
}
|
||||||
|
@ -349,12 +348,11 @@ export class Rotor{
|
||||||
@returns {number[]}
|
@returns {number[]}
|
||||||
*/
|
*/
|
||||||
getNumMapping(wireSetting, rev) {
|
getNumMapping(wireSetting, rev) {
|
||||||
if (rev==false){
|
if (rev===false) {
|
||||||
return wireSetting;
|
return wireSetting;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
const length = wireSetting.length;
|
const length = wireSetting.length;
|
||||||
let tempMapping = new Array(length);
|
const tempMapping = new Array(length);
|
||||||
for (let i=0; i<length; i++) {
|
for (let i=0; i<length; i++) {
|
||||||
tempMapping[wireSetting[i]] = i;
|
tempMapping[wireSetting[i]] = i;
|
||||||
}
|
}
|
||||||
|
@ -370,8 +368,8 @@ export class Rotor{
|
||||||
*/
|
*/
|
||||||
getPosMapping(rev) {
|
getPosMapping(rev) {
|
||||||
const length = this.numMapping.length;
|
const length = this.numMapping.length;
|
||||||
let posMapping = [];
|
const posMapping = [];
|
||||||
if (rev==false){
|
if (rev===false) {
|
||||||
for (let i = this.state; i < this.state+length; i++) {
|
for (let i = this.state; i < this.state+length; i++) {
|
||||||
let res = i%length;
|
let res = i%length;
|
||||||
if (res<0) {
|
if (res<0) {
|
||||||
|
@ -379,8 +377,7 @@ export class Rotor{
|
||||||
}
|
}
|
||||||
posMapping.push(res);
|
posMapping.push(res);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
for (let i = this.state; i > this.state-length; i--) {
|
for (let i = this.state; i > this.state-length; i--) {
|
||||||
let res = i%length;
|
let res = i%length;
|
||||||
if (res<0) {
|
if (res<0) {
|
||||||
|
@ -401,11 +398,10 @@ export class Rotor{
|
||||||
*/
|
*/
|
||||||
cryptNum(inputPos, direction) {
|
cryptNum(inputPos, direction) {
|
||||||
const inpNum = this.posMapping[inputPos];
|
const inpNum = this.posMapping[inputPos];
|
||||||
var outNum;
|
let outNum;
|
||||||
if (direction == "leftToRight"){
|
if (direction === "leftToRight") {
|
||||||
outNum = this.numMapping[inpNum];
|
outNum = this.numMapping[inpNum];
|
||||||
}
|
} else if (direction === "rightToLeft") {
|
||||||
else if (direction == "rightToLeft") {
|
|
||||||
outNum = this.numMapping.indexOf(inpNum);
|
outNum = this.numMapping.indexOf(inpNum);
|
||||||
}
|
}
|
||||||
const outPos = this.posMapping.indexOf(outNum);
|
const outPos = this.posMapping.indexOf(outNum);
|
||||||
|
|
|
@ -7,7 +7,6 @@ Emulation of the SIGABA machine.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
import OperationError from "../errors/OperationError.mjs";
|
|
||||||
import {LETTERS} from "../lib/Enigma.mjs";
|
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";
|
||||||
|
|
||||||
|
@ -252,40 +251,32 @@ this.module = "SIGABA";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@param {string} rotor - rotor wirings
|
@param {string} input
|
||||||
|
@param {Object[]} args
|
||||||
@returns {string}
|
@returns {string}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
parseRotorStr(rotor){
|
|
||||||
if (rotor === ""){
|
|
||||||
throw new OperationError(`All rotor wirings must be provided.`);
|
|
||||||
}
|
|
||||||
return rotor;
|
|
||||||
}
|
|
||||||
|
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const sigabaSwitch = args[40];
|
const sigabaSwitch = args[40];
|
||||||
const cipherRotors = [];
|
const cipherRotors = [];
|
||||||
const controlRotors = [];
|
const controlRotors = [];
|
||||||
const indexRotors = [];
|
const indexRotors = [];
|
||||||
for (let i=0; i<5; i++) {
|
for (let i=0; i<5; i++) {
|
||||||
const rotorWiring = this.parseRotorStr(args[i*3]);
|
const rotorWiring = args[i*3];
|
||||||
cipherRotors.push(new CRRotor(rotorWiring, args[i*3+2], args[i*3+1]));
|
cipherRotors.push(new CRRotor(rotorWiring, args[i*3+2], args[i*3+1]));
|
||||||
}
|
}
|
||||||
for (let i=5; i<10; i++) {
|
for (let i=5; i<10; i++) {
|
||||||
const rotorWiring = this.parseRotorStr(args[i*3]);
|
const rotorWiring = args[i*3];
|
||||||
controlRotors.push(new CRRotor(rotorWiring, args[i*3+2], args[i*3+1]));
|
controlRotors.push(new CRRotor(rotorWiring, args[i*3+2], args[i*3+1]));
|
||||||
}
|
}
|
||||||
for (let i=15; i<20; i++) {
|
for (let i=15; i<20; i++) {
|
||||||
const rotorWiring = this.parseRotorStr(args[i*2]);
|
const rotorWiring = args[i*2];
|
||||||
indexRotors.push(new IRotor(rotorWiring, args[i*2+1]));
|
indexRotors.push(new IRotor(rotorWiring, args[i*2+1]));
|
||||||
}
|
}
|
||||||
const sigaba = new SigabaMachine(cipherRotors, controlRotors, indexRotors);
|
const sigaba = new SigabaMachine(cipherRotors, controlRotors, indexRotors);
|
||||||
var result;
|
let result;
|
||||||
if (sigabaSwitch === "Encrypt") {
|
if (sigabaSwitch === "Encrypt") {
|
||||||
result = sigaba.encrypt(input);
|
result = sigaba.encrypt(input);
|
||||||
}
|
} else if (sigabaSwitch === "Decrypt") {
|
||||||
else if (sigabaSwitch === "Decrypt") {
|
|
||||||
result = sigaba.decrypt(input);
|
result = sigaba.decrypt(input);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue