diff --git a/src/core/Utils.mjs b/src/core/Utils.mjs index a9c381d7..879e9bbb 100755 --- a/src/core/Utils.mjs +++ b/src/core/Utils.mjs @@ -1302,6 +1302,7 @@ class Utils { "Backslash": "\\", "0x": "0x", "\\x": "\\x", + "Hyphen": "-", "Nothing (separate chars)": "", "None": "", }[token]; diff --git a/src/core/operations/A1Z26CipherDecode.mjs b/src/core/operations/A1Z26CipherDecode.mjs index 0b097c2b..43b4a583 100644 --- a/src/core/operations/A1Z26CipherDecode.mjs +++ b/src/core/operations/A1Z26CipherDecode.mjs @@ -26,11 +26,24 @@ class A1Z26CipherDecode extends Operation { this.infoURL = ""; this.inputType = "string"; this.outputType = "string"; + + // Issue 1124 - sometimes hyphen is used as a character delimiter + var char_d = [...DELIM_OPTIONS]; + char_d.push("Hyphen"); + + var word_d = [...DELIM_OPTIONS]; + word_d.unshift("None"); + this.args = [ { - name: "Delimiter", + name: "Character Delimiter", type: "option", - value: DELIM_OPTIONS + value: char_d + }, + { + name: "Word Delimiter", + type: "option", + value: word_d } ]; this.checks = [ @@ -59,6 +72,11 @@ class A1Z26CipherDecode extends Operation { flags: "", args: ["Line feed"] }, + { + pattern: "^\\s*([12]?[0-9]-)+[12]?[0-9]\\s*$", + flags: "", + args: ["Hyphen"] + }, { pattern: "^\\s*([12]?[0-9]\\r\\n)+[12]?[0-9]\\s*$", flags: "", @@ -73,21 +91,33 @@ class A1Z26CipherDecode extends Operation { * @returns {string} */ run(input, args) { - const delim = Utils.charRep(args[0] || "Space"); + const char_delim = Utils.charRep(args[0] || "Space"); + const word_delim = Utils.charRep(args[1] || "None"); if (input.length === 0) { return []; } - const bites = input.split(delim); - let latin1 = ""; - for (let i = 0; i < bites.length; i++) { - if (bites[i] < 1 || bites[i] > 26) { - throw new OperationError("Error: all numbers must be between 1 and 26."); - } - latin1 += Utils.chr(parseInt(bites[i], 10) + 96); + var words; + if (word_delim != "") { + words = input.split(word_delim); + } else { + words = [input]; } - return latin1; + + let output = ""; + for (let j = 0; j < words.length; j++) { + const bites = words[j].split(char_delim); + let latin1 = ""; + for (let i = 0; i < bites.length; i++) { + if (bites[i] < 1 || bites[i] > 26) { + throw new OperationError("Error: all numbers must be between 1 and 26."); + } + latin1 += Utils.chr(parseInt(bites[i], 10) + 96); + } + output = output + " " + latin1; + } + return output; } }