mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-10 00:05:11 -04:00
Added in custom delimiter and word delimiter as per 1124
This commit is contained in:
parent
c9d9730726
commit
5d8a245ea6
2 changed files with 42 additions and 11 deletions
|
@ -1159,6 +1159,7 @@ class Utils {
|
|||
"Backslash": "\\",
|
||||
"0x": "0x",
|
||||
"\\x": "\\x",
|
||||
"Hyphen": "-",
|
||||
"Nothing (separate chars)": "",
|
||||
"None": "",
|
||||
}[token];
|
||||
|
|
|
@ -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,13 +91,23 @@ 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);
|
||||
var words;
|
||||
if (word_delim != "") {
|
||||
words = input.split(word_delim);
|
||||
} else {
|
||||
words = [input];
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -87,7 +115,9 @@ class A1Z26CipherDecode extends Operation {
|
|||
}
|
||||
latin1 += Utils.chr(parseInt(bites[i], 10) + 96);
|
||||
}
|
||||
return latin1;
|
||||
output = output + " " + latin1;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue