From 597fba2fd0a5edd318f8586b5e4a19078466d94b Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Wed, 15 Jan 2020 00:14:43 +0000 Subject: [PATCH 01/21] Add line size formatting and comma separation --- src/core/lib/Hex.mjs | 35 ++++++++++++++++++++++++++--------- src/core/operations/ToHex.mjs | 13 ++++++++++++- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/core/lib/Hex.mjs b/src/core/lib/Hex.mjs index 5ae06a7e..0274f876 100644 --- a/src/core/lib/Hex.mjs +++ b/src/core/lib/Hex.mjs @@ -23,25 +23,42 @@ import Utils from "../Utils.mjs"; * * // returns "0a:14:1e" * toHex([10,20,30], ":"); + * + * // returns "0x0a,0x14,0x1e" + * toHex([10,20,30], "0x", 2, ",") */ -export function toHex(data, delim=" ", padding=2) { +export function toHex(data, delim=" ", padding=2, extraDelim="", lineSize=0) { if (!data) return ""; if (data instanceof ArrayBuffer) data = new Uint8Array(data); let output = ""; + const prepend = (delim === "0x" || delim === "\\x"); for (let i = 0; i < data.length; i++) { - output += data[i].toString(16).padStart(padding, "0") + delim; + const hex = data[i].toString(16).padStart(padding, "0"); + if (prepend) { + output += delim + hex; + } else { + output += hex + delim; + } + if (extraDelim) { + output += extraDelim; + } + // Add LF after each lineSize amount of bytes but not at the end + if ((i !== data.length - 1) && ((i + 1) % lineSize === 0)) { + output += "\n"; + } } - // Add \x or 0x to beginning - if (delim === "0x") output = "0x" + output; - if (delim === "\\x") output = "\\x" + output; - - if (delim.length) - return output.slice(0, -delim.length); - else + // Remove the extraDelim at the end (if there is); + // and remove the delim at the end, but if it's prepended there's nothing to remove + const rTruncLen = extraDelim.length + (prepend ? 0 : delim.length); + if (rTruncLen) { + // If rTruncLen === 0 then output.slice(0,0) will be returned, which is nothing + return output.slice(0, -rTruncLen); + } else { return output; + } } diff --git a/src/core/operations/ToHex.mjs b/src/core/operations/ToHex.mjs index 6ae48da9..b2712b40 100644 --- a/src/core/operations/ToHex.mjs +++ b/src/core/operations/ToHex.mjs @@ -30,6 +30,16 @@ class ToHex extends Operation { name: "Delimiter", type: "option", value: TO_HEX_DELIM_OPTIONS + }, + { + name: "Bytes per line", + type: "number", + value: 0 + }, + { + name: "Comma separated", + type: "boolean", + value: false } ]; } @@ -41,7 +51,8 @@ class ToHex extends Operation { */ run(input, args) { const delim = Utils.charRep(args[0] || "Space"); - return toHex(new Uint8Array(input), delim, 2); + const comma = args[2] ? "," : ""; + return toHex(new Uint8Array(input), delim, 2, comma, args[1]); } /** From 41c8a5aff0a95d7cb8a12d204269b568a9cb0964 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Wed, 15 Jan 2020 22:20:47 +0000 Subject: [PATCH 02/21] fromHex can now extract 0x format --- src/core/lib/Hex.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/lib/Hex.mjs b/src/core/lib/Hex.mjs index 0274f876..0108eabd 100644 --- a/src/core/lib/Hex.mjs +++ b/src/core/lib/Hex.mjs @@ -104,7 +104,7 @@ export function toHexFast(data) { */ export function fromHex(data, delim="Auto", byteLen=2) { if (delim !== "None") { - const delimRegex = delim === "Auto" ? /[^a-f\d]/gi : Utils.regexRep(delim); + const delimRegex = delim === "Auto" ? /[^a-f\d]|(0x)/gi : Utils.regexRep(delim); data = data.replace(delimRegex, ""); } From 1d8c7dcb970cb9d40bf76803c08661fb0dbc7f05 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Wed, 15 Jan 2020 23:29:18 +0000 Subject: [PATCH 03/21] Allow output highlighting --- src/core/operations/ToHex.mjs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/core/operations/ToHex.mjs b/src/core/operations/ToHex.mjs index b2712b40..f2c308b2 100644 --- a/src/core/operations/ToHex.mjs +++ b/src/core/operations/ToHex.mjs @@ -66,15 +66,25 @@ class ToHex extends Operation { */ highlight(pos, args) { const delim = Utils.charRep(args[0] || "Space"), - len = delim === "\r\n" ? 1 : delim.length; + lineSize = args[1], + comma = args[2], + len = (delim === "\r\n" ? 1 : delim.length) + (comma ? 1 : 0); - pos[0].start = pos[0].start * (2 + len); - pos[0].end = pos[0].end * (2 + len) - len; + const countLF = function(p) { + // Count the number of LFs from 0 upto p + return (p / lineSize | 0) - (p >= lineSize && p % lineSize === 0); + }; - // 0x and \x are added to the beginning if they are selected, so increment the positions accordingly - if (delim === "0x" || delim === "\\x") { - pos[0].start += 2; - pos[0].end += 2; + pos[0].start = pos[0].start * (2 + len) + countLF(pos[0].start); + pos[0].end = pos[0].end * (2 + len) + countLF(pos[0].end); + + // if the deliminators are not prepended, trim the trailing deliminator + if (!(delim === "0x" || delim === "\\x")) { + pos[0].end -= delim.length; + } + // if there is comma, trim the trailing comma + if (comma) { + pos[0].end--; } return pos; } From 6dbaf6a36c8b129b98b1434bd9986bd0d5c4338e Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Fri, 17 Jan 2020 12:48:21 +0000 Subject: [PATCH 04/21] reverse highlight --- src/core/operations/ToHex.mjs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/core/operations/ToHex.mjs b/src/core/operations/ToHex.mjs index f2c308b2..996eacfa 100644 --- a/src/core/operations/ToHex.mjs +++ b/src/core/operations/ToHex.mjs @@ -100,19 +100,19 @@ class ToHex extends Operation { */ highlightReverse(pos, args) { const delim = Utils.charRep(args[0] || "Space"), - len = delim === "\r\n" ? 1 : delim.length, + lineSize = args[1], + comma = args[2], + len = (delim === "\r\n" ? 1 : delim.length) + (comma ? 1 : 0), width = len + 2; - // 0x and \x are added to the beginning if they are selected, so increment the positions accordingly - if (delim === "0x" || delim === "\\x") { - if (pos[0].start > 1) pos[0].start -= 2; - else pos[0].start = 0; - if (pos[0].end > 1) pos[0].end -= 2; - else pos[0].end = 0; - } + const countLF = function(p) { + // Count the number of LFs from 0 up to p + const lineLength = width * lineSize; + return (p / lineLength | 0) - (p >= lineLength && p % lineLength === 0); + }; - pos[0].start = pos[0].start === 0 ? 0 : Math.round(pos[0].start / width); - pos[0].end = pos[0].end === 0 ? 0 : Math.ceil(pos[0].end / width); + pos[0].start = pos[0].start === 0 ? 0 : Math.round((pos[0].start - countLF(pos[0].start)) / width); + pos[0].end = pos[0].end === 0 ? 0 : Math.ceil((pos[0].end - countLF(pos[0].end)) / width); return pos; } } From 23956480b724aa2a763186e14f6e3ebfb6ee7405 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Fri, 17 Jan 2020 18:47:46 +0000 Subject: [PATCH 05/21] Variable name --- src/core/operations/ToHex.mjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/operations/ToHex.mjs b/src/core/operations/ToHex.mjs index 996eacfa..8c9297f5 100644 --- a/src/core/operations/ToHex.mjs +++ b/src/core/operations/ToHex.mjs @@ -51,8 +51,10 @@ class ToHex extends Operation { */ run(input, args) { const delim = Utils.charRep(args[0] || "Space"); + const lineSize = args[1]; const comma = args[2] ? "," : ""; - return toHex(new Uint8Array(input), delim, 2, comma, args[1]); + + return toHex(new Uint8Array(input), delim, 2, comma, lineSize); } /** From 55dddd3ef969a9bcfee13701c7cd02e826878fd4 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Sat, 18 Jan 2020 00:21:15 +0000 Subject: [PATCH 06/21] Add tests --- tests/operations/index.mjs | 1 + tests/operations/tests/Hex.mjs | 101 +++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 tests/operations/tests/Hex.mjs diff --git a/tests/operations/index.mjs b/tests/operations/index.mjs index bf440414..3257905d 100644 --- a/tests/operations/index.mjs +++ b/tests/operations/index.mjs @@ -45,6 +45,7 @@ import "./tests/Gzip.mjs"; import "./tests/Gunzip.mjs"; import "./tests/Hash.mjs"; import "./tests/HaversineDistance.mjs"; +import "./tests/Hex.mjs"; import "./tests/Hexdump.mjs"; import "./tests/Image.mjs"; import "./tests/IndexOfCoincidence.mjs"; diff --git a/tests/operations/tests/Hex.mjs b/tests/operations/tests/Hex.mjs new file mode 100644 index 00000000..9d55c411 --- /dev/null +++ b/tests/operations/tests/Hex.mjs @@ -0,0 +1,101 @@ +import TestRegister from "../../lib/TestRegister.mjs"; + +TestRegister.addTests([ + { + name: "ASCII to Hex stream", + input: "aberystwyth", + expectedOutput: "6162657279737477797468", + recipeConfig: [ + { + "op": "To Hex", + "args": [ + "None", + 0, + false + ] + }, + ] + }, + { + name: "ASCII to Hex with colon deliminator ", + input: "aberystwyth", + expectedOutput: "61:62:65:72:79:73:74:77:79:74:68", + recipeConfig: [ + { + "op": "To Hex", + "args": [ + "Colon", + 0, + false + ] + } + ] + }, + { + name: "ASCII to 0x Hex with comma", + input: "aberystwyth", + expectedOutput: "0x61,0x62,0x65,0x72,0x79,0x73,0x74,0x77,0x79,0x74,0x68", + recipeConfig: [ + { + "op": "To Hex", + "args": [ + "0x", + 0, + true + ] + } + ] + }, + { + name: "ASCII to 0x Hex with comma and line breaks", + input: "aberystwyth", + expectedOutput: "0x61,0x62,0x65,0x72,\n0x79,0x73,0x74,0x77,\n0x79,0x74,0x68", + recipeConfig: [ + { + "op": "To Hex", + "args": [ + "0x", + 4, + true + ] + } + ] + }, + { + name: "Hex stream to UTF-8", + input: "e69591e69591e5ada9e5ad90", + expectedOutput: "救救孩子", + recipeConfig: [ + { + "op": "From Hex", + "args": [ + "Auto" + ] + } + ] + + }, + { + name: "Multiline 0x hex to ASCII", + input: "0x49,0x20,0x73,0x61,0x77,0x20,0x6d,0x79,0x73,0x65,0x6c,0x66,0x20,0x73,0x69,\ +0x74,0x74,0x69,0x6e,0x67,0x20,0x69,0x6e,0x20,0x74,0x68,0x65,0x20,0x63,0x72,\ +0x6f,0x74,0x63,0x68,0x20,0x6f,0x66,0x20,0x74,0x68,0x65,0x20,0x74,0x68,0x69,\ +0x73,0x20,0x66,0x69,0x67,0x20,0x74,0x72,0x65,0x65,0x2c,0x20,0x73,0x74,0x61,\ +0x72,0x76,0x69,0x6e,0x67,0x20,0x74,0x6f,0x20,0x64,0x65,0x61,0x74,0x68,0x2c,\ +0x20,0x6a,0x75,0x73,0x74,0x20,0x62,0x65,0x63,0x61,0x75,0x73,0x65,0x20,0x49,\ +0x20,0x63,0x6f,0x75,0x6c,0x64,0x6e,0x27,0x74,0x20,0x6d,0x61,0x6b,0x65,0x20,\ +0x75,0x70,0x20,0x6d,0x79,0x20,0x6d,0x69,0x6e,0x64,0x20,0x77,0x68,0x69,0x63,\ +0x68,0x20,0x6f,0x66,0x20,0x74,0x68,0x65,0x20,0x66,0x69,0x67,0x73,0x20,0x49,\ +0x20,0x77,0x6f,0x75,0x6c,0x64,0x20,0x63,0x68,0x6f,0x6f,0x73,0x65,0x2e", + expectedOutput: "I saw myself sitting in the crotch of the this fig tree, starving to death, just because I couldn't make up my mind which of the figs I would choose.", + recipeConfig: [ + { + "op": "From Hex", + "args": [ + "Auto" + ] + } + ] + + } +]); From 9a3464a5ec0f0e00dd7731e69faa9d2af1f68674 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Sat, 18 Jan 2020 13:19:28 +0000 Subject: [PATCH 07/21] Fix ingredient type conversion for null number --- src/core/Ingredient.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/Ingredient.mjs b/src/core/Ingredient.mjs index f74b42d6..da9c664b 100755 --- a/src/core/Ingredient.mjs +++ b/src/core/Ingredient.mjs @@ -113,6 +113,7 @@ class Ingredient { return data; } case "number": + if (data === null) return 0; number = parseFloat(data); if (isNaN(number)) { const sample = Utils.truncate(data.toString(), 10); From 293a95e938e120aa2d2f246240ea2d524d0e6497 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Sat, 18 Jan 2020 13:55:32 +0000 Subject: [PATCH 08/21] Remove tickbox and make 0x comma an option --- src/core/operations/ToHex.mjs | 50 ++++++++++++++++++++-------------- tests/operations/tests/Hex.mjs | 16 ++++------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/core/operations/ToHex.mjs b/src/core/operations/ToHex.mjs index 8c9297f5..25d4e059 100644 --- a/src/core/operations/ToHex.mjs +++ b/src/core/operations/ToHex.mjs @@ -5,7 +5,7 @@ */ import Operation from "../Operation.mjs"; -import {toHex, TO_HEX_DELIM_OPTIONS} from "../lib/Hex.mjs"; +import {toHex} from "../lib/Hex.mjs"; import Utils from "../Utils.mjs"; /** @@ -29,17 +29,12 @@ class ToHex extends Operation { { name: "Delimiter", type: "option", - value: TO_HEX_DELIM_OPTIONS + value: ["Space", "Percent", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF", "0x", "0x with comma", "\\x", "None"] }, { name: "Bytes per line", type: "number", value: 0 - }, - { - name: "Comma separated", - type: "boolean", - value: false } ]; } @@ -50,9 +45,14 @@ class ToHex extends Operation { * @returns {string} */ run(input, args) { - const delim = Utils.charRep(args[0] || "Space"); + let delim, comma; + if (args[0] === "0x with comma") { + delim = "0x"; + comma = ","; + } else { + delim = Utils.charRep(args[0] || "Space"); + } const lineSize = args[1]; - const comma = args[2] ? "," : ""; return toHex(new Uint8Array(input), delim, 2, comma, lineSize); } @@ -67,10 +67,16 @@ class ToHex extends Operation { * @returns {Object[]} pos */ highlight(pos, args) { - const delim = Utils.charRep(args[0] || "Space"), - lineSize = args[1], - comma = args[2], - len = (delim === "\r\n" ? 1 : delim.length) + (comma ? 1 : 0); + let delim, commaLen; + if (args[0] === "0x with comma") { + delim = "0x"; + commaLen = 1; + } else { + delim = Utils.charRep(args[0] || "Space"); + } + + const lineSize = args[1], + len = (delim === "\r\n" ? 1 : delim.length) + commaLen; const countLF = function(p) { // Count the number of LFs from 0 upto p @@ -85,9 +91,7 @@ class ToHex extends Operation { pos[0].end -= delim.length; } // if there is comma, trim the trailing comma - if (comma) { - pos[0].end--; - } + pos[0].end -= commaLen; return pos; } @@ -101,10 +105,16 @@ class ToHex extends Operation { * @returns {Object[]} pos */ highlightReverse(pos, args) { - const delim = Utils.charRep(args[0] || "Space"), - lineSize = args[1], - comma = args[2], - len = (delim === "\r\n" ? 1 : delim.length) + (comma ? 1 : 0), + let delim, commaLen; + if (args[0] === "0x with comma") { + delim = "0x"; + commaLen = 1; + } else { + delim = Utils.charRep(args[0] || "Space"); + } + + const lineSize = args[1], + len = (delim === "\r\n" ? 1 : delim.length) + commaLen, width = len + 2; const countLF = function(p) { diff --git a/tests/operations/tests/Hex.mjs b/tests/operations/tests/Hex.mjs index 9d55c411..91520d88 100644 --- a/tests/operations/tests/Hex.mjs +++ b/tests/operations/tests/Hex.mjs @@ -10,8 +10,7 @@ TestRegister.addTests([ "op": "To Hex", "args": [ "None", - 0, - false + 0 ] }, ] @@ -25,8 +24,7 @@ TestRegister.addTests([ "op": "To Hex", "args": [ "Colon", - 0, - false + 0 ] } ] @@ -39,9 +37,8 @@ TestRegister.addTests([ { "op": "To Hex", "args": [ - "0x", - 0, - true + "0x with comma", + 0 ] } ] @@ -54,9 +51,8 @@ TestRegister.addTests([ { "op": "To Hex", "args": [ - "0x", - 4, - true + "0x with comma", + 4 ] } ] From 1197859865ccc9dd7b31ee68b95ce101f5edc4c5 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Sat, 18 Jan 2020 14:56:17 +0000 Subject: [PATCH 09/21] Preserve null data when type is number in prepare --- src/core/Ingredient.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/Ingredient.mjs b/src/core/Ingredient.mjs index da9c664b..d64bf763 100755 --- a/src/core/Ingredient.mjs +++ b/src/core/Ingredient.mjs @@ -113,7 +113,7 @@ class Ingredient { return data; } case "number": - if (data === null) return 0; + if (data === null) return data; number = parseFloat(data); if (isNaN(number)) { const sample = Utils.truncate(data.toString(), 10); From 4b6cebc0689fc1f1c1729fb455cb69449a71a555 Mon Sep 17 00:00:00 2001 From: retnikt <_@retnikt.uk> Date: Mon, 27 Jan 2020 18:55:50 +0000 Subject: [PATCH 10/21] allow custom ports for Grunt tasks --- Gruntfile.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index 1a504d82..1a9e3f2f 100755 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -219,6 +219,7 @@ module.exports = function (grunt) { options: { webpack: webpackConfig, host: "0.0.0.0", + port: grunt.option("port") || 8080, disableHostCheck: true, overlay: true, inline: false, @@ -275,7 +276,7 @@ module.exports = function (grunt) { connect: { prod: { options: { - port: 8000, + port: grunt.option("port") || 8000, base: "build/prod/" } } From 4430ea55c47f2a7ab4dc3ac8c47bd964145de564 Mon Sep 17 00:00:00 2001 From: comet Date: Mon, 27 Jan 2020 17:02:13 -0600 Subject: [PATCH 11/21] update --- src/core/vendor/gost/gostEngine.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/vendor/gost/gostEngine.mjs b/src/core/vendor/gost/gostEngine.mjs index fb68a791..b54819c6 100755 --- a/src/core/vendor/gost/gostEngine.mjs +++ b/src/core/vendor/gost/gostEngine.mjs @@ -383,7 +383,7 @@ if (root.importScripts) { * method with data parameter: algorithm, method and arg.
* Call method execute and postMessage() results to onmessage event handler * in the main process.
- * If error occured onerror event handler executed in main process. + * If error occurred onerror event handler executed in main process. * * @memberOf gostEngine * @name onmessage From 1509b2b96cecbe5202e8d43471d29330b9e7cb90 Mon Sep 17 00:00:00 2001 From: Flavio Diez Date: Wed, 29 Jan 2020 12:46:38 +0100 Subject: [PATCH 12/21] Implemented the Rail Fence Cipher with both encoding and decoding --- src/core/config/Categories.json | 2 + src/core/operations/RailFenceCipherDecode.mjs | 87 ++++++++++++++ src/core/operations/RailFenceCipherEncode.mjs | 73 ++++++++++++ tests/operations/tests/Ciphers.mjs | 110 ++++++++++++++++++ 4 files changed, 272 insertions(+) create mode 100644 src/core/operations/RailFenceCipherDecode.mjs create mode 100644 src/core/operations/RailFenceCipherEncode.mjs diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json index 53ca796d..0d68efe8 100755 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -95,6 +95,8 @@ "Affine Cipher Decode", "A1Z26 Cipher Encode", "A1Z26 Cipher Decode", + "Rail Fence Cipher Encode", + "Rail Fence Cipher Decode", "Atbash Cipher", "Substitute", "Derive PBKDF2 key", diff --git a/src/core/operations/RailFenceCipherDecode.mjs b/src/core/operations/RailFenceCipherDecode.mjs new file mode 100644 index 00000000..5280bb1a --- /dev/null +++ b/src/core/operations/RailFenceCipherDecode.mjs @@ -0,0 +1,87 @@ +/** + * @author Flavio Diez [flaviofdiez+cyberchef@gmail.com] + * @copyright Crown Copyright 2020 + * @license Apache-2.0 + */ + +import Operation from "../Operation.mjs"; + +/** + * Rail Fence Cipher Decode operation + */ +class RailFenceCipherDecode extends Operation { + + /** + * RailFenceCipherDecode constructor + */ + constructor() { + super(); + + this.name = "Rail Fence Cipher Decode"; + this.module = "Ciphers"; + this.description = "Decodes Strings that were created using the Rail fence Cipher provided a key and an offset"; + this.infoURL = "https://en.wikipedia.org/wiki/Rail_fence_cipher"; + this.inputType = "string"; + this.outputType = "string"; + this.args = [ + { + name: "Key", + type: "number", + value: 2 + }, + { + name: "Offset", + type: "number", + value: 0 + } + ]; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + const [key, offset] = args; + + let cipher = input; + + if (key < 2) { + return "Key has to be bigger than 2"; + } else if (key > cipher.length) { + return "Key should be smaller than the cipher's length"; + } + + if (offset < 0) { + return "Offset has to be a positive integer"; + } + + const cycle = (key - 1) * 2; + + const rest = cipher.length % key; + + if (rest !== 0) { + cipher = cipher + (" ".repeat(key - rest)); + } + + const plaintext = new Array(cipher.length); + + let j = 0; + let x, y; + + for (y = 0; y < key; y++) { + for (x = 0; x < cipher.length; x++) { + if ((y + x + offset) % cycle === 0 || (y - x - offset) % cycle === 0) { + plaintext[x] = cipher[j++]; + } + } + } + + return plaintext.join("").trim(); + } + +} + + +export default RailFenceCipherDecode; diff --git a/src/core/operations/RailFenceCipherEncode.mjs b/src/core/operations/RailFenceCipherEncode.mjs new file mode 100644 index 00000000..5d9d5eb1 --- /dev/null +++ b/src/core/operations/RailFenceCipherEncode.mjs @@ -0,0 +1,73 @@ +/** + * @author Flavio Diez [flaviofdiez+cyberchef@gmail.com] + * @copyright Crown Copyright 2020 + * @license Apache-2.0 + */ + +import Operation from "../Operation.mjs"; + +/** + * Rail Fence Cipher Encode operation + */ +class RailFenceCipherEncode extends Operation { + + /** + * RailFenceCipherEncode constructor + */ + constructor() { + super(); + + this.name = "Rail Fence Cipher Encode"; + this.module = "Ciphers"; + this.description = "Encodes Strings using the Rail fence Cipher provided a key and an offset"; + this.infoURL = "https://en.wikipedia.org/wiki/Rail_fence_cipher"; + this.inputType = "string"; + this.outputType = "string"; + this.args = [ + { + name: "Key", + type: "number", + value: 2 + }, + { + name: "Offset", + type: "number", + value: 0 + } + ]; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + const [key, offset] = args; + + const plaintext = input; + if (key < 2) { + return "Key has to be bigger than 2"; + } else if (key > plaintext.length) { + return "Key should be smaller than the plain text's length"; + } + + if (offset < 0) { + return "Offset has to be a positive integer"; + } + + const cycle = (key - 1) * 2; + const rows = new Array(key).fill(""); + + for (let pos = 0; pos < plaintext.length; pos++) { + const rowIdx = key - 1 - Math.abs(cycle / 2 - (pos + offset) % cycle); + + rows[rowIdx] += plaintext[pos]; + } + + return rows.join("").trim(); + } + +} + +export default RailFenceCipherEncode; diff --git a/tests/operations/tests/Ciphers.mjs b/tests/operations/tests/Ciphers.mjs index 62cbaa54..47453cf7 100644 --- a/tests/operations/tests/Ciphers.mjs +++ b/tests/operations/tests/Ciphers.mjs @@ -418,4 +418,114 @@ TestRegister.addTests([ } ], }, + { + name: "Rail Fence Cipher Decode: normal", + input: "Cytgah sTEAto rtn rsligcdsrporpyi H r fWiigo ovn oe", + expectedOutput: "Cryptography is THE Art of Writing or solving codes", + recipeConfig: [ + { + "op": "Rail Fence Cipher Decode", + "args": [2, 0] + } + ], + }, + { + name: "Rail Fence Cipher Decode: key has to be bigger than 2", + input: "Cytgah sTEAto rtn rsligcdsrporpyi H r fWiigo ovn oe", + expectedOutput: "Key has to be bigger than 2", + recipeConfig: [ + { + "op": "Rail Fence Cipher Decode", + "args": [1, 0] + } + ], + }, + { + name: "Rail Fence Cipher Decode: key has to be smaller than input's length", + input: "shortinput", + expectedOutput: "Key should be smaller than the cipher's length", + recipeConfig: [ + { + "op": "Rail Fence Cipher Decode", + "args": [22, 0] + } + ], + }, + { + name: "Rail Fence Cipher Decode: offset should be positive", + input: "shortinput", + expectedOutput: "Offset has to be a positive integer", + recipeConfig: [ + { + "op": "Rail Fence Cipher Decode", + "args": [2, -1] + } + ], + }, + { + name: "Rail Fence Cipher Decode: Normal with Offset non-null", + input: "51746026813793592840", + expectedOutput: "12345678901234567890", + recipeConfig: [ + { + "op": "Rail Fence Cipher Decode", + "args": [4, 2] + } + ], + }, + { + name: "Rail Fence Cipher Encode: normal", + input: "Cryptography is THE Art of Writing or solving codes", + expectedOutput: "Cytgah sTEAto rtn rsligcdsrporpyi H r fWiigo ovn oe", + recipeConfig: [ + { + "op": "Rail Fence Cipher Encode", + "args": [2, 0] + } + ], + }, + { + name: "Rail Fence Cipher Encode: key has to be bigger than 2", + input: "Cryptography is THE Art of Writing or solving codes", + expectedOutput: "Key has to be bigger than 2", + recipeConfig: [ + { + "op": "Rail Fence Cipher Encode", + "args": [1, 0] + } + ], + }, + { + name: "Rail Fence Cipher Encode: key has to be smaller than input's length", + input: "shortinput", + expectedOutput: "Key should be smaller than the plain text's length", + recipeConfig: [ + { + "op": "Rail Fence Cipher Encode", + "args": [22, 0] + } + ], + }, + { + name: "Rail Fence Cipher Encode: offset should be positive", + input: "shortinput", + expectedOutput: "Offset has to be a positive integer", + recipeConfig: [ + { + "op": "Rail Fence Cipher Encode", + "args": [2, -1] + } + ], + }, + { + name: "Rail Fence Cipher Encode: Normal with Offset non-null", + input: "12345678901234567890", + expectedOutput: "51746026813793592840", + recipeConfig: [ + { + "op": "Rail Fence Cipher Encode", + "args": [4, 2] + } + ], + }, ]); From 0ab96dd4ca19c61f5d20c56d858908c8f5ecf883 Mon Sep 17 00:00:00 2001 From: Flavio Diez Date: Wed, 29 Jan 2020 14:16:04 +0100 Subject: [PATCH 13/21] Throw OperationError instead of returning a String --- src/core/operations/RailFenceCipherDecode.mjs | 7 ++++--- src/core/operations/RailFenceCipherEncode.mjs | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/core/operations/RailFenceCipherDecode.mjs b/src/core/operations/RailFenceCipherDecode.mjs index 5280bb1a..7317b438 100644 --- a/src/core/operations/RailFenceCipherDecode.mjs +++ b/src/core/operations/RailFenceCipherDecode.mjs @@ -5,6 +5,7 @@ */ import Operation from "../Operation.mjs"; +import OperationError from "../errors/OperationError.mjs"; /** * Rail Fence Cipher Decode operation @@ -48,13 +49,13 @@ class RailFenceCipherDecode extends Operation { let cipher = input; if (key < 2) { - return "Key has to be bigger than 2"; + throw new OperationError("Key has to be bigger than 2"); } else if (key > cipher.length) { - return "Key should be smaller than the cipher's length"; + throw new OperationError("Key should be smaller than the cipher's length"); } if (offset < 0) { - return "Offset has to be a positive integer"; + throw new OperationError("Offset has to be a positive integer"); } const cycle = (key - 1) * 2; diff --git a/src/core/operations/RailFenceCipherEncode.mjs b/src/core/operations/RailFenceCipherEncode.mjs index 5d9d5eb1..af3a0016 100644 --- a/src/core/operations/RailFenceCipherEncode.mjs +++ b/src/core/operations/RailFenceCipherEncode.mjs @@ -5,6 +5,7 @@ */ import Operation from "../Operation.mjs"; +import OperationError from "../errors/OperationError.mjs"; /** * Rail Fence Cipher Encode operation @@ -47,13 +48,13 @@ class RailFenceCipherEncode extends Operation { const plaintext = input; if (key < 2) { - return "Key has to be bigger than 2"; + throw new OperationError("Key has to be bigger than 2"); } else if (key > plaintext.length) { - return "Key should be smaller than the plain text's length"; + throw new OperationError("Key should be smaller than the plain text's length"); } if (offset < 0) { - return "Offset has to be a positive integer"; + throw new OperationError("Offset has to be a positive integer"); } const cycle = (key - 1) * 2; From 7a58567659b7e6ce6553cccd173e17c424858264 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Thu, 13 Feb 2020 12:54:05 +0000 Subject: [PATCH 14/21] Updated chromedriver version --- package-lock.json | 310 ++++++++++++++++++++++++++++++++++++++++++++-- package.json | 4 +- 2 files changed, 299 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index e41e4fff..708a8880 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2514,6 +2514,38 @@ "core-js": "^3.4.1" } }, + "@nodelib/fs.scandir": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.3.tgz", + "integrity": "sha512-eGmwYQn3gxo4r7jdQnkrrN6bY478C3P+a/y72IJukF8LjB6ZHeB3c+Ehacj3sYeSmUXGlnA67/PmbM9CVwL7Dw==", + "dev": true, + "requires": { + "@nodelib/fs.stat": "2.0.3", + "run-parallel": "^1.1.9" + } + }, + "@nodelib/fs.stat": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.3.tgz", + "integrity": "sha512-bQBFruR2TAwoevBEd/NWMoAAtNGzTRgdrqnYCc7dhzfoNvqPzLyqlEQnzZ3kVnNrSp25iyxE00/3h2fqGAGArA==", + "dev": true + }, + "@nodelib/fs.walk": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.4.tgz", + "integrity": "sha512-1V9XOY4rDW0rehzbrcqAmHnz8e7SKvX27gh8Gt2WgB0+pdzdiLV83p72kZPU+jvMbS1qU5mauP2iOvO8rhmurQ==", + "dev": true, + "requires": { + "@nodelib/fs.scandir": "2.1.3", + "fastq": "^1.6.0" + } + }, + "@testim/chrome-version": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/@testim/chrome-version/-/chrome-version-1.0.7.tgz", + "integrity": "sha512-8UT/J+xqCYfn3fKtOznAibsHpiuDshCb0fwgWxRazTT19Igp9ovoXMPhXyLD6m3CKQGTMHgqoxaFfMWaL40Rnw==", + "dev": true + }, "@types/color-name": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", @@ -2868,6 +2900,24 @@ } } }, + "aggregate-error": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.0.1.tgz", + "integrity": "sha512-quoaXsZ9/BLNae5yiNoUz+Nhkwz83GhWwtYFglcjEQB2NDHCIpApbqXxIFnm4Pq/Nvhrsq5sYJFyohrrxnTGAA==", + "dev": true, + "requires": { + "clean-stack": "^2.0.0", + "indent-string": "^4.0.0" + }, + "dependencies": { + "indent-string": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", + "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==", + "dev": true + } + } + }, "ajv": { "version": "6.5.5", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.5.5.tgz", @@ -4146,18 +4196,59 @@ } }, "chromedriver": { - "version": "78.0.1", - "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-78.0.1.tgz", - "integrity": "sha512-eOsyFk4xb9EECs1VMrDbxO713qN+Bu1XUE8K9AuePc3839TPdAegg72kpXSzkeNqRNZiHbnJUItIVCLFkDqceA==", + "version": "80.0.1", + "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-80.0.1.tgz", + "integrity": "sha512-VfRtZUpBUIjeypS+xM40+VD9g4Drv7L2VibG/4+0zX3mMx4KayN6gfKETycPfO6JwQXTLSxEr58fRcrsa8r5xQ==", "dev": true, "requires": { - "del": "^4.1.1", + "@testim/chrome-version": "^1.0.7", + "axios": "^0.19.2", + "del": "^5.1.0", "extract-zip": "^1.6.7", - "mkdirp": "^0.5.1", - "request": "^2.88.0", + "mkdirp": "^1.0.3", "tcp-port-used": "^1.0.1" }, "dependencies": { + "array-union": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", + "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", + "dev": true + }, + "axios": { + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz", + "integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==", + "dev": true, + "requires": { + "follow-redirects": "1.5.10" + } + }, + "del": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/del/-/del-5.1.0.tgz", + "integrity": "sha512-wH9xOVHnczo9jN2IW68BabcecVPxacIA3g/7z6vhSU/4stOKQzeCRK0yD0A24WiAAUJmmVpWqrERcTxnLo3AnA==", + "dev": true, + "requires": { + "globby": "^10.0.1", + "graceful-fs": "^4.2.2", + "is-glob": "^4.0.1", + "is-path-cwd": "^2.2.0", + "is-path-inside": "^3.0.1", + "p-map": "^3.0.0", + "rimraf": "^3.0.0", + "slash": "^3.0.0" + } + }, + "dir-glob": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", + "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", + "dev": true, + "requires": { + "path-type": "^4.0.0" + } + }, "extract-zip": { "version": "1.6.7", "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.6.7.tgz", @@ -4168,7 +4259,94 @@ "debug": "2.6.9", "mkdirp": "0.5.1", "yauzl": "2.4.1" + }, + "dependencies": { + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, + "requires": { + "minimist": "0.0.8" + } + } } + }, + "globby": { + "version": "10.0.2", + "resolved": "https://registry.npmjs.org/globby/-/globby-10.0.2.tgz", + "integrity": "sha512-7dUi7RvCoT/xast/o/dLN53oqND4yk0nsHkhRgn9w65C4PofCLOoJ39iSOg+qVDdWQPIEj+eszMHQ+aLVwwQSg==", + "dev": true, + "requires": { + "@types/glob": "^7.1.1", + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.0.3", + "glob": "^7.1.3", + "ignore": "^5.1.1", + "merge2": "^1.2.3", + "slash": "^3.0.0" + } + }, + "graceful-fs": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.3.tgz", + "integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ==", + "dev": true + }, + "ignore": { + "version": "5.1.4", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.4.tgz", + "integrity": "sha512-MzbUSahkTW1u7JpKKjY7LCARd1fU5W2rLdxlM4kdkayuCwZImjkpluF9CM1aLewYJguPDqewLam18Y6AU69A8A==", + "dev": true + }, + "is-path-inside": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.2.tgz", + "integrity": "sha512-/2UGPSgmtqwo1ktx8NDHjuPwZWmHhO+gj0f93EkhLB5RgW9RZevWYYlIkS6zePc6U2WpOdQYIwHe9YC4DWEBVg==", + "dev": true + }, + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + }, + "mkdirp": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.3.tgz", + "integrity": "sha512-6uCP4Qc0sWsgMLy1EOqqS/3rjDHOEnsStVr/4vtAIK2Y5i2kA7lFFejYrpIyiN9w0pYf4ckeCYT9f1r1P9KX5g==", + "dev": true + }, + "p-map": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/p-map/-/p-map-3.0.0.tgz", + "integrity": "sha512-d3qXVTF/s+W+CdJ5A29wywV2n8CQQYahlgz2bFiA+4eVNJbHJodPZ+/gXwPGh0bOqA+j8S+6+ckmvLGPk1QpxQ==", + "dev": true, + "requires": { + "aggregate-error": "^3.0.0" + } + }, + "path-type": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", + "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", + "dev": true + }, + "rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, + "slash": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", + "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", + "dev": true } } }, @@ -4220,6 +4398,12 @@ "source-map": "~0.6.0" } }, + "clean-stack": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", + "integrity": "sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==", + "dev": true + }, "cli-cursor": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", @@ -6709,6 +6893,73 @@ "integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=", "dev": true }, + "fast-glob": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.1.1.tgz", + "integrity": "sha512-nTCREpBY8w8r+boyFYAx21iL6faSsQynliPHM4Uf56SbkyohCNxpVPEH9xrF5TXKy+IsjkPUHDKiUkzBVRXn9g==", + "dev": true, + "requires": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.0", + "merge2": "^1.3.0", + "micromatch": "^4.0.2" + }, + "dependencies": { + "braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "requires": { + "fill-range": "^7.0.1" + } + }, + "fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "requires": { + "to-regex-range": "^5.0.1" + } + }, + "glob-parent": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.0.tgz", + "integrity": "sha512-qjtRgnIVmOfnKUE3NJAQEdk+lKrxfw8t5ke7SXtfMTHcjsBfOfWXCQfdb30zfDoZQ2IRSIiidmjtbHZPZ++Ihw==", + "dev": true, + "requires": { + "is-glob": "^4.0.1" + } + }, + "is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true + }, + "micromatch": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.2.tgz", + "integrity": "sha512-y7FpHSbMUMoyPbYUSzO6PaZ6FyRnQOpHuKwbo1G+Knck95XVU4QAiKdGEnj5wwoS7PlOgthX/09u5iFJ+aYf5Q==", + "dev": true, + "requires": { + "braces": "^3.0.1", + "picomatch": "^2.0.5" + } + }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "requires": { + "is-number": "^7.0.0" + } + } + } + }, "fast-json-stable-stringify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", @@ -6720,6 +6971,15 @@ "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=" }, + "fastq": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.6.0.tgz", + "integrity": "sha512-jmxqQ3Z/nXoeyDmWAzF9kH1aGZSis6e/SbfPmJpUnyZ0ogr6iscHQaml4wsEepEWSdtmpy+eVXmCRIMpxaXqOA==", + "dev": true, + "requires": { + "reusify": "^1.0.0" + } + }, "faye-websocket": { "version": "0.10.0", "resolved": "https://registry.npmjs.org/faye-websocket/-/faye-websocket-0.10.0.tgz", @@ -10214,6 +10474,12 @@ "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=", "dev": true }, + "merge2": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.3.0.tgz", + "integrity": "sha512-2j4DAdlBOkiSZIsaXk4mTE3sRS02yBHAtfy127xRV3bQUFqXkjHCHLW6Scv7DwNRbIWNHH8zpnz9zMaKXIdvYw==", + "dev": true + }, "methods": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", @@ -10778,9 +11044,9 @@ "dev": true }, "nightwatch": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/nightwatch/-/nightwatch-1.3.2.tgz", - "integrity": "sha512-1Lcte2Su/JrzET62va4oVLbSXwZkZaTmxTdjShylio3U+woY6U250iNuQz/bOkL+Qvuw+9Vfp+5T13yT0YfsKg==", + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/nightwatch/-/nightwatch-1.3.4.tgz", + "integrity": "sha512-27zWPjmBsHu3IDKc6QTQdRKbTWx4WuTUXbCOT1Wa8Ovxbv+3TZ7GCd9Dt9wm14ElO9Db9/PKVk8JIWThkqGRZA==", "dev": true, "requires": { "assertion-error": "^1.1.0", @@ -11343,7 +11609,7 @@ "dependencies": { "minimist": { "version": "0.0.10", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=", "dev": true }, @@ -11391,9 +11657,9 @@ "dev": true }, "ansi-styles": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.0.tgz", - "integrity": "sha512-7kFQgnEaMdRtwf6uSfUnVr9gSGC7faurn+J/Mv90/W+iTtN0405/nLdopfMWwchyxhbGYl6TC4Sccn9TUkGAgg==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", + "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", "dev": true, "requires": { "@types/color-name": "^1.1.1", @@ -11945,6 +12211,12 @@ "resolved": "https://registry.npmjs.org/phin/-/phin-2.9.3.tgz", "integrity": "sha512-CzFr90qM24ju5f88quFC/6qohjC144rehe5n6DH900lgXmUe86+xCKc10ev56gRKC4/BkHUoG4uSiQgBiIXwDA==" }, + "picomatch": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.1.tgz", + "integrity": "sha512-ISBaA8xQNmwELC7eOjqFKMESB2VIqt4PPDD0nsS95b/9dZXvVKOlz9keMSnoGGKcOHXfTvDD6WMaRoSc9UuhRA==", + "dev": true + }, "pify": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz", @@ -13050,6 +13322,12 @@ "integrity": "sha1-G0KmJmoh8HQh0bC1S33BZ7AcATs=", "dev": true }, + "reusify": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", + "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", + "dev": true + }, "revalidator": { "version": "0.1.8", "resolved": "https://registry.npmjs.org/revalidator/-/revalidator-0.1.8.tgz", @@ -13084,6 +13362,12 @@ "is-promise": "^2.1.0" } }, + "run-parallel": { + "version": "1.1.9", + "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.1.9.tgz", + "integrity": "sha512-DEqnSRTDw/Tc3FXf49zedI638Z9onwUotBMiUFKmrO2sdFKIbXamXGQ3Axd4qgphxKB4kw/qP1w5kTxnfU1B9Q==", + "dev": true + }, "run-queue": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/run-queue/-/run-queue-1.0.3.tgz", diff --git a/package.json b/package.json index fe6b41be..bb2f862a 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "babel-eslint": "^10.0.3", "babel-loader": "^8.0.6", "babel-plugin-dynamic-import-node": "^2.3.0", - "chromedriver": "^78.0.1", + "chromedriver": "^80.0.1", "colors": "^1.4.0", "copy-webpack-plugin": "^5.0.5", "css-loader": "^3.2.1", @@ -65,7 +65,7 @@ "html-webpack-plugin": "^3.2.0", "imports-loader": "^0.8.0", "mini-css-extract-plugin": "^0.8.0", - "nightwatch": "^1.3.2", + "nightwatch": "^1.3.4", "node-sass": "^4.13.0", "postcss-css-variables": "^0.14.0", "postcss-import": "^12.0.1", From c2212f9ab36cb41672fb2f7946501d2532f4f424 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Thu, 13 Feb 2020 14:17:43 +0000 Subject: [PATCH 15/21] Tidied up To Hex mods --- src/core/lib/Hex.mjs | 11 ++++------- src/core/operations/ToHex.mjs | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/core/lib/Hex.mjs b/src/core/lib/Hex.mjs index 0108eabd..9c70e91c 100644 --- a/src/core/lib/Hex.mjs +++ b/src/core/lib/Hex.mjs @@ -36,11 +36,8 @@ export function toHex(data, delim=" ", padding=2, extraDelim="", lineSize=0) { for (let i = 0; i < data.length; i++) { const hex = data[i].toString(16).padStart(padding, "0"); - if (prepend) { - output += delim + hex; - } else { - output += hex + delim; - } + output += prepend ? delim + hex : hex + delim; + if (extraDelim) { output += extraDelim; } @@ -50,7 +47,7 @@ export function toHex(data, delim=" ", padding=2, extraDelim="", lineSize=0) { } } - // Remove the extraDelim at the end (if there is); + // Remove the extraDelim at the end (if there is one) // and remove the delim at the end, but if it's prepended there's nothing to remove const rTruncLen = extraDelim.length + (prepend ? 0 : delim.length); if (rTruncLen) { @@ -119,7 +116,7 @@ export function fromHex(data, delim="Auto", byteLen=2) { /** * To Hexadecimal delimiters. */ -export const TO_HEX_DELIM_OPTIONS = ["Space", "Percent", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF", "0x", "\\x", "None"]; +export const TO_HEX_DELIM_OPTIONS = ["Space", "Percent", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF", "0x", "0x with comma", "\\x", "None"]; /** diff --git a/src/core/operations/ToHex.mjs b/src/core/operations/ToHex.mjs index 25d4e059..2e97de8f 100644 --- a/src/core/operations/ToHex.mjs +++ b/src/core/operations/ToHex.mjs @@ -5,7 +5,7 @@ */ import Operation from "../Operation.mjs"; -import {toHex} from "../lib/Hex.mjs"; +import {toHex, TO_HEX_DELIM_OPTIONS} from "../lib/Hex.mjs"; import Utils from "../Utils.mjs"; /** @@ -29,7 +29,7 @@ class ToHex extends Operation { { name: "Delimiter", type: "option", - value: ["Space", "Percent", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF", "0x", "0x with comma", "\\x", "None"] + value: TO_HEX_DELIM_OPTIONS }, { name: "Bytes per line", From d7cc6c736317db72788107f6c869371423416a61 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Thu, 13 Feb 2020 14:18:12 +0000 Subject: [PATCH 16/21] 9.12.1 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 708a8880..e8c3e9f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "cyberchef", - "version": "9.12.0", + "version": "9.12.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index bb2f862a..40fd91c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cyberchef", - "version": "9.12.0", + "version": "9.12.1", "description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.", "author": "n1474335 ", "homepage": "https://gchq.github.io/CyberChef", From b045dc37f53e9643749bb8234a317bffba6f0fbf Mon Sep 17 00:00:00 2001 From: n1474335 Date: Thu, 13 Feb 2020 15:05:33 +0000 Subject: [PATCH 17/21] Tidied up infoURL in Rail Fence Cipher ops --- src/core/operations/RailFenceCipherDecode.mjs | 2 +- src/core/operations/RailFenceCipherEncode.mjs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/operations/RailFenceCipherDecode.mjs b/src/core/operations/RailFenceCipherDecode.mjs index 7317b438..d98742b8 100644 --- a/src/core/operations/RailFenceCipherDecode.mjs +++ b/src/core/operations/RailFenceCipherDecode.mjs @@ -21,7 +21,7 @@ class RailFenceCipherDecode extends Operation { this.name = "Rail Fence Cipher Decode"; this.module = "Ciphers"; this.description = "Decodes Strings that were created using the Rail fence Cipher provided a key and an offset"; - this.infoURL = "https://en.wikipedia.org/wiki/Rail_fence_cipher"; + this.infoURL = "https://wikipedia.org/wiki/Rail_fence_cipher"; this.inputType = "string"; this.outputType = "string"; this.args = [ diff --git a/src/core/operations/RailFenceCipherEncode.mjs b/src/core/operations/RailFenceCipherEncode.mjs index af3a0016..03651f85 100644 --- a/src/core/operations/RailFenceCipherEncode.mjs +++ b/src/core/operations/RailFenceCipherEncode.mjs @@ -21,7 +21,7 @@ class RailFenceCipherEncode extends Operation { this.name = "Rail Fence Cipher Encode"; this.module = "Ciphers"; this.description = "Encodes Strings using the Rail fence Cipher provided a key and an offset"; - this.infoURL = "https://en.wikipedia.org/wiki/Rail_fence_cipher"; + this.infoURL = "https://wikipedia.org/wiki/Rail_fence_cipher"; this.inputType = "string"; this.outputType = "string"; this.args = [ From 3ecbe22d99ef619a8fd091f3bfc1c7c14591bd14 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Thu, 13 Feb 2020 15:08:54 +0000 Subject: [PATCH 18/21] Updated CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00c96618..86ba6848 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). +### [9.13.0] - 2020-02-13 +- 'Rail Fence Cipher Encode' and 'Rail Fence Cipher Decode' operations added [@Flavsditz] | [#948] + ### [9.12.0] - 2019-12-20 - 'Normalise Unicode' operation added [@matthieuxyz] | [#912] @@ -200,6 +203,7 @@ All major and minor version changes will be documented in this file. Details of +[9.13.0]: https://github.com/gchq/CyberChef/releases/tag/v9.13.0 [9.12.0]: https://github.com/gchq/CyberChef/releases/tag/v9.12.0 [9.11.0]: https://github.com/gchq/CyberChef/releases/tag/v9.11.0 [9.10.0]: https://github.com/gchq/CyberChef/releases/tag/v9.10.0 @@ -286,6 +290,7 @@ All major and minor version changes will be documented in this file. Details of [@VirtualColossus]: https://github.com/VirtualColossus [@cbeuw]: https://github.com/cbeuw [@matthieuxyz]: https://github.com/matthieuxyz +[@Flavsditz]: https://github.com/Flavsditz [#95]: https://github.com/gchq/CyberChef/pull/299 [#173]: https://github.com/gchq/CyberChef/pull/173 @@ -350,3 +355,4 @@ All major and minor version changes will be documented in this file. Details of [#653]: https://github.com/gchq/CyberChef/pull/653 [#865]: https://github.com/gchq/CyberChef/pull/865 [#912]: https://github.com/gchq/CyberChef/pull/912 +[#948]: https://github.com/gchq/CyberChef/pull/948 From cf1349ccb27d82c2ecd983d3202ef74aa96f7996 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Thu, 13 Feb 2020 15:09:19 +0000 Subject: [PATCH 19/21] 9.13.0 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index e8c3e9f7..ad92ad80 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "cyberchef", - "version": "9.12.1", + "version": "9.13.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 40fd91c8..b7fc6ea8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cyberchef", - "version": "9.12.1", + "version": "9.13.0", "description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.", "author": "n1474335 ", "homepage": "https://gchq.github.io/CyberChef", From d5615b90bbc56f22999a44a988f9301addab3738 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Thu, 13 Feb 2020 16:14:02 +0000 Subject: [PATCH 20/21] Updated .travis.yml --- .travis.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3cfad188..d97e8eb8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: node_js node_js: - lts/dubnium cache: npm +os: linux addons: chrome: stable install: npm install @@ -19,16 +20,14 @@ before_deploy: - grunt copy:ghPages deploy: - provider: pages - skip_cleanup: true - github_token: $GITHUB_TOKEN + token: $GITHUB_TOKEN local_dir: build/prod/ target_branch: gh-pages on: repo: gchq/CyberChef branch: master - provider: releases - skip_cleanup: true - api_key: + token: secure: "HV1WSKv4l/0Y2bKKs1iBJocBcmLj08PCRUeEM/jTwA4jqJ8EiLHWiXtER/D5sEg2iibRVKd2OQjfrmS6bo4AiwdeVgAKmv0FtS2Jw+391N8Nd5AkEANHa5Om/IpHLTL2YRAjpJTsDpY72bMUTJIwjQA3TFJkgrpOw6KYfohOcgbxLpZ4XuNJRU3VL4Hsxdv5V9aOVmfFOmMOVPQlakXy7NgtW5POp1f2WJwgcZxylkR1CjwaqMyXmSoVl46pyH3tr5+dptsQoKSGdi6sIHGA60oDotFPcm+0ifa47wZw+vapuuDi4tdNxhrHGaDMG8xiE0WFDHwQUDlk2/+W7j9SEX0H3Em7us371JXRp56EDwEcDa34VpVkC6i8HGcHK55hnxVbMZXGf3qhOFD8wY7qMbjMRvIpucrMHBi86OfkDfv0vDj2LyvIl5APj/AX50BrE0tfH1MZbH26Jkx4NdlkcxQ14GumarmUqfmVvbX/fsoA6oUuAAE9ZgRRi3KHO4wci6KUcRfdm+XOeUkaBFsL86G3EEYIvrtBTuaypdz+Cx7nd1iPZyWMx5Y1gXnVzha4nBdV4+7l9JIsFggD8QVpw2uHXQiS1KXFjOeqA3DBD8tjMB7q26Fl2fD3jkOo4BTbQ2NrRIZUu/iL+fOmMPsyMt2qulB0yaSBCfkbEq8xrUA=" file_glob: true file: @@ -38,9 +37,8 @@ deploy: repo: gchq/CyberChef tags: true - provider: npm - skip_cleanup: true email: "n1474335@gmail.com" - api_key: + api_token: secure: "UnDQL3Kh+GK2toL0TK3FObO0ujVssU3Eg4BBuYdjwLB81GhiGE5/DTh7THdZPOpbLo6wQeOwfZDuMeKC1OU+0Uf4NsdYFu1aq6xMO20qBQ4qUfgsyiK4Qgywj9gk0p1+OFZdGAZ/j1CNRAaF71XQIY6iV84c+SO4WoizXYrNT0Jh4sr2DA4/97G2xmJtPi0qOzYrJ09R56ZUozmqeik5G0pMRIuJRbpjS/7bZXV+N7WV0ombZc9RkUaetbabEVOLQ+Xx5YAIVq+VuEeMe9VBSnxY/FfCLmy1wJsjGzpLCyBI9nbrG4nw8Wgc2m8NfK9rcpIvBTGner9r2j60NVDkZ8kLZPrqXhq6AZMwa+oz6K5UQCqRo2RRQzSGwXxg67HY5Tcq+oNmjd+DqpPg4LZ3eGlluyP5XfG+hpSr9Ya4d8q8SrUWLxkoLHI6ZKMtoKFbTCSSQPiluW5hsZxjz3yDkkjsJw64M/EM8UyJrgaXqDklQu+7rBGKLfsK6os7RDiqjBWpQ7gwpo8HvY0O8yqEAabPz+QGkanpjcCOZCXFbSkzWxYy37RMAPu88iINVZVlZE4l+WJenCpZY95ueyy0mG9cyMSzVRPyX6A+/n4H6VMFPFjpGDLTD588ACEjY1lmHfS/eXwXJcgqPPD2gW0XdRdUheU/ssqlfCfGWQMTDXs=" on: tags: true From ab6576d7394321aec56107cdfa31d504df66bbd0 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Thu, 13 Feb 2020 16:31:44 +0000 Subject: [PATCH 21/21] Travis config now uses dpl v2 --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index d97e8eb8..a67e99b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,7 @@ before_deploy: - grunt copy:ghPages deploy: - provider: pages + edge: true token: $GITHUB_TOKEN local_dir: build/prod/ target_branch: gh-pages @@ -27,6 +28,7 @@ deploy: repo: gchq/CyberChef branch: master - provider: releases + edge: true token: secure: "HV1WSKv4l/0Y2bKKs1iBJocBcmLj08PCRUeEM/jTwA4jqJ8EiLHWiXtER/D5sEg2iibRVKd2OQjfrmS6bo4AiwdeVgAKmv0FtS2Jw+391N8Nd5AkEANHa5Om/IpHLTL2YRAjpJTsDpY72bMUTJIwjQA3TFJkgrpOw6KYfohOcgbxLpZ4XuNJRU3VL4Hsxdv5V9aOVmfFOmMOVPQlakXy7NgtW5POp1f2WJwgcZxylkR1CjwaqMyXmSoVl46pyH3tr5+dptsQoKSGdi6sIHGA60oDotFPcm+0ifa47wZw+vapuuDi4tdNxhrHGaDMG8xiE0WFDHwQUDlk2/+W7j9SEX0H3Em7us371JXRp56EDwEcDa34VpVkC6i8HGcHK55hnxVbMZXGf3qhOFD8wY7qMbjMRvIpucrMHBi86OfkDfv0vDj2LyvIl5APj/AX50BrE0tfH1MZbH26Jkx4NdlkcxQ14GumarmUqfmVvbX/fsoA6oUuAAE9ZgRRi3KHO4wci6KUcRfdm+XOeUkaBFsL86G3EEYIvrtBTuaypdz+Cx7nd1iPZyWMx5Y1gXnVzha4nBdV4+7l9JIsFggD8QVpw2uHXQiS1KXFjOeqA3DBD8tjMB7q26Fl2fD3jkOo4BTbQ2NrRIZUu/iL+fOmMPsyMt2qulB0yaSBCfkbEq8xrUA=" file_glob: true @@ -37,6 +39,7 @@ deploy: repo: gchq/CyberChef tags: true - provider: npm + edge: true email: "n1474335@gmail.com" api_token: secure: "UnDQL3Kh+GK2toL0TK3FObO0ujVssU3Eg4BBuYdjwLB81GhiGE5/DTh7THdZPOpbLo6wQeOwfZDuMeKC1OU+0Uf4NsdYFu1aq6xMO20qBQ4qUfgsyiK4Qgywj9gk0p1+OFZdGAZ/j1CNRAaF71XQIY6iV84c+SO4WoizXYrNT0Jh4sr2DA4/97G2xmJtPi0qOzYrJ09R56ZUozmqeik5G0pMRIuJRbpjS/7bZXV+N7WV0ombZc9RkUaetbabEVOLQ+Xx5YAIVq+VuEeMe9VBSnxY/FfCLmy1wJsjGzpLCyBI9nbrG4nw8Wgc2m8NfK9rcpIvBTGner9r2j60NVDkZ8kLZPrqXhq6AZMwa+oz6K5UQCqRo2RRQzSGwXxg67HY5Tcq+oNmjd+DqpPg4LZ3eGlluyP5XfG+hpSr9Ya4d8q8SrUWLxkoLHI6ZKMtoKFbTCSSQPiluW5hsZxjz3yDkkjsJw64M/EM8UyJrgaXqDklQu+7rBGKLfsK6os7RDiqjBWpQ7gwpo8HvY0O8yqEAabPz+QGkanpjcCOZCXFbSkzWxYy37RMAPu88iINVZVlZE4l+WJenCpZY95ueyy0mG9cyMSzVRPyX6A+/n4H6VMFPFjpGDLTD588ACEjY1lmHfS/eXwXJcgqPPD2gW0XdRdUheU/ssqlfCfGWQMTDXs="