Fixed grunt lint errors
This commit is contained in:
parent
5d01b06877
commit
938385c18b
@ -85,10 +85,9 @@ export class SigabaMachine{
|
||||
*/
|
||||
encryptLetter(letter) {
|
||||
letter = convToUpperCase(letter);
|
||||
if (letter == " "){
|
||||
if (letter === " ") {
|
||||
letter = "Z";
|
||||
}
|
||||
else if (letter == "Z") {
|
||||
} else if (letter === "Z") {
|
||||
letter = "X";
|
||||
}
|
||||
const encryptedLetter = this.cipherBank.encrypt(letter);
|
||||
@ -105,7 +104,7 @@ export class SigabaMachine{
|
||||
decryptLetter(letter) {
|
||||
letter = convToUpperCase(letter);
|
||||
let decryptedLetter = this.cipherBank.decrypt(letter);
|
||||
if (decryptedLetter == "Z"){
|
||||
if (decryptedLetter === "Z") {
|
||||
decryptedLetter = " ";
|
||||
}
|
||||
this.step();
|
||||
@ -162,7 +161,7 @@ export class CipherBank{
|
||||
@returns {char}
|
||||
*/
|
||||
encrypt(inputPos) {
|
||||
for (let rotor of this.rotors){
|
||||
for (const rotor of this.rotors) {
|
||||
inputPos = rotor.crypt(inputPos, "leftToRight");
|
||||
}
|
||||
return inputPos;
|
||||
@ -176,7 +175,7 @@ export class CipherBank{
|
||||
*/
|
||||
decrypt(inputPos) {
|
||||
const revOrderedRotors = [...this.rotors].reverse();
|
||||
for (let rotor of revOrderedRotors){
|
||||
for (const rotor of revOrderedRotors) {
|
||||
inputPos = rotor.crypt(inputPos, "rightToLeft");
|
||||
}
|
||||
return inputPos;
|
||||
@ -189,7 +188,7 @@ export class CipherBank{
|
||||
*/
|
||||
step(indexInputs) {
|
||||
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) {
|
||||
const item = logicDict[key];
|
||||
for (const i of indexInputs) {
|
||||
@ -199,7 +198,7 @@ export class CipherBank{
|
||||
}
|
||||
}
|
||||
}
|
||||
for (let rotor of rotorsToMove){
|
||||
for (const rotor of rotorsToMove) {
|
||||
rotor.step();
|
||||
}
|
||||
}
|
||||
@ -227,7 +226,7 @@ export class ControlBank{
|
||||
@returns {char}
|
||||
*/
|
||||
crypt(inputPos) {
|
||||
for (let rotor of this.rotors){
|
||||
for (const rotor of this.rotors) {
|
||||
inputPos = rotor.crypt(inputPos, "rightToLeft");
|
||||
}
|
||||
return inputPos;
|
||||
@ -241,10 +240,10 @@ export class ControlBank{
|
||||
getOutputs() {
|
||||
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"};
|
||||
let numberOutputs = [];
|
||||
for (let key in logicDict){
|
||||
const numberOutputs = [];
|
||||
for (const key in logicDict) {
|
||||
const item = logicDict[key];
|
||||
for (let output of outputs){
|
||||
for (const output of outputs) {
|
||||
if (item.includes(output)) {
|
||||
numberOutputs.push(key);
|
||||
break;
|
||||
@ -261,10 +260,10 @@ export class ControlBank{
|
||||
const MRotor = this.rotors[1], FRotor = this.rotors[2], SRotor = this.rotors[3];
|
||||
this.numberOfMoves ++;
|
||||
FRotor.step();
|
||||
if (this.numberOfMoves%26 == 0){
|
||||
if (this.numberOfMoves%26 === 0) {
|
||||
MRotor.step();
|
||||
}
|
||||
if (this.numberOfMoves%(26*26) == 0){
|
||||
if (this.numberOfMoves%(26*26) === 0) {
|
||||
SRotor.step();
|
||||
}
|
||||
}
|
||||
@ -302,7 +301,7 @@ export class IndexBank{
|
||||
@returns {number}
|
||||
*/
|
||||
crypt(inputPos) {
|
||||
for (let rotor of this.rotors){
|
||||
for (const rotor of this.rotors) {
|
||||
inputPos = rotor.crypt(inputPos);
|
||||
}
|
||||
return inputPos;
|
||||
@ -315,7 +314,7 @@ export class IndexBank{
|
||||
@returns {number[]}
|
||||
*/
|
||||
goThroughIndex(controlInputs) {
|
||||
let outputs = [];
|
||||
const outputs = [];
|
||||
for (const inp of controlInputs) {
|
||||
outputs.push(this.crypt(inp));
|
||||
}
|
||||
@ -349,12 +348,11 @@ export class Rotor{
|
||||
@returns {number[]}
|
||||
*/
|
||||
getNumMapping(wireSetting, rev) {
|
||||
if (rev==false){
|
||||
if (rev===false) {
|
||||
return wireSetting;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
const length = wireSetting.length;
|
||||
let tempMapping = new Array(length);
|
||||
const tempMapping = new Array(length);
|
||||
for (let i=0; i<length; i++) {
|
||||
tempMapping[wireSetting[i]] = i;
|
||||
}
|
||||
@ -370,8 +368,8 @@ export class Rotor{
|
||||
*/
|
||||
getPosMapping(rev) {
|
||||
const length = this.numMapping.length;
|
||||
let posMapping = [];
|
||||
if (rev==false){
|
||||
const posMapping = [];
|
||||
if (rev===false) {
|
||||
for (let i = this.state; i < this.state+length; i++) {
|
||||
let res = i%length;
|
||||
if (res<0) {
|
||||
@ -379,8 +377,7 @@ export class Rotor{
|
||||
}
|
||||
posMapping.push(res);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
for (let i = this.state; i > this.state-length; i--) {
|
||||
let res = i%length;
|
||||
if (res<0) {
|
||||
@ -401,11 +398,10 @@ export class Rotor{
|
||||
*/
|
||||
cryptNum(inputPos, direction) {
|
||||
const inpNum = this.posMapping[inputPos];
|
||||
var outNum;
|
||||
if (direction == "leftToRight"){
|
||||
let outNum;
|
||||
if (direction === "leftToRight") {
|
||||
outNum = this.numMapping[inpNum];
|
||||
}
|
||||
else if (direction == "rightToLeft") {
|
||||
} else if (direction === "rightToLeft") {
|
||||
outNum = this.numMapping.indexOf(inpNum);
|
||||
}
|
||||
const outPos = this.posMapping.indexOf(outNum);
|
||||
|
@ -7,7 +7,6 @@ Emulation of the SIGABA machine.
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import {LETTERS} from "../lib/Enigma.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}
|
||||
*/
|
||||
|
||||
parseRotorStr(rotor){
|
||||
if (rotor === ""){
|
||||
throw new OperationError(`All rotor wirings must be provided.`);
|
||||
}
|
||||
return rotor;
|
||||
}
|
||||
|
||||
run(input, args) {
|
||||
const sigabaSwitch = args[40];
|
||||
const cipherRotors = [];
|
||||
const controlRotors = [];
|
||||
const indexRotors = [];
|
||||
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]));
|
||||
}
|
||||
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]));
|
||||
}
|
||||
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]));
|
||||
}
|
||||
const sigaba = new SigabaMachine(cipherRotors, controlRotors, indexRotors);
|
||||
var result;
|
||||
let result;
|
||||
if (sigabaSwitch === "Encrypt") {
|
||||
result = sigaba.encrypt(input);
|
||||
}
|
||||
else if (sigabaSwitch === "Decrypt") {
|
||||
} else if (sigabaSwitch === "Decrypt") {
|
||||
result = sigaba.decrypt(input);
|
||||
}
|
||||
return result;
|
||||
|
Loading…
x
Reference in New Issue
Block a user