diff --git a/CHANGELOG.md b/CHANGELOG.md index 15943e7e..6355831e 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.15.0] - 2018-12-18 +- 'Text Encoding Brute Force' operation added [@Cynser] | [#439] + ### [8.14.0] - 2018-12-18 - 'To Base62' and 'From Base62' operations added [@tcode2k16] | [#443] @@ -73,6 +76,7 @@ All major and minor version changes will be documented in this file. Details of +[8.15.0]: https://github.com/gchq/CyberChef/releases/tag/v8.15.0 [8.14.0]: https://github.com/gchq/CyberChef/releases/tag/v8.14.0 [8.13.0]: https://github.com/gchq/CyberChef/releases/tag/v8.13.0 [8.12.0]: https://github.com/gchq/CyberChef/releases/tag/v8.12.0 @@ -107,6 +111,7 @@ All major and minor version changes will be documented in this file. Details of [@bwhitn]: https://github.com/bwhitn [@jarmovanlenthe]: https://github.com/jarmovanlenthe [@tcode2k16]: https://github.com/tcode2k16 +[@Cynser]: https://github.com/Cynser [#95]: https://github.com/gchq/CyberChef/pull/299 [#173]: https://github.com/gchq/CyberChef/pull/173 @@ -130,5 +135,6 @@ All major and minor version changes will be documented in this file. Details of [#387]: https://github.com/gchq/CyberChef/pull/387 [#394]: https://github.com/gchq/CyberChef/pull/394 [#428]: https://github.com/gchq/CyberChef/pull/428 +[#439]: https://github.com/gchq/CyberChef/pull/439 [#441]: https://github.com/gchq/CyberChef/pull/441 [#443]: https://github.com/gchq/CyberChef/pull/443 diff --git a/babel.config.js b/babel.config.js index 2362c42a..5459f6c8 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,7 +1,7 @@ module.exports = function(api) { api.cache.forever(); - return { + return { "presets": [ ["@babel/preset-env", { "targets": { diff --git a/src/core/operations/TextEncodingBruteForce.mjs b/src/core/operations/TextEncodingBruteForce.mjs index 9c606eaa..3919dcd9 100644 --- a/src/core/operations/TextEncodingBruteForce.mjs +++ b/src/core/operations/TextEncodingBruteForce.mjs @@ -1,5 +1,6 @@ /** * @author Cynser + * @author n1474335 [n1474335@gmail.com] * @copyright Crown Copyright 2018 * @license Apache-2.0 */ @@ -22,10 +23,18 @@ class TextEncodingBruteForce extends Operation { this.name = "Text Encoding Brute Force"; this.module = "CharEnc"; - this.description = "Enumerate all possible text encodings for input."; + this.description = [ + "Enumerates all supported text encodings for the input, allowing you to quickly spot the correct one.", + "

", + "Supported charsets are:", + "" + ].join("\n"); this.infoURL = "https://wikipedia.org/wiki/Character_encoding"; this.inputType = "string"; - this.outputType = "string"; + this.outputType = "json"; + this.presentType = "html"; this.args = [ { name: "Mode", @@ -38,30 +47,44 @@ class TextEncodingBruteForce extends Operation { /** * @param {string} input * @param {Object[]} args - * @returns {string} + * @returns {json} */ run(input, args) { - const output = [], - charSets = Object.keys(IO_FORMAT), + const output = {}, + charsets = Object.keys(IO_FORMAT), mode = args[0]; - for (let i = 0; i < charSets.length; i++) { - let currentEncoding = charSets[i] + ": "; - + charsets.forEach(charset => { try { if (mode === "Decode") { - currentEncoding += cptable.utils.decode(IO_FORMAT[charSets[i]], input); + output[charset] = cptable.utils.decode(IO_FORMAT[charset], input); } else { - currentEncoding += cptable.utils.encode(IO_FORMAT[charSets[i]], input); + output[charset] = Utils.arrayBufferToStr(cptable.utils.encode(IO_FORMAT[charset], input)); } } catch (err) { - currentEncoding += "Could not decode."; + output[charset] = "Could not decode."; } + }); - output.push(Utils.printable(currentEncoding, true)); + return output; + } + + /** + * Displays the encodings in an HTML table for web apps. + * + * @param {Object[]} encodings + * @returns {html} + */ + present(encodings) { + let table = ""; + + for (const enc in encodings) { + const value = Utils.printable(encodings[enc], true); + table += ``; } - return output.join("\n"); + table += "
EncodingValue
${enc}${value}
"; + return table; } } diff --git a/src/core/operations/ToBase62.mjs b/src/core/operations/ToBase62.mjs index 3f615db2..51f89ecd 100644 --- a/src/core/operations/ToBase62.mjs +++ b/src/core/operations/ToBase62.mjs @@ -23,7 +23,7 @@ class ToBase62 extends Operation { this.name = "To Base62"; this.module = "Default"; this.description = "Base62 is a notation for encoding arbitrary byte data using a restricted set of symbols that can be conveniently used by humans and processed by computers. The high number base results in shorter strings than with the decimal or hexadecimal system."; - this.infoURL = "https://en.wikipedia.org/wiki/List_of_numeral_systems"; + this.infoURL = "https://wikipedia.org/wiki/List_of_numeral_systems"; this.inputType = "byteArray"; this.outputType = "string"; this.args = [ diff --git a/test/tests/operations/TextEncodingBruteForce.mjs b/test/tests/operations/TextEncodingBruteForce.mjs index 3b16453d..22e8f7c5 100644 --- a/test/tests/operations/TextEncodingBruteForce.mjs +++ b/test/tests/operations/TextEncodingBruteForce.mjs @@ -12,7 +12,7 @@ TestRegister.addTests([ { name: "Text Encoding Brute Force - Encode", input: "Булкі праз ляніва сабаку.", - expectedMatch: /Windows-1251 Cyrillic \(1251\): Булкі праз ляніва сабаку\./, + expectedMatch: /Windows-1251 Cyrillic \(1251\).{1,10}Булкі праз ляніва сабаку\./, recipeConfig: [ { op: "Text Encoding Brute Force", @@ -23,7 +23,7 @@ TestRegister.addTests([ { name: "Text Encoding Brute Force - Decode", input: "Áóëê³ ïðàç ëÿí³âà ñàáàêó.", - expectedMatch: /Windows-1251 Cyrillic \(1251\): Булкі праз ляніва сабаку\./, + expectedMatch: /Windows-1251 Cyrillic \(1251\).{1,10}Булкі праз ляніва сабаку\./, recipeConfig: [ { op: "Text Encoding Brute Force",