Merge branch 'operation/convert-to-nato-alphabet' of https://github.com/MarvinJWendt/CyberChef into MarvinJWendt-operation/convert-to-nato-alphabet

This commit is contained in:
n1474335 2020-03-13 16:45:37 +00:00
commit 0fad891a3a
3 changed files with 194 additions and 1 deletions

View file

@ -201,7 +201,8 @@
"Encode text", "Encode text",
"Decode text", "Decode text",
"Remove Diacritics", "Remove Diacritics",
"Unescape Unicode Characters" "Unescape Unicode Characters",
"Convert to NATO alphabet"
] ]
}, },
{ {

View file

@ -0,0 +1,160 @@
/**
* @author MarvinJWendt [git@marvinjwendt.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
/**
* Convert to NATO alphabet operation
*/
class ConvertToNATOAlphabet extends Operation {
/**
* ConvertToNATOAlphabet constructor
*/
constructor() {
super();
this.name = "Convert to NATO alphabet";
this.module = "Default";
this.description = "Convert a text to NATO alphabet.";
this.infoURL = "https://en.wikipedia.org/wiki/NATO_phonetic_alphabet";
this.inputType = "string";
this.outputType = "string";
this.args = [];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
let result = "";
const text = input.toUpperCase();
for (let i = 0; i < text.length; i++) {
switch (text.charAt(i)) {
case "A":
result += "alfa ";
break;
case "B":
result += "bravo ";
break;
case "C":
result += "charlie ";
break;
case "D":
result += "delta ";
break;
case "E":
result += "echo ";
break;
case "F":
result += "foxtrot ";
break;
case "G":
result += "golf ";
break;
case "H":
result += "hotel ";
break;
case "I":
result += "india ";
break;
case "J":
result += "juliett ";
break;
case "K":
result += "kilo ";
break;
case "L":
result += "lima ";
break;
case "M":
result += "mike ";
break;
case "N":
result += "november ";
break;
case "O":
result += "oscar ";
break;
case "P":
result += "papa ";
break;
case "Q":
result += "quebec ";
break;
case "R":
result += "romeo ";
break;
case "S":
result += "sierra ";
break;
case "T":
result += "tango ";
break;
case "U":
result += "uniform ";
break;
case "V":
result += "victor ";
break;
case "W":
result += "whiskey ";
break;
case "X":
result += "xray ";
break;
case "Y":
result += "yankee ";
break;
case "Z":
result += "zulu ";
break;
case " ":
result += " ";
break;
case "0":
result += "zero ";
break;
case "1":
result += "one ";
break;
case "2":
result += "two ";
break;
case "3":
result += "three ";
break;
case "4":
result += "four ";
break;
case "5":
result += "five ";
break;
case "6":
result += "six ";
break;
case "7":
result += "seven ";
break;
case "8":
result += "eight ";
break;
case "9":
result += "nine ";
break;
default:
result += text.charAt(i) + " ";
}
}
return result;
}
}
export default ConvertToNATOAlphabet;

View file

@ -0,0 +1,32 @@
/**
* @author MarvinJWendt [git@marvinjwendt.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "Convert to NATO alphabet: nothing",
input: "",
expectedOutput: "",
recipeConfig: [
{
op: "Convert to NATO alphabet",
args: [""]
}
]
},
{
name: "Convert to NATO alphabet: full alphabet with numbers",
input: "abcdefghijklmnopqrstuvwxyz0123456789",
expectedOutput: "alfa bravo charlie delta echo foxtrot golf hotel india juliett kilo lima mike november oscar papa quebec romeo sierra tango uniform victor whiskey xray yankee zulu zero one two three four five six seven eight nine ",
recipeConfig: [
{
op: "Convert to NATO alphabet",
args: [""]
}
]
}
]);