mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-24 00:36:16 -04:00
Merge branch 'master' into io-overhaul
This commit is contained in:
commit
2785459257
38 changed files with 1703 additions and 29 deletions
|
@ -249,6 +249,7 @@ module.exports = {
|
|||
// testOp(browser, "RIPEMD", "test input", "test_output");
|
||||
// testOp(browser, "ROT13", "test input", "test_output");
|
||||
// testOp(browser, "ROT47", "test input", "test_output");
|
||||
// testOp(browser, "ROT8000", "test input", "test_output");
|
||||
// testOp(browser, "Rail Fence Cipher Decode", "test input", "test_output");
|
||||
// testOp(browser, "Rail Fence Cipher Encode", "test input", "test_output");
|
||||
// testOp(browser, "Randomize Colour Palette", "test input", "test_output");
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
import Chef from "../../src/core/Chef.mjs";
|
||||
import Utils from "../../src/core/Utils.mjs";
|
||||
import cliProgress from "cli-progress";
|
||||
import log from "loglevel";
|
||||
|
||||
/**
|
||||
* Object to store and run the list of tests.
|
||||
|
@ -50,6 +51,9 @@ class TestRegister {
|
|||
* Runs all the tests in the register.
|
||||
*/
|
||||
async runTests () {
|
||||
// Turn off logging to avoid messy errors
|
||||
log.setLevel("silent", false);
|
||||
|
||||
const progBar = new cliProgress.SingleBar({
|
||||
format: formatter,
|
||||
stopOnComplete: true
|
||||
|
@ -84,7 +88,17 @@ class TestRegister {
|
|||
|
||||
if (result.error) {
|
||||
if (test.expectedError) {
|
||||
ret.status = "passing";
|
||||
if (result.error.displayStr === test.expectedOutput) {
|
||||
ret.status = "passing";
|
||||
} else {
|
||||
ret.status = "failing";
|
||||
ret.output = [
|
||||
"Expected",
|
||||
"\t" + test.expectedOutput.replace(/\n/g, "\n\t"),
|
||||
"Received",
|
||||
"\t" + result.error.displayStr.replace(/\n/g, "\n\t"),
|
||||
].join("\n");
|
||||
}
|
||||
} else {
|
||||
ret.status = "erroring";
|
||||
ret.output = result.error.displayStr;
|
||||
|
@ -118,6 +132,9 @@ class TestRegister {
|
|||
progBar.increment();
|
||||
}
|
||||
|
||||
// Turn logging back on
|
||||
log.setLevel("info", false);
|
||||
|
||||
return testResults;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,9 +24,12 @@ import "./tests/Base45.mjs";
|
|||
import "./tests/Base58.mjs";
|
||||
import "./tests/Base64.mjs";
|
||||
import "./tests/Base62.mjs";
|
||||
import "./tests/Base85.mjs";
|
||||
import "./tests/BitwiseOp.mjs";
|
||||
import "./tests/ByteRepr.mjs";
|
||||
import "./tests/CartesianProduct.mjs";
|
||||
import "./tests/CetaceanCipherEncode.mjs";
|
||||
import "./tests/CetaceanCipherDecode.mjs";
|
||||
import "./tests/CharEnc.mjs";
|
||||
import "./tests/ChangeIPFormat.mjs";
|
||||
import "./tests/Charts.mjs";
|
||||
|
@ -114,6 +117,10 @@ import "./tests/HASSH.mjs";
|
|||
import "./tests/GetAllCasings.mjs";
|
||||
import "./tests/SIGABA.mjs";
|
||||
import "./tests/ELFInfo.mjs";
|
||||
import "./tests/Subsection.mjs";
|
||||
import "./tests/CaesarBoxCipher.mjs";
|
||||
import "./tests/LS47.mjs";
|
||||
import "./tests/LZString.mjs";
|
||||
|
||||
|
||||
// Cannot test operations that use the File type yet
|
||||
|
|
48
tests/operations/tests/Base85.mjs
Normal file
48
tests/operations/tests/Base85.mjs
Normal file
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Base85 tests
|
||||
*
|
||||
* @author john19696
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
// Example from Wikipedia
|
||||
const wpExample = "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.";
|
||||
// Escape newline, quote & backslash
|
||||
const wpOutput = "9jqo^BlbD-BleB1DJ+*+F(f,q/0JhKF<GL>Cj@.4Gp$d7F!,L7@<6@)/0JDEF<G%<+EV:2F!,O<\
|
||||
DJ+*.@<*K0@<6L(Df-\\0Ec5e;DffZ(EZee.Bl.9pF\"AGXBPCsi+DGm>@3BB/F*&OCAfu2/AKYi(\
|
||||
DIb:@FD,*)+C]U=@3BN#EcYf8ATD3s@q?d$AftVqCh[NqF<G:8+EV:.+Cf>-FD5W8ARlolDIal(\
|
||||
DId<j@<?3r@:F%a+D58'ATD4$Bl@l3De:,-DJs`8ARoFb/0JMK@qB4^F!,R<AKZ&-DfTqBG%G>u\
|
||||
D.RTpAKYo'+CT/5+Cei#DII?(E,9)oF*2M7/c";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "To Base85",
|
||||
input: wpExample,
|
||||
expectedOutput: wpOutput,
|
||||
recipeConfig: [
|
||||
{ "op": "To Base85",
|
||||
"args": ["!-u"] }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "From Base85",
|
||||
input: wpOutput + "\n",
|
||||
expectedOutput: wpExample,
|
||||
recipeConfig: [
|
||||
{ "op": "From Base85",
|
||||
"args": ["!-u", true] }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "From Base85",
|
||||
input: wpOutput + "v",
|
||||
expectedError: true,
|
||||
expectedOutput: "From Base85 - Invalid character 'v' at index 337",
|
||||
recipeConfig: [
|
||||
{ "op": "From Base85",
|
||||
"args": ["!-u", false] }
|
||||
]
|
||||
},
|
||||
]);
|
45
tests/operations/tests/CaesarBoxCipher.mjs
Normal file
45
tests/operations/tests/CaesarBoxCipher.mjs
Normal file
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* Caesar Box Cipher tests.
|
||||
*
|
||||
* @author n1073645 [n1073645@gmail.com]
|
||||
*
|
||||
* @copyright Crown Copyright 2020
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Caesar Box Cipher: nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Caesar Box Cipher",
|
||||
args: ["1"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Caesar Box Cipher: Hello World!",
|
||||
input: "Hello World!",
|
||||
expectedOutput: "Hlodeor!lWl",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Caesar Box Cipher",
|
||||
args: ["3"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Caesar Box Cipher: Hello World!",
|
||||
input: "Hlodeor!lWl",
|
||||
expectedOutput: "HelloWorld!",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Caesar Box Cipher",
|
||||
args: ["4"],
|
||||
},
|
||||
],
|
||||
}
|
||||
]);
|
22
tests/operations/tests/CetaceanCipherDecode.mjs
Normal file
22
tests/operations/tests/CetaceanCipherDecode.mjs
Normal file
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* CetaceanCipher Encode tests
|
||||
*
|
||||
* @author dolphinOnKeys
|
||||
* @copyright Crown Copyright 2022
|
||||
* @licence Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Cetacean Cipher Decode",
|
||||
input: "EEEEEEEEEeeEEEEe EEEEEEEEEeeEEEeE EEEEEEEEEeeEEEee EEeeEEEEEeeEEeee",
|
||||
expectedOutput: "a b c で",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Cetacean Cipher Decode",
|
||||
args: []
|
||||
},
|
||||
],
|
||||
}
|
||||
]);
|
22
tests/operations/tests/CetaceanCipherEncode.mjs
Normal file
22
tests/operations/tests/CetaceanCipherEncode.mjs
Normal file
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* CetaceanCipher Encode tests
|
||||
*
|
||||
* @author dolphinOnKeys
|
||||
* @copyright Crown Copyright 2022
|
||||
* @licence Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Cetacean Cipher Encode",
|
||||
input: "a b c で",
|
||||
expectedOutput: "EEEEEEEEEeeEEEEe EEEEEEEEEeeEEEeE EEEEEEEEEeeEEEee EEeeEEEEEeeEEeee",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Cetacean Cipher Encode",
|
||||
args: []
|
||||
},
|
||||
],
|
||||
}
|
||||
]);
|
|
@ -31,7 +31,7 @@ TestRegister.addTests([
|
|||
},
|
||||
{
|
||||
op: "Merge",
|
||||
args: [],
|
||||
args: [true],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -50,7 +50,7 @@ TestRegister.addTests([
|
|||
},
|
||||
{
|
||||
op: "Merge",
|
||||
args: [],
|
||||
args: [true],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -66,5 +66,16 @@ TestRegister.addTests([
|
|||
{"op": "Label", "args": ["skipReturn"]},
|
||||
{"op": "To Base64", "args": ["A-Za-z0-9+/="]}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "Fork, Partial Merge",
|
||||
input: "Hello World",
|
||||
expectedOutput: "48656c6c6f 576f726c64",
|
||||
recipeConfig: [
|
||||
{ "op": "Fork", "args": [" ", " ", false] },
|
||||
{ "op": "Fork", "args": ["l", "l", false] },
|
||||
{ "op": "Merge", "args": [false] },
|
||||
{ "op": "To Hex", "args": ["None", 0] },
|
||||
]
|
||||
},
|
||||
]);
|
||||
|
|
45
tests/operations/tests/LS47.mjs
Normal file
45
tests/operations/tests/LS47.mjs
Normal file
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* LS47 tests.
|
||||
*
|
||||
* @author n1073645 [n1073645@gmail.com]
|
||||
*
|
||||
* @copyright Crown Copyright 2020
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "LS47 Encrypt",
|
||||
input: "thequickbrownfoxjumped",
|
||||
expectedOutput: "(,t74ci78cp/8trx*yesu:alp1wqy",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "LS47 Encrypt",
|
||||
args: ["helloworld", 0, "test"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "LS47 Decrypt",
|
||||
input: "(,t74ci78cp/8trx*yesu:alp1wqy",
|
||||
expectedOutput: "thequickbrownfoxjumped---test",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "LS47 Decrypt",
|
||||
args: ["helloworld", 0],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "LS47 Encrypt",
|
||||
input: "thequickbrownfoxjumped",
|
||||
expectedOutput: "Letter H is not included in LS47",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "LS47 Encrypt",
|
||||
args: ["Helloworld", 0, "test"],
|
||||
},
|
||||
],
|
||||
}
|
||||
]);
|
33
tests/operations/tests/LZString.mjs
Normal file
33
tests/operations/tests/LZString.mjs
Normal file
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* LZString tests.
|
||||
*
|
||||
* @author crespyl [peter@crespyl.net]
|
||||
* @copyright Peter Jacobs 2021
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "LZString Compress To Base64",
|
||||
input: "hello world",
|
||||
expectedOutput: "BYUwNmD2AEDukCcwBMg=",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "LZString Compress",
|
||||
"args": ["Base64"]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "LZString Decompress From Base64",
|
||||
input: "BYUwNmD2AEDukCcwBMg=",
|
||||
expectedOutput: "hello world",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "LZString Decompress",
|
||||
"args": ["Base64"]
|
||||
}
|
||||
],
|
||||
}
|
||||
]);
|
|
@ -212,4 +212,37 @@ TestRegister.addTests([
|
|||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ROT8000: nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "ROT8000",
|
||||
args: []
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ROT8000: normal",
|
||||
input: "The Quick Brown Fox Jumped Over The Lazy Dog.",
|
||||
expectedOutput: "籝籱籮 籚籾籲籬籴 籋类籸粀籷 籏籸粁 籓籾籶籹籮籭 籘籿籮类 籝籱籮 籕籪粃粂 籍籸籰簷",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "ROT8000",
|
||||
args: []
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ROT8000: backward",
|
||||
input: "籝籱籮 籚籾籲籬籴 籋类籸粀籷 籏籸粁 籓籾籶籹籮籭 籘籿籮类 籝籱籮 籕籪粃粂 籍籸籰簷",
|
||||
expectedOutput: "The Quick Brown Fox Jumped Over The Lazy Dog.",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "ROT8000",
|
||||
args: []
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
|
102
tests/operations/tests/Subsection.mjs
Normal file
102
tests/operations/tests/Subsection.mjs
Normal file
|
@ -0,0 +1,102 @@
|
|||
/**
|
||||
* Subsection Tests.
|
||||
*
|
||||
* @author n1073645 [n1073645@gmail.com]
|
||||
* @copyright Crown Copyright 2022
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Subsection: nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Subsection",
|
||||
"args": ["", true, true, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Subsection, Full Merge: nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Subsection",
|
||||
"args": ["", true, true, false],
|
||||
},
|
||||
{
|
||||
"op": "Merge",
|
||||
"args": [true],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Subsection, Partial Merge: nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Subsection",
|
||||
"args": ["", true, true, false],
|
||||
},
|
||||
{
|
||||
"op": "Merge",
|
||||
"args": [false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Subsection, Full Merge: Base64 with Hex",
|
||||
input: "SGVsbG38675629ybGQ=",
|
||||
expectedOutput: "Hello World",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Subsection",
|
||||
"args": ["386756", true, true, false],
|
||||
},
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["Auto"],
|
||||
},
|
||||
{
|
||||
"op": "Merge",
|
||||
"args": [true],
|
||||
},
|
||||
{
|
||||
"op": "From Base64",
|
||||
"args": ["A-Za-z0-9+/=", true, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Subsection, Partial Merge: Base64 with Hex surrounded by binary data.",
|
||||
input: "000000000SGVsbG38675629ybGQ=0000000000",
|
||||
expectedOutput: "000000000Hello World0000000000",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Subsection",
|
||||
"args": ["SGVsbG38675629ybGQ=", true, true, false],
|
||||
},
|
||||
{
|
||||
"op": "Subsection",
|
||||
"args": ["386756", true, true, false],
|
||||
},
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["Auto"],
|
||||
},
|
||||
{
|
||||
"op": "Merge",
|
||||
"args": [false],
|
||||
},
|
||||
{
|
||||
"op": "From Base64",
|
||||
"args": ["A-Za-z0-9+/=", true, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
Loading…
Add table
Add a link
Reference in a new issue