Merge branch 'Cynser-text-brute-force'

This commit is contained in:
n1474335 2018-12-18 13:50:23 +00:00
commit 973b5f3f5c
7 changed files with 137 additions and 2 deletions

View file

@ -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

View file

@ -1,7 +1,7 @@
module.exports = function(api) {
api.cache.forever();
return {
return {
"presets": [
["@babel/preset-env", {
"targets": {

View file

@ -51,6 +51,7 @@
"Change IP format",
"Encode text",
"Decode text",
"Text Encoding Brute Force",
"Swap endianness",
"To MessagePack",
"From MessagePack",

View file

@ -0,0 +1,92 @@
/**
* @author Cynser
* @author n1474335 [n1474335@gmail.com]
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import Operation from "../Operation";
import Utils from "../Utils";
import cptable from "../vendor/js-codepage/cptable.js";
import {IO_FORMAT} from "../lib/ChrEnc";
/**
* Text Encoding Brute Force operation
*/
class TextEncodingBruteForce extends Operation {
/**
* TextEncodingBruteForce constructor
*/
constructor() {
super();
this.name = "Text Encoding Brute Force";
this.module = "CharEnc";
this.description = [
"Enumerates all supported text encodings for the input, allowing you to quickly spot the correct one.",
"<br><br>",
"Supported charsets are:",
"<ul>",
Object.keys(IO_FORMAT).map(e => `<li>${e}</li>`).join("\n"),
"</ul>"
].join("\n");
this.infoURL = "https://wikipedia.org/wiki/Character_encoding";
this.inputType = "string";
this.outputType = "json";
this.presentType = "html";
this.args = [
{
name: "Mode",
type: "option",
value: ["Encode", "Decode"]
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {json}
*/
run(input, args) {
const output = {},
charsets = Object.keys(IO_FORMAT),
mode = args[0];
charsets.forEach(charset => {
try {
if (mode === "Decode") {
output[charset] = cptable.utils.decode(IO_FORMAT[charset], input);
} else {
output[charset] = Utils.arrayBufferToStr(cptable.utils.encode(IO_FORMAT[charset], input));
}
} catch (err) {
output[charset] = "Could not decode.";
}
});
return output;
}
/**
* Displays the encodings in an HTML table for web apps.
*
* @param {Object[]} encodings
* @returns {html}
*/
present(encodings) {
let table = "<table class='table table-hover table-sm table-bordered table-nonfluid'><tr><th>Encoding</th><th>Value</th></tr>";
for (const enc in encodings) {
const value = Utils.printable(encodings[enc], true);
table += `<tr><td>${enc}</td><td>${value}</td></tr>`;
}
table += "<table>";
return table;
}
}
export default TextEncodingBruteForce;

View file

@ -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 = [

View file

@ -75,6 +75,7 @@ import "./tests/operations/SetIntersection";
import "./tests/operations/SetUnion";
import "./tests/operations/StrUtils";
import "./tests/operations/SymmetricDifference";
import "./tests/operations/TextEncodingBruteForce";
import "./tests/operations/ToGeohash.mjs";
import "./tests/operations/TranslateDateTimeFormat";
import "./tests/operations/Magic";

View file

@ -0,0 +1,35 @@
/**
* Text Encoding Brute Force tests.
*
* @author Cynser
*
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../../TestRegister";
TestRegister.addTests([
{
name: "Text Encoding Brute Force - Encode",
input: "Булкі праз ляніва сабаку.",
expectedMatch: /Windows-1251 Cyrillic \(1251\).{1,10}Булкі праз ляніва сабаку\./,
recipeConfig: [
{
op: "Text Encoding Brute Force",
args: ["Encode"],
},
],
},
{
name: "Text Encoding Brute Force - Decode",
input: "Áóëê³ ïðàç ëÿí³âà ñàáàêó.",
expectedMatch: /Windows-1251 Cyrillic \(1251\).{1,10}Булкі праз ляніва сабаку\./,
recipeConfig: [
{
op: "Text Encoding Brute Force",
args: ["Decode"],
},
],
}
]);