mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Added decode option
This commit is contained in:
parent
3f7059a235
commit
dacb3ef6c3
2 changed files with 35 additions and 7 deletions
|
@ -26,7 +26,13 @@ class TextEncodingBruteForce extends Operation {
|
||||||
this.infoURL = "https://wikipedia.org/wiki/Character_encoding";
|
this.infoURL = "https://wikipedia.org/wiki/Character_encoding";
|
||||||
this.inputType = "string";
|
this.inputType = "string";
|
||||||
this.outputType = "string";
|
this.outputType = "string";
|
||||||
this.args = [];
|
this.args = [
|
||||||
|
{
|
||||||
|
name: "Mode",
|
||||||
|
type: "option",
|
||||||
|
value: ["Encode", "Decode"]
|
||||||
|
}
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,12 +42,23 @@ class TextEncodingBruteForce extends Operation {
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const output = [],
|
const output = [],
|
||||||
charSets = Object.keys(IO_FORMAT);
|
charSets = Object.keys(IO_FORMAT),
|
||||||
|
mode = args[0];
|
||||||
|
|
||||||
for (let i = 0; i < charSets.length; i++) {
|
for (let i = 0; i < charSets.length; i++) {
|
||||||
let currentEncoding = Utils.printable(charSets[i] + ": ", false);
|
let currentEncoding = charSets[i] + ": ";
|
||||||
currentEncoding += cptable.utils.encode(IO_FORMAT[charSets[i]], input);
|
|
||||||
output.push(currentEncoding);
|
try {
|
||||||
|
if (mode === "Decode") {
|
||||||
|
currentEncoding += cptable.utils.decode(IO_FORMAT[charSets[i]], input);
|
||||||
|
} else {
|
||||||
|
currentEncoding += cptable.utils.encode(IO_FORMAT[charSets[i]], input);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
currentEncoding += "Could not decode.";
|
||||||
|
}
|
||||||
|
|
||||||
|
output.push(Utils.printable(currentEncoding, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
return output.join("\n");
|
return output.join("\n");
|
||||||
|
|
|
@ -10,13 +10,24 @@ import TestRegister from "../../TestRegister";
|
||||||
|
|
||||||
TestRegister.addTests([
|
TestRegister.addTests([
|
||||||
{
|
{
|
||||||
name: "Text Encoding Brute Force",
|
name: "Text Encoding Brute Force - Encode",
|
||||||
input: "Булкі праз ляніва сабаку.",
|
input: "Булкі праз ляніва сабаку.",
|
||||||
expectedMatch: /Windows-1251 Cyrillic \(1251\): Булкі праз ляніва сабаку\./,
|
expectedMatch: /Windows-1251 Cyrillic \(1251\): Булкі праз ляніва сабаку\./,
|
||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{
|
{
|
||||||
op: "Text Encoding Brute Force",
|
op: "Text Encoding Brute Force",
|
||||||
args: [],
|
args: ["Encode"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Text Encoding Brute Force - Decode",
|
||||||
|
input: "Áóëê³ ïðàç ëÿí³âà ñàáàêó.",
|
||||||
|
expectedMatch: /Windows-1251 Cyrillic \(1251\): Булкі праз ляніва сабаку\./,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Text Encoding Brute Force",
|
||||||
|
args: ["Decode"],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue