From 32aea6b86cb982d4f901197c162ce10fe90ee644 Mon Sep 17 00:00:00 2001 From: Spencer Walden Date: Sun, 30 Dec 2018 03:20:24 -0800 Subject: [PATCH 1/6] Adds 'To Case Insensitive Regex' operation --- .../operations/ToCaseInsensitiveRegex.mjs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/core/operations/ToCaseInsensitiveRegex.mjs diff --git a/src/core/operations/ToCaseInsensitiveRegex.mjs b/src/core/operations/ToCaseInsensitiveRegex.mjs new file mode 100644 index 00000000..32fb96c7 --- /dev/null +++ b/src/core/operations/ToCaseInsensitiveRegex.mjs @@ -0,0 +1,39 @@ +/** + * @author masq [github.cyberchef@masq.cc] + * @copyright Crown Copyright 2018 + * @license Apache-2.0 + */ + +import Operation from "../Operation"; + +/** + * To Case Insensitive Regex operation + */ +class ToCaseInsensitiveRegex extends Operation { + + /** + * ToCaseInsensitiveRegex constructor + */ + constructor() { + super(); + + this.name = "To Case Insensitive Regex"; + this.module = "Default"; + this.description = "Converts a case-sensitive regex string into a case-insensitive regex string in case /i flag is unavailable to you."; + this.infoURL = "https://wikipedia.org/wiki/Regular_expression"; + this.inputType = "string"; + this.outputType = "string"; + this.args = []; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + return input.replace(/[a-z]/ig, m => `[${m.toLowerCase()}${m.toUpperCase()}]`); + } +} + +export default ToCaseInsensitiveRegex; From 3c16b839b6fdbfe1d95cd0df6337f94d6f7f31c6 Mon Sep 17 00:00:00 2001 From: Spencer Walden Date: Sun, 30 Dec 2018 03:20:44 -0800 Subject: [PATCH 2/6] Adds 'From Case Insensitive Regex' operation --- .../operations/FromCaseInsensitiveRegex.mjs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/core/operations/FromCaseInsensitiveRegex.mjs diff --git a/src/core/operations/FromCaseInsensitiveRegex.mjs b/src/core/operations/FromCaseInsensitiveRegex.mjs new file mode 100644 index 00000000..2448c5e5 --- /dev/null +++ b/src/core/operations/FromCaseInsensitiveRegex.mjs @@ -0,0 +1,39 @@ +/** + * @author masq [github.cyberchef@masq.cc] + * @copyright Crown Copyright 2018 + * @license Apache-2.0 + */ + +import Operation from "../Operation"; + +/** + * From Case Insensitive Regex operation + */ +class FromCaseInsensitiveRegex extends Operation { + + /** + * FromCaseInsensitiveRegex constructor + */ + constructor() { + super(); + + this.name = "From Case Insensitive Regex"; + this.module = "Default"; + this.description = "Converts a case-insensitive regex string to a case sensitive regex string (no guarantee on it being the proper original casing) in case /i wasn't available at the time but now is, or you need it to be case-sensitive again."; + this.infoURL = "https://wikipedia.org/wiki/Regular_expression"; + this.inputType = "string"; + this.outputType = "string"; + this.args = []; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + return input.replace(/\[[a-z]{2}\]/ig, m => m[1].toUpperCase() === m[2].toUpperCase() ? m[1] : m); + } +} + +export default FromCaseInsensitiveRegex; From b750006cf0bef9b8609d30ffb445281150b0837a Mon Sep 17 00:00:00 2001 From: Spencer Walden Date: Sun, 30 Dec 2018 03:21:19 -0800 Subject: [PATCH 3/6] Adds tests for 'To/From Case Insensitive Regex' operations --- .../operations/ToFromInsensitiveRegex.mjs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test/tests/operations/ToFromInsensitiveRegex.mjs diff --git a/test/tests/operations/ToFromInsensitiveRegex.mjs b/test/tests/operations/ToFromInsensitiveRegex.mjs new file mode 100644 index 00000000..13c24e44 --- /dev/null +++ b/test/tests/operations/ToFromInsensitiveRegex.mjs @@ -0,0 +1,56 @@ +/** + * To/From Case Insensitive Regex tests. + * + * @author masq [github.cyberchef@masq.cc] + * + * @copyright Crown Copyright 2018 + * @license Apache-2.0 + */ +import TestRegister from "../../TestRegister"; + +TestRegister.addTests([ + { + name: "To Case Insensitive Regex: nothing", + input: "", + expectedOutput: "", + recipeConfig: [ + { + op: "To Case Insensitive Regex", + args: [], + }, + ], + }, + { + name: "From Case Insensitive Regex: nothing", + input: "", + expectedOutput: "", + recipeConfig: [ + { + op: "From Case Insensitive Regex", + args: [], + }, + ], + }, + { + name: "To Case Insensitive Regex: simple test", + input: "S0meth!ng", + expectedOutput: "[sS]0[mM][eE][tT][hH]![nN][gG]", + recipeConfig: [ + { + op: "To Case Insensitive Regex", + args: [], + }, + ], + }, + { + name: "From Case Insensitive Regex: simple test", + input: "[sS]0[mM][eE][tT][hH]![nN][Gg] [wr][On][g]?", + expectedOutput: "s0meth!nG [wr][On][g]?", + recipeConfig: [ + { + op: "From Case Insensitive Regex", + args: [], + }, + ], + }, +]); From 1d04b649e00f81220e8ad7c00744817d6aa87acc Mon Sep 17 00:00:00 2001 From: Spencer Walden Date: Sun, 30 Dec 2018 03:21:52 -0800 Subject: [PATCH 4/6] Adds 'To/From Case Insensitive Regex' operations under 'Utils' --- src/core/config/Categories.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json index a93149fe..c2dad458 100755 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -189,6 +189,8 @@ "Remove null bytes", "To Upper case", "To Lower case", + "To Case Insensitive Regex", + "From Case Insensitive Regex", "Add line numbers", "Remove line numbers", "To Table", From 126ad585c03f238769fc085fc151f56fd6fe1d2c Mon Sep 17 00:00:00 2001 From: Spencer Walden Date: Sun, 30 Dec 2018 03:22:23 -0800 Subject: [PATCH 5/6] Registers tests for 'To/From Case Insensitive Regex' operations --- test/index.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/index.mjs b/test/index.mjs index ff13fe3b..3900490a 100644 --- a/test/index.mjs +++ b/test/index.mjs @@ -82,6 +82,7 @@ import "./tests/operations/TranslateDateTimeFormat"; import "./tests/operations/Magic"; import "./tests/operations/ParseTLV"; import "./tests/operations/Media"; +import "./tests/operations/ToFromInsensitiveRegex"; let allTestsPassing = true; const testStatusCounts = { From 995fcab071e187c092ee085bc6e5c41c817e9590 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Thu, 10 Jan 2019 15:01:01 +0000 Subject: [PATCH 6/6] Tidied up Case Insensitive Regex ops --- CHANGELOG.md | 6 ++++++ src/core/operations/FromCaseInsensitiveRegex.mjs | 2 +- src/core/operations/ToCaseInsensitiveRegex.mjs | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9b8eff0..4761b540 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All major and minor version changes will be documented in this file. Details of patch-level version changes can be found in [commit messages](https://github.com/gchq/CyberChef/commits/master). +### [8.21.0] - 2019-01-10 +- 'To Case Insensitive Regex' and 'From Case Insensitive Regex' operations added [@masq] | [#461] + ### [8.20.0] - 2019-01-09 - 'Generate Lorem Ipsum' operation added [@klaxon1] | [#455] @@ -91,6 +94,7 @@ All major and minor version changes will be documented in this file. Details of +[8.21.0]: https://github.com/gchq/CyberChef/releases/tag/v8.21.0 [8.20.0]: https://github.com/gchq/CyberChef/releases/tag/v8.20.0 [8.19.0]: https://github.com/gchq/CyberChef/releases/tag/v8.19.0 [8.18.0]: https://github.com/gchq/CyberChef/releases/tag/v8.18.0 @@ -134,6 +138,7 @@ All major and minor version changes will be documented in this file. Details of [@tcode2k16]: https://github.com/tcode2k16 [@Cynser]: https://github.com/Cynser [@anthony-arnold]: https://github.com/anthony-arnold +[@masq]: https://github.com/masq [#95]: https://github.com/gchq/CyberChef/pull/299 [#173]: https://github.com/gchq/CyberChef/pull/173 @@ -165,3 +170,4 @@ All major and minor version changes will be documented in this file. Details of [#449]: https://github.com/gchq/CyberChef/pull/449 [#455]: https://github.com/gchq/CyberChef/pull/455 [#458]: https://github.com/gchq/CyberChef/pull/458 +[#461]: https://github.com/gchq/CyberChef/pull/461 diff --git a/src/core/operations/FromCaseInsensitiveRegex.mjs b/src/core/operations/FromCaseInsensitiveRegex.mjs index 2448c5e5..36cd9b14 100644 --- a/src/core/operations/FromCaseInsensitiveRegex.mjs +++ b/src/core/operations/FromCaseInsensitiveRegex.mjs @@ -19,7 +19,7 @@ class FromCaseInsensitiveRegex extends Operation { this.name = "From Case Insensitive Regex"; this.module = "Default"; - this.description = "Converts a case-insensitive regex string to a case sensitive regex string (no guarantee on it being the proper original casing) in case /i wasn't available at the time but now is, or you need it to be case-sensitive again."; + this.description = "Converts a case-insensitive regex string to a case sensitive regex string (no guarantee on it being the proper original casing) in case the i flag wasn't available at the time but now is, or you need it to be case-sensitive again.

e.g. [mM][oO][zZ][iI][lL][lL][aA]/[0-9].[0-9] .* becomes Mozilla/[0-9].[0-9] .*"; this.infoURL = "https://wikipedia.org/wiki/Regular_expression"; this.inputType = "string"; this.outputType = "string"; diff --git a/src/core/operations/ToCaseInsensitiveRegex.mjs b/src/core/operations/ToCaseInsensitiveRegex.mjs index 32fb96c7..0d606a05 100644 --- a/src/core/operations/ToCaseInsensitiveRegex.mjs +++ b/src/core/operations/ToCaseInsensitiveRegex.mjs @@ -19,7 +19,7 @@ class ToCaseInsensitiveRegex extends Operation { this.name = "To Case Insensitive Regex"; this.module = "Default"; - this.description = "Converts a case-sensitive regex string into a case-insensitive regex string in case /i flag is unavailable to you."; + this.description = "Converts a case-sensitive regex string into a case-insensitive regex string in case the i flag is unavailable to you.

e.g. Mozilla/[0-9].[0-9] .* becomes [mM][oO][zZ][iI][lL][lL][aA]/[0-9].[0-9] .*"; this.infoURL = "https://wikipedia.org/wiki/Regular_expression"; this.inputType = "string"; this.outputType = "string";