Added in custom delimiter and word delimiter as per 1124

This commit is contained in:
mt3571 2020-11-27 14:29:27 +00:00
parent c9d9730726
commit 5d8a245ea6
2 changed files with 42 additions and 11 deletions

View file

@ -1159,6 +1159,7 @@ class Utils {
"Backslash": "\\", "Backslash": "\\",
"0x": "0x", "0x": "0x",
"\\x": "\\x", "\\x": "\\x",
"Hyphen": "-",
"Nothing (separate chars)": "", "Nothing (separate chars)": "",
"None": "", "None": "",
}[token]; }[token];

View file

@ -26,11 +26,24 @@ class A1Z26CipherDecode extends Operation {
this.infoURL = ""; this.infoURL = "";
this.inputType = "string"; this.inputType = "string";
this.outputType = "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 = [ this.args = [
{ {
name: "Delimiter", name: "Character Delimiter",
type: "option", type: "option",
value: DELIM_OPTIONS value: char_d
},
{
name: "Word Delimiter",
type: "option",
value: word_d
} }
]; ];
this.checks = [ this.checks = [
@ -59,6 +72,11 @@ class A1Z26CipherDecode extends Operation {
flags: "", flags: "",
args: ["Line feed"] 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*$", pattern: "^\\s*([12]?[0-9]\\r\\n)+[12]?[0-9]\\s*$",
flags: "", flags: "",
@ -73,21 +91,33 @@ class A1Z26CipherDecode extends Operation {
* @returns {string} * @returns {string}
*/ */
run(input, args) { 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) { if (input.length === 0) {
return []; return [];
} }
const bites = input.split(delim); var words;
let latin1 = ""; if (word_delim != "") {
for (let i = 0; i < bites.length; i++) { words = input.split(word_delim);
if (bites[i] < 1 || bites[i] > 26) { } else {
throw new OperationError("Error: all numbers must be between 1 and 26."); words = [input];
}
latin1 += Utils.chr(parseInt(bites[i], 10) + 96);
} }
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;
} }
} }