mirror of
https://github.com/gchq/CyberChef.git
synced 2025-07-05 20:32:21 -04:00
Merge remote-tracking branch 'upstream/master' into feature_filter
This commit is contained in:
commit
f44171c005
22 changed files with 9087 additions and 131 deletions
|
@ -475,6 +475,43 @@ var Cipher = {
|
|||
return output;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
SUBS_PLAINTEXT: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
SUBS_CIPHERTEXT: "XYZABCDEFGHIJKLMNOPQRSTUVW",
|
||||
|
||||
/**
|
||||
* Substitute operation.
|
||||
*
|
||||
* @param {byte_array} input
|
||||
* @param {Object[]} args
|
||||
* @returns {byte_array}
|
||||
*/
|
||||
run_substitute: function (input, args) {
|
||||
var plaintext = Utils.str_to_byte_array(Utils.expand_alph_range(args[0]).join()),
|
||||
ciphertext = Utils.str_to_byte_array(Utils.expand_alph_range(args[1]).join()),
|
||||
output = [],
|
||||
index = -1;
|
||||
|
||||
if (plaintext.length !== ciphertext.length) {
|
||||
output = Utils.str_to_byte_array("Warning: Plaintext and Ciphertext lengths differ\n\n");
|
||||
}
|
||||
|
||||
for (var i = 0; i < input.length; i++) {
|
||||
index = plaintext.indexOf(input[i]);
|
||||
output.push(index > -1 && index < ciphertext.length ? ciphertext[index] : input[i]);
|
||||
}
|
||||
|
||||
return output;
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* globals prettyPrintOne, vkbeautify */
|
||||
/* globals prettyPrintOne, vkbeautify, xpath */
|
||||
|
||||
/**
|
||||
* Code operations.
|
||||
|
@ -304,4 +304,119 @@ var Code = {
|
|||
}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
XPATH_INITIAL: "",
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
XPATH_DELIMITER: "\\n",
|
||||
|
||||
/**
|
||||
* XPath expression operation.
|
||||
*
|
||||
* @author Mikescher (https://github.com/Mikescher | https://mikescher.com)
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run_xpath:function(input, args) {
|
||||
const query = args[0],
|
||||
delimiter = args[1];
|
||||
|
||||
var xml;
|
||||
try {
|
||||
xml = $.parseXML(input);
|
||||
} catch (err) {
|
||||
return "Invalid input XML.";
|
||||
}
|
||||
|
||||
var result;
|
||||
try {
|
||||
result = xpath.evaluate(xml, query);
|
||||
} catch (err) {
|
||||
return "Invalid XPath. Details:\n" + err.message;
|
||||
}
|
||||
|
||||
const serializer = new XMLSerializer();
|
||||
const node_to_string = function(node) {
|
||||
switch (node.nodeType) {
|
||||
case Node.ELEMENT_NODE: return serializer.serializeToString(node);
|
||||
case Node.ATTRIBUTE_NODE: return node.value;
|
||||
case Node.COMMENT_NODE: return node.data;
|
||||
case Node.DOCUMENT_NODE: return serializer.serializeToString(node);
|
||||
default: throw new Error("Unknown Node Type: " + node.nodeType);
|
||||
}
|
||||
};
|
||||
|
||||
return Object.keys(result).map(function(key) {
|
||||
return result[key];
|
||||
}).slice(0, -1) // all values except last (length)
|
||||
.map(node_to_string)
|
||||
.join(delimiter);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
CSS_SELECTOR_INITIAL: "",
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
CSS_QUERY_DELIMITER: "\\n",
|
||||
|
||||
/**
|
||||
* CSS selector operation.
|
||||
*
|
||||
* @author Mikescher (https://github.com/Mikescher | https://mikescher.com)
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run_css_query: function(input, args) {
|
||||
const query = args[0],
|
||||
delimiter = args[1];
|
||||
|
||||
var html;
|
||||
try {
|
||||
html = $.parseHTML(input);
|
||||
} catch (err) {
|
||||
return "Invalid input HTML.";
|
||||
}
|
||||
|
||||
var result;
|
||||
try {
|
||||
result = $(html).find(query);
|
||||
} catch (err) {
|
||||
return "Invalid CSS Selector. Details:\n" + err.message;
|
||||
}
|
||||
|
||||
const node_to_string = function(node) {
|
||||
switch (node.nodeType) {
|
||||
case Node.ELEMENT_NODE: return node.outerHTML;
|
||||
case Node.ATTRIBUTE_NODE: return node.value;
|
||||
case Node.COMMENT_NODE: return node.data;
|
||||
case Node.TEXT_NODE: return node.wholeText;
|
||||
case Node.DOCUMENT_NODE: return node.outerHTML;
|
||||
default: throw new Error("Unknown Node Type: " + node.nodeType);
|
||||
}
|
||||
};
|
||||
|
||||
return Array.apply(null, Array(result.length))
|
||||
.map(function(_, i) {
|
||||
return result[i];
|
||||
})
|
||||
.map(node_to_string)
|
||||
.join(delimiter);
|
||||
},
|
||||
|
||||
};
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
var Extract = {
|
||||
|
||||
/**
|
||||
* Runs search operations across the input data using refular expressions.
|
||||
* Runs search operations across the input data using regular expressions.
|
||||
*
|
||||
* @private
|
||||
* @param {string} input
|
||||
|
@ -293,5 +293,5 @@ var Extract = {
|
|||
output += Extract.run_dates(input, []);
|
||||
return output;
|
||||
},
|
||||
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue