This commit is contained in:
mt3571 2024-04-25 19:25:42 +01:00 committed by GitHub
commit 148c4335e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 11 deletions

View File

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

View File

@ -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;
}
}