mirror of
https://github.com/gchq/CyberChef
synced 2024-11-15 09:07:06 +00:00
Add Text Encoding Brute Force operation
This commit is contained in:
parent
15fbe5a459
commit
71c743ff5a
4 changed files with 78 additions and 0 deletions
|
@ -49,6 +49,7 @@
|
|||
"Change IP format",
|
||||
"Encode text",
|
||||
"Decode text",
|
||||
"Text Encoding Brute Force",
|
||||
"Swap endianness",
|
||||
"To MessagePack",
|
||||
"From MessagePack",
|
||||
|
|
52
src/core/operations/TextEncodingBruteForce.mjs
Normal file
52
src/core/operations/TextEncodingBruteForce.mjs
Normal file
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* @author Cynser
|
||||
* @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 = "Enumerate all possible text encodings for input.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Character_encoding";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const output = [],
|
||||
charSets = Object.keys(IO_FORMAT);
|
||||
|
||||
for (let i = 0; i < charSets.length; i++) {
|
||||
let currentEncoding = Utils.printable(charSets[i] + ": ", false);
|
||||
currentEncoding += cptable.utils.encode(IO_FORMAT[charSets[i]], input);
|
||||
output.push(currentEncoding);
|
||||
}
|
||||
|
||||
return output.join("\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default TextEncodingBruteForce;
|
|
@ -74,6 +74,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";
|
||||
|
|
24
test/tests/operations/TextEncodingBruteForce.mjs
Normal file
24
test/tests/operations/TextEncodingBruteForce.mjs
Normal file
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
* 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",
|
||||
input: "Булкі праз ляніва сабаку.",
|
||||
expectedMatch: /Windows\-1251 Cyrillic \(1251\): Булкі праз ляніва сабаку\./,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Text Encoding Brute Force",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
}
|
||||
]);
|
||||
|
Loading…
Reference in a new issue