cyberchef 9.39.4 → 9.39.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/core/config/OperationConfig.json +10 -0
- package/src/core/operations/FromBase45.mjs +14 -2
- package/src/core/operations/FromBase85.mjs +13 -1
- package/tests/lib/TestRegister.mjs +11 -1
- package/tests/operations/index.mjs +1 -0
- package/tests/operations/tests/Base85.mjs +48 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cyberchef",
|
|
3
|
-
"version": "9.39.
|
|
3
|
+
"version": "9.39.5",
|
|
4
4
|
"description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.",
|
|
5
5
|
"author": "n1474335 <n1474335@gmail.com>",
|
|
6
6
|
"homepage": "https://gchq.github.io/CyberChef",
|
|
@@ -5652,6 +5652,11 @@
|
|
|
5652
5652
|
"name": "Alphabet",
|
|
5653
5653
|
"type": "string",
|
|
5654
5654
|
"value": "0-9A-Z $%*+\\-./:"
|
|
5655
|
+
},
|
|
5656
|
+
{
|
|
5657
|
+
"name": "Remove non-alphabet chars",
|
|
5658
|
+
"type": "boolean",
|
|
5659
|
+
"value": true
|
|
5655
5660
|
}
|
|
5656
5661
|
]
|
|
5657
5662
|
},
|
|
@@ -5995,6 +6000,11 @@
|
|
|
5995
6000
|
"value": "0-9A-Za-z!#$%&()*+\\-;<=>?@^_`{|}~"
|
|
5996
6001
|
}
|
|
5997
6002
|
]
|
|
6003
|
+
},
|
|
6004
|
+
{
|
|
6005
|
+
"name": "Remove non-alphabet chars",
|
|
6006
|
+
"type": "boolean",
|
|
6007
|
+
"value": true
|
|
5998
6008
|
}
|
|
5999
6009
|
]
|
|
6000
6010
|
},
|
|
@@ -32,7 +32,12 @@ class FromBase45 extends Operation {
|
|
|
32
32
|
name: "Alphabet",
|
|
33
33
|
type: "string",
|
|
34
34
|
value: ALPHABET
|
|
35
|
-
}
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: "Remove non-alphabet chars",
|
|
38
|
+
type: "boolean",
|
|
39
|
+
value: true
|
|
40
|
+
},
|
|
36
41
|
];
|
|
37
42
|
|
|
38
43
|
this.highlight = highlightFromBase45;
|
|
@@ -46,10 +51,17 @@ class FromBase45 extends Operation {
|
|
|
46
51
|
*/
|
|
47
52
|
run(input, args) {
|
|
48
53
|
if (!input) return [];
|
|
49
|
-
const alphabet = Utils.expandAlphRange(args[0]);
|
|
54
|
+
const alphabet = Utils.expandAlphRange(args[0]).join("");
|
|
55
|
+
const removeNonAlphChars = args[1];
|
|
50
56
|
|
|
51
57
|
const res = [];
|
|
52
58
|
|
|
59
|
+
// Remove non-alphabet characters
|
|
60
|
+
if (removeNonAlphChars) {
|
|
61
|
+
const re = new RegExp("[^" + alphabet.replace(/[[\]\\\-^$]/g, "\\$&") + "]", "g");
|
|
62
|
+
input = input.replace(re, "");
|
|
63
|
+
}
|
|
64
|
+
|
|
53
65
|
for (const triple of Utils.chunked(input, 3)) {
|
|
54
66
|
triple.reverse();
|
|
55
67
|
let b = 0;
|
|
@@ -32,6 +32,11 @@ class FromBase85 extends Operation {
|
|
|
32
32
|
type: "editableOption",
|
|
33
33
|
value: ALPHABET_OPTIONS
|
|
34
34
|
},
|
|
35
|
+
{
|
|
36
|
+
name: "Remove non-alphabet chars",
|
|
37
|
+
type: "boolean",
|
|
38
|
+
value: true
|
|
39
|
+
},
|
|
35
40
|
];
|
|
36
41
|
}
|
|
37
42
|
|
|
@@ -43,6 +48,7 @@ class FromBase85 extends Operation {
|
|
|
43
48
|
run(input, args) {
|
|
44
49
|
const alphabet = Utils.expandAlphRange(args[0]).join(""),
|
|
45
50
|
encoding = alphabetName(alphabet),
|
|
51
|
+
removeNonAlphChars = args[1],
|
|
46
52
|
result = [];
|
|
47
53
|
|
|
48
54
|
if (alphabet.length !== 85 ||
|
|
@@ -50,6 +56,12 @@ class FromBase85 extends Operation {
|
|
|
50
56
|
throw new OperationError("Alphabet must be of length 85");
|
|
51
57
|
}
|
|
52
58
|
|
|
59
|
+
// Remove non-alphabet characters
|
|
60
|
+
if (removeNonAlphChars) {
|
|
61
|
+
const re = new RegExp("[^" + alphabet.replace(/[[\]\\\-^$]/g, "\\$&") + "]", "g");
|
|
62
|
+
input = input.replace(re, "");
|
|
63
|
+
}
|
|
64
|
+
|
|
53
65
|
if (input.length === 0) return [];
|
|
54
66
|
|
|
55
67
|
const matches = input.match(/<~(.+?)~>/);
|
|
@@ -69,7 +81,7 @@ class FromBase85 extends Operation {
|
|
|
69
81
|
.map((chr, idx) => {
|
|
70
82
|
const digit = alphabet.indexOf(chr);
|
|
71
83
|
if (digit < 0 || digit > 84) {
|
|
72
|
-
throw `Invalid character '${chr}' at index ${idx}`;
|
|
84
|
+
throw `Invalid character '${chr}' at index ${i + idx}`;
|
|
73
85
|
}
|
|
74
86
|
return digit;
|
|
75
87
|
});
|
|
@@ -84,7 +84,17 @@ class TestRegister {
|
|
|
84
84
|
|
|
85
85
|
if (result.error) {
|
|
86
86
|
if (test.expectedError) {
|
|
87
|
-
|
|
87
|
+
if (result.error.displayStr === test.expectedOutput) {
|
|
88
|
+
ret.status = "passing";
|
|
89
|
+
} else {
|
|
90
|
+
ret.status = "failing";
|
|
91
|
+
ret.output = [
|
|
92
|
+
"Expected",
|
|
93
|
+
"\t" + test.expectedOutput.replace(/\n/g, "\n\t"),
|
|
94
|
+
"Received",
|
|
95
|
+
"\t" + result.error.displayStr.replace(/\n/g, "\n\t"),
|
|
96
|
+
].join("\n");
|
|
97
|
+
}
|
|
88
98
|
} else {
|
|
89
99
|
ret.status = "erroring";
|
|
90
100
|
ret.output = result.error.displayStr;
|
|
@@ -24,6 +24,7 @@ import "./tests/Base45.mjs";
|
|
|
24
24
|
import "./tests/Base58.mjs";
|
|
25
25
|
import "./tests/Base64.mjs";
|
|
26
26
|
import "./tests/Base62.mjs";
|
|
27
|
+
import "./tests/Base85.mjs";
|
|
27
28
|
import "./tests/BitwiseOp.mjs";
|
|
28
29
|
import "./tests/ByteRepr.mjs";
|
|
29
30
|
import "./tests/CartesianProduct.mjs";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base85 tests
|
|
3
|
+
*
|
|
4
|
+
* @author john19696
|
|
5
|
+
* @copyright Crown Copyright 2019
|
|
6
|
+
* @license Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
import TestRegister from "../../lib/TestRegister.mjs";
|
|
9
|
+
|
|
10
|
+
// Example from Wikipedia
|
|
11
|
+
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.";
|
|
12
|
+
// Escape newline, quote & backslash
|
|
13
|
+
const wpOutput = "9jqo^BlbD-BleB1DJ+*+F(f,q/0JhKF<GL>Cj@.4Gp$d7F!,L7@<6@)/0JDEF<G%<+EV:2F!,O<\
|
|
14
|
+
DJ+*.@<*K0@<6L(Df-\\0Ec5e;DffZ(EZee.Bl.9pF\"AGXBPCsi+DGm>@3BB/F*&OCAfu2/AKYi(\
|
|
15
|
+
DIb:@FD,*)+C]U=@3BN#EcYf8ATD3s@q?d$AftVqCh[NqF<G:8+EV:.+Cf>-FD5W8ARlolDIal(\
|
|
16
|
+
DId<j@<?3r@:F%a+D58'ATD4$Bl@l3De:,-DJs`8ARoFb/0JMK@qB4^F!,R<AKZ&-DfTqBG%G>u\
|
|
17
|
+
D.RTpAKYo'+CT/5+Cei#DII?(E,9)oF*2M7/c";
|
|
18
|
+
|
|
19
|
+
TestRegister.addTests([
|
|
20
|
+
{
|
|
21
|
+
name: "To Base85",
|
|
22
|
+
input: wpExample,
|
|
23
|
+
expectedOutput: wpOutput,
|
|
24
|
+
recipeConfig: [
|
|
25
|
+
{ "op": "To Base85",
|
|
26
|
+
"args": ["!-u"] }
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "From Base85",
|
|
31
|
+
input: wpOutput + "\n",
|
|
32
|
+
expectedOutput: wpExample,
|
|
33
|
+
recipeConfig: [
|
|
34
|
+
{ "op": "From Base85",
|
|
35
|
+
"args": ["!-u", true] }
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "From Base85",
|
|
40
|
+
input: wpOutput + "v",
|
|
41
|
+
expectedError: true,
|
|
42
|
+
expectedOutput: "From Base85 - Invalid character 'v' at index 337",
|
|
43
|
+
recipeConfig: [
|
|
44
|
+
{ "op": "From Base85",
|
|
45
|
+
"args": ["!-u", false] }
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
]);
|