mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 07:16:17 -04:00
Tidied Morse Code operations to match the project conventions.
This commit is contained in:
parent
718e1dc153
commit
8f69ee441e
7 changed files with 42 additions and 210 deletions
|
@ -82,11 +82,11 @@ var Categories = [
|
|||
"XOR Brute Force",
|
||||
"Vigenère Encode",
|
||||
"Vigenère Decode",
|
||||
"To Morse Code",
|
||||
"From Morse Code",
|
||||
"Substitute",
|
||||
"Derive PBKDF2 key",
|
||||
"Derive EVP key",
|
||||
"To Morse code",
|
||||
"From Morse code",
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -2953,9 +2953,9 @@ var OperationConfig = {
|
|||
}
|
||||
]
|
||||
},
|
||||
"To Morse code": {
|
||||
description: "Translates alphanumeric characters into International Morse code.<br><br>Ignores non-Morse characters.<br><br>e.g. SOS becomes ... --- ...",
|
||||
run: MorseCode.translateTo,
|
||||
"To Morse Code": {
|
||||
description: "Translates alphanumeric characters into International Morse Code.<br><br>Ignores non-Morse characters.<br><br>e.g. <code>SOS</code> becomes <code>... --- ...</code>",
|
||||
run: MorseCode.runTo,
|
||||
inputType: "string",
|
||||
outputType: "string",
|
||||
args: [
|
||||
|
@ -2976,9 +2976,9 @@ var OperationConfig = {
|
|||
}
|
||||
]
|
||||
},
|
||||
"From Morse code": {
|
||||
description: "Translates Morse code into (upper case) alphanumeric characters.",
|
||||
run: MorseCode.translateFrom,
|
||||
"From Morse Code": {
|
||||
description: "Translates Morse Code into (upper case) alphanumeric characters.",
|
||||
run: MorseCode.runFrom,
|
||||
inputType: "string",
|
||||
outputType: "string",
|
||||
args: [
|
||||
|
|
|
@ -14,29 +14,16 @@ var MorseCode = {
|
|||
* @default
|
||||
*/
|
||||
FORMAT_OPTIONS: ["-/.", "_/.", "Dash/Dot", "DASH/DOT", "dash/dot"],
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
LETTER_DELIM_OPTIONS: ["space", "line feed", "crlf"],
|
||||
|
||||
LETTER_DELIM_OPTIONS: ["Space", "Line feed", "CRLF", "Comma", "Semi-colon", "Colon"],
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
WORD_DELIM_OPTIONS: ["line feed", "crlf", "space"],
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
OPTION_TABLE: {
|
||||
"space": " ",
|
||||
"line feed": "\n",
|
||||
"crlf": "\r\n"
|
||||
},
|
||||
|
||||
WORD_DELIM_OPTIONS: ["Line feed", "CRLF", "Space", "Comma", "Semi-colon", "Colon"],
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
|
@ -88,13 +75,13 @@ var MorseCode = {
|
|||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
translateTo: function(input, args) {
|
||||
runTo: function(input, args) {
|
||||
var format = args[0].split("/");
|
||||
var dash = format[0];
|
||||
var dot = format[1];
|
||||
|
||||
var letterDelim = MorseCode.OPTION_TABLE[args[1]];
|
||||
var wordDelim = MorseCode.OPTION_TABLE[args[2]];
|
||||
var letterDelim = Utils.charRep[args[1]];
|
||||
var wordDelim = Utils.charRep[args[2]];
|
||||
|
||||
input = input.split(/\r?\n/);
|
||||
input = Array.prototype.map.call(input, function(line) {
|
||||
|
@ -139,7 +126,7 @@ var MorseCode = {
|
|||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
translateFrom: (function() {
|
||||
runFrom: (function() {
|
||||
var reversedTable = null;
|
||||
var reverseTable = function() {
|
||||
reversedTable = {};
|
||||
|
@ -155,8 +142,8 @@ var MorseCode = {
|
|||
reverseTable();
|
||||
}
|
||||
|
||||
var letterDelim = MorseCode.OPTION_TABLE[args[0]];
|
||||
var wordDelim = MorseCode.OPTION_TABLE[args[1]];
|
||||
var letterDelim = Utils.charRep[args[0]];
|
||||
var wordDelim = Utils.charRep[args[1]];
|
||||
|
||||
input = input.replace(/-|_|dash/ig, "<dash>");
|
||||
input = input.replace(/\.|dot/ig, "<dot>");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue