From 2a49af1ec3a22ae0a0cae5f6104ac04aedd3f1e0 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Fri, 24 Aug 2018 01:07:51 +0100 Subject: [PATCH] 'To Braille' and 'From Braille' operations added. Closes #255 --- CHANGELOG.md | 5 +++ src/core/config/Categories.json | 4 +- src/core/lib/Braille.mjs | 15 +++++++ src/core/operations/FromBraille.mjs | 70 +++++++++++++++++++++++++++++ src/core/operations/ToBraille.mjs | 70 +++++++++++++++++++++++++++++ 5 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 src/core/lib/Braille.mjs create mode 100644 src/core/operations/FromBraille.mjs create mode 100644 src/core/operations/ToBraille.mjs diff --git a/CHANGELOG.md b/CHANGELOG.md index e4f7dc1c..d1cb1fd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog All notable changes to CyberChef will be documented in this file. +### [8.5.0] - 2018-08-23 +- 'To Braille' and 'From Braille' operations added [@n1474335] | [#255] + ### [8.4.0] - 2018-08-23 - 'To Base85' and 'From Base85' operations added [@PenguinGeorge] | [#340] @@ -41,6 +44,7 @@ All notable changes to CyberChef will be documented in this file. - Initial open source commit [@n1474335] | [b1d73a72](https://github.com/gchq/CyberChef/commit/b1d73a725dc7ab9fb7eb789296efd2b7e4b08306) +[8.5.0]: https://github.com/gchq/CyberChef/releases/tag/v8.5.0 [8.4.0]: https://github.com/gchq/CyberChef/releases/tag/v8.4.0 [8.3.0]: https://github.com/gchq/CyberChef/releases/tag/v8.3.0 [8.2.0]: https://github.com/gchq/CyberChef/releases/tag/v8.2.0 @@ -65,6 +69,7 @@ All notable changes to CyberChef will be documented in this file. [#224]: https://github.com/gchq/CyberChef/pull/224 [#239]: https://github.com/gchq/CyberChef/pull/239 [#248]: https://github.com/gchq/CyberChef/pull/248 +[#255]: https://github.com/gchq/CyberChef/issues/255 [#281]: https://github.com/gchq/CyberChef/pull/281 [#284]: https://github.com/gchq/CyberChef/pull/284 [#294]: https://github.com/gchq/CyberChef/pull/294 diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json index d8c7975e..66663f4a 100755 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -51,7 +51,9 @@ "Decode text", "Swap endianness", "To MessagePack", - "From MessagePack" + "From MessagePack", + "To Braille", + "From Braille" ] }, { diff --git a/src/core/lib/Braille.mjs b/src/core/lib/Braille.mjs new file mode 100644 index 00000000..098c0e73 --- /dev/null +++ b/src/core/lib/Braille.mjs @@ -0,0 +1,15 @@ +/** + * Braille resources. + * + * @author n1474335 [n1474335@gmail.com] + * @copyright Crown Copyright 2018 + * @license Apache-2.0 + */ + +/** + * Braille lookup table. + */ +export const BRAILLE_LOOKUP = { + ascii: " A1B'K2L@CIF/MSP\"E3H9O6R^DJG>NTQ,*5<-U8V.%[$+X!&;:4\\0Z7(_?W]#Y)=", + dot6: "⠀⠁⠂⠃⠄⠅⠆⠇⠈⠉⠊⠋⠌⠍⠎⠏⠐⠑⠒⠓⠔⠕⠖⠗⠘⠙⠚⠛⠜⠝⠞⠟⠠⠡⠢⠣⠤⠥⠦⠧⠨⠩⠪⠫⠬⠭⠮⠯⠰⠱⠲⠳⠴⠵⠶⠷⠸⠹⠺⠻⠼⠽⠾⠿" +}; diff --git a/src/core/operations/FromBraille.mjs b/src/core/operations/FromBraille.mjs new file mode 100644 index 00000000..61fa1452 --- /dev/null +++ b/src/core/operations/FromBraille.mjs @@ -0,0 +1,70 @@ +/** + * @author n1474335 [n1474335@gmail.com] + * @copyright Crown Copyright 2018 + * @license Apache-2.0 + */ + +import Operation from "../Operation"; +import {BRAILLE_LOOKUP} from "../lib/Braille"; + +/** + * From Braille operation + */ +class FromBraille extends Operation { + + /** + * FromBraille constructor + */ + constructor() { + super(); + + this.name = "From Braille"; + this.module = "Default"; + this.description = "Converts six-dot braille symbols to text."; + this.infoURL = "https://wikipedia.org/wiki/Braille"; + this.inputType = "string"; + this.outputType = "string"; + this.args = []; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + return input.split("").map(b => { + const idx = BRAILLE_LOOKUP.dot6.indexOf(b); + return idx < 0 ? b : BRAILLE_LOOKUP.ascii[idx]; + }).join(""); + } + + /** + * Highlight From Braille + * + * @param {Object[]} pos + * @param {number} pos[].start + * @param {number} pos[].end + * @param {Object[]} args + * @returns {Object[]} pos + */ + highlight(pos, args) { + return pos; + } + + /** + * Highlight From Braille in reverse + * + * @param {Object[]} pos + * @param {number} pos[].start + * @param {number} pos[].end + * @param {Object[]} args + * @returns {Object[]} pos + */ + highlightReverse(pos, args) { + return pos; + } + +} + +export default FromBraille; diff --git a/src/core/operations/ToBraille.mjs b/src/core/operations/ToBraille.mjs new file mode 100644 index 00000000..9530f9d3 --- /dev/null +++ b/src/core/operations/ToBraille.mjs @@ -0,0 +1,70 @@ +/** + * @author n1474335 [n1474335@gmail.com] + * @copyright Crown Copyright 2018 + * @license Apache-2.0 + */ + +import Operation from "../Operation"; +import {BRAILLE_LOOKUP} from "../lib/Braille"; + +/** + * To Braille operation + */ +class ToBraille extends Operation { + + /** + * ToBraille constructor + */ + constructor() { + super(); + + this.name = "To Braille"; + this.module = "Default"; + this.description = "Converts text to six-dot braille symbols."; + this.infoURL = "https://wikipedia.org/wiki/Braille"; + this.inputType = "string"; + this.outputType = "string"; + this.args = []; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + return input.split("").map(c => { + const idx = BRAILLE_LOOKUP.ascii.indexOf(c.toUpperCase()); + return idx < 0 ? c : BRAILLE_LOOKUP.dot6[idx]; + }).join(""); + } + + /** + * Highlight To Braille + * + * @param {Object[]} pos + * @param {number} pos[].start + * @param {number} pos[].end + * @param {Object[]} args + * @returns {Object[]} pos + */ + highlight(pos, args) { + return pos; + } + + /** + * Highlight To Braille in reverse + * + * @param {Object[]} pos + * @param {number} pos[].start + * @param {number} pos[].end + * @param {Object[]} args + * @returns {Object[]} pos + */ + highlightReverse(pos, args) { + return pos; + } + +} + +export default ToBraille;