cyberchef 9.34.2 → 9.35.0

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/CHANGELOG.md CHANGED
@@ -13,6 +13,9 @@ All major and minor version changes will be documented in this file. Details of
13
13
 
14
14
  ## Details
15
15
 
16
+ ### [9.35.0] - 2022-03-28
17
+ - 'To Base45' and 'From Base45' operations added [@t-8ch] | [#1242]
18
+
16
19
  ### [9.34.0] - 2022-03-28
17
20
  - 'Get All Casings' operation added [@n1073645] | [#1065]
18
21
 
@@ -278,6 +281,7 @@ All major and minor version changes will be documented in this file. Details of
278
281
 
279
282
 
280
283
 
284
+ [9.35.0]: https://github.com/gchq/CyberChef/releases/tag/v9.35.0
281
285
  [9.34.0]: https://github.com/gchq/CyberChef/releases/tag/v9.34.0
282
286
  [9.33.0]: https://github.com/gchq/CyberChef/releases/tag/v9.33.0
283
287
  [9.32.0]: https://github.com/gchq/CyberChef/releases/tag/v9.32.0
@@ -482,6 +486,7 @@ All major and minor version changes will be documented in this file. Details of
482
486
  [#1049]: https://github.com/gchq/CyberChef/pull/1049
483
487
  [#1065]: https://github.com/gchq/CyberChef/pull/1065
484
488
  [#1083]: https://github.com/gchq/CyberChef/pull/1083
489
+ [#1242]: https://github.com/gchq/CyberChef/pull/1242
485
490
  [#1244]: https://github.com/gchq/CyberChef/pull/1244
486
491
  [#1313]: https://github.com/gchq/CyberChef/pull/1313
487
492
  [#1326]: https://github.com/gchq/CyberChef/pull/1326
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cyberchef",
3
- "version": "9.34.2",
3
+ "version": "9.35.0",
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",
@@ -1207,6 +1207,30 @@ class Utils {
1207
1207
  }[token];
1208
1208
  }
1209
1209
 
1210
+ /**
1211
+ * Iterate object in chunks of given size.
1212
+ *
1213
+ * @param {Iterable} iterable
1214
+ * @param {number} chunksize
1215
+ */
1216
+ static* chunked(iterable, chunksize) {
1217
+ const iterator = iterable[Symbol.iterator]();
1218
+ while (true) {
1219
+ const res = [];
1220
+ for (let i = 0; i < chunksize; i++) {
1221
+ const next = iterator.next();
1222
+ if (next.done) {
1223
+ break;
1224
+ }
1225
+ res.push(next.value);
1226
+ }
1227
+ if (res.length) {
1228
+ yield res;
1229
+ } else {
1230
+ return;
1231
+ }
1232
+ }
1233
+ }
1210
1234
  }
1211
1235
 
1212
1236
  /**
@@ -20,6 +20,8 @@
20
20
  "From Octal",
21
21
  "To Base32",
22
22
  "From Base32",
23
+ "To Base45",
24
+ "From Base45",
23
25
  "To Base58",
24
26
  "From Base58",
25
27
  "To Base62",
@@ -5548,6 +5548,22 @@
5548
5548
  }
5549
5549
  ]
5550
5550
  },
5551
+ "From Base45": {
5552
+ "module": "Default",
5553
+ "description": "Base45 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. Base45 is optimized for usage with QR codes.",
5554
+ "infoURL": "https://wikipedia.org/wiki/List_of_numeral_systems",
5555
+ "inputType": "string",
5556
+ "outputType": "byteArray",
5557
+ "flowControl": false,
5558
+ "manualBake": false,
5559
+ "args": [
5560
+ {
5561
+ "name": "Alphabet",
5562
+ "type": "string",
5563
+ "value": "0-9A-Z $%*+\\-./:"
5564
+ }
5565
+ ]
5566
+ },
5551
5567
  "From Base58": {
5552
5568
  "module": "Default",
5553
5569
  "description": "Base58 (similar to Base64) is a notation for encoding arbitrary byte data. It differs from Base64 by removing easily misread characters (i.e. l, I, 0 and O) to improve human readability.<br><br>This operation decodes data from an ASCII string (with an alphabet of your choosing, presets included) back into its raw form.<br><br>e.g. <code>StV1DL6CwTryKyV</code> becomes <code>hello world</code><br><br>Base58 is commonly used in cryptocurrencies (Bitcoin, Ripple, etc).",
@@ -12083,6 +12099,22 @@
12083
12099
  }
12084
12100
  ]
12085
12101
  },
12102
+ "To Base45": {
12103
+ "module": "Default",
12104
+ "description": "Base45 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. Base45 is optimized for usage with QR codes.",
12105
+ "infoURL": "https://wikipedia.org/wiki/List_of_numeral_systems",
12106
+ "inputType": "ArrayBuffer",
12107
+ "outputType": "string",
12108
+ "flowControl": false,
12109
+ "manualBake": false,
12110
+ "args": [
12111
+ {
12112
+ "name": "Alphabet",
12113
+ "type": "string",
12114
+ "value": "0-9A-Z $%*+\\-./:"
12115
+ }
12116
+ ]
12117
+ },
12086
12118
  "To Base58": {
12087
12119
  "module": "Default",
12088
12120
  "description": "Base58 (similar to Base64) is a notation for encoding arbitrary byte data. It differs from Base64 by removing easily misread characters (i.e. l, I, 0 and O) to improve human readability.<br><br>This operation encodes data in an ASCII string (with an alphabet of your choosing, presets included).<br><br>e.g. <code>hello world</code> becomes <code>StV1DL6CwTryKyV</code><br><br>Base58 is commonly used in cryptocurrencies (Bitcoin, Ripple, etc).",
@@ -45,6 +45,7 @@ import FrequencyDistribution from "../../operations/FrequencyDistribution.mjs";
45
45
  import FromBCD from "../../operations/FromBCD.mjs";
46
46
  import FromBase from "../../operations/FromBase.mjs";
47
47
  import FromBase32 from "../../operations/FromBase32.mjs";
48
+ import FromBase45 from "../../operations/FromBase45.mjs";
48
49
  import FromBase58 from "../../operations/FromBase58.mjs";
49
50
  import FromBase62 from "../../operations/FromBase62.mjs";
50
51
  import FromBase64 from "../../operations/FromBase64.mjs";
@@ -134,6 +135,7 @@ import TakeBytes from "../../operations/TakeBytes.mjs";
134
135
  import ToBCD from "../../operations/ToBCD.mjs";
135
136
  import ToBase from "../../operations/ToBase.mjs";
136
137
  import ToBase32 from "../../operations/ToBase32.mjs";
138
+ import ToBase45 from "../../operations/ToBase45.mjs";
137
139
  import ToBase58 from "../../operations/ToBase58.mjs";
138
140
  import ToBase62 from "../../operations/ToBase62.mjs";
139
141
  import ToBase64 from "../../operations/ToBase64.mjs";
@@ -209,6 +211,7 @@ OpModules.Default = {
209
211
  "From BCD": FromBCD,
210
212
  "From Base": FromBase,
211
213
  "From Base32": FromBase32,
214
+ "From Base45": FromBase45,
212
215
  "From Base58": FromBase58,
213
216
  "From Base62": FromBase62,
214
217
  "From Base64": FromBase64,
@@ -298,6 +301,7 @@ OpModules.Default = {
298
301
  "To BCD": ToBCD,
299
302
  "To Base": ToBase,
300
303
  "To Base32": ToBase32,
304
+ "To Base45": ToBase45,
301
305
  "To Base58": ToBase58,
302
306
  "To Base62": ToBase62,
303
307
  "To Base64": ToBase64,
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Base45 resources.
3
+ *
4
+ * @author Thomas Weißschuh [thomas@t-8ch.de]
5
+ * @copyright Crown Copyright 2021
6
+ * @license Apache-2.0
7
+ */
8
+
9
+ /**
10
+ * Highlight to Base45
11
+ */
12
+ export function highlightToBase45(pos, args) {
13
+ pos[0].start = Math.floor(pos[0].start / 2) * 3;
14
+ pos[0].end = Math.ceil(pos[0].end / 2) * 3;
15
+ return pos;
16
+ }
17
+
18
+ /**
19
+ * Highlight from Base45
20
+ */
21
+ export function highlightFromBase45(pos, args) {
22
+ pos[0].start = Math.floor(pos[0].start / 3) * 2;
23
+ pos[0].end = Math.ceil(pos[0].end / 3) * 2;
24
+ return pos;
25
+ }
26
+
27
+ export const ALPHABET = "0-9A-Z $%*+\\-./:";
@@ -0,0 +1,89 @@
1
+ /**
2
+ * @author Thomas Weißschuh [thomas@t-8ch.de]
3
+ * @copyright Crown Copyright 2021
4
+ * @license Apache-2.0
5
+ */
6
+
7
+ import {ALPHABET, highlightToBase45, highlightFromBase45} from "../lib/Base45.mjs";
8
+ import Operation from "../Operation.mjs";
9
+ import OperationError from "../errors/OperationError.mjs";
10
+ import Utils from "../Utils.mjs";
11
+
12
+
13
+ /**
14
+ * From Base45 operation
15
+ */
16
+ class FromBase45 extends Operation {
17
+
18
+ /**
19
+ * FromBase45 constructor
20
+ */
21
+ constructor() {
22
+ super();
23
+
24
+ this.name = "From Base45";
25
+ this.module = "Default";
26
+ this.description = "Base45 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. Base45 is optimized for usage with QR codes.";
27
+ this.infoURL = "https://wikipedia.org/wiki/List_of_numeral_systems";
28
+ this.inputType = "string";
29
+ this.outputType = "byteArray";
30
+ this.args = [
31
+ {
32
+ name: "Alphabet",
33
+ type: "string",
34
+ value: ALPHABET
35
+ }
36
+ ];
37
+
38
+ this.highlight = highlightFromBase45;
39
+ this.highlightReverse = highlightToBase45;
40
+ }
41
+
42
+ /**
43
+ * @param {string} input
44
+ * @param {Object[]} args
45
+ * @returns {byteArray}
46
+ */
47
+ run(input, args) {
48
+ if (!input) return [];
49
+ const alphabet = Utils.expandAlphRange(args[0]);
50
+
51
+ const res = [];
52
+
53
+ for (const triple of Utils.chunked(input, 3)) {
54
+ triple.reverse();
55
+ let b = 0;
56
+ for (const c of triple) {
57
+ const idx = alphabet.indexOf(c);
58
+ if (idx === -1) {
59
+ throw new OperationError(`Character not in alphabet: '${c}'`);
60
+ }
61
+ b *= 45;
62
+ b += idx;
63
+ }
64
+
65
+ if (b > 65535) {
66
+ throw new OperationError(`Triplet too large: '${triple.join("")}'`);
67
+ }
68
+
69
+ if (triple.length > 2) {
70
+ /**
71
+ * The last triple may only have 2 bytes so we push the MSB when we got 3 bytes
72
+ * Pushing MSB
73
+ */
74
+ res.push(b >> 8);
75
+ }
76
+
77
+ /**
78
+ * Pushing LSB
79
+ */
80
+ res.push(b & 0xff);
81
+
82
+ }
83
+
84
+ return res;
85
+ }
86
+
87
+ }
88
+
89
+ export default FromBase45;
@@ -0,0 +1,78 @@
1
+ /**
2
+ * @author Thomas Weißschuh [thomas@t-8ch.de]
3
+ * @copyright Crown Copyright 2021
4
+ * @license Apache-2.0
5
+ */
6
+
7
+ import {ALPHABET, highlightToBase45, highlightFromBase45} from "../lib/Base45.mjs";
8
+ import Operation from "../Operation.mjs";
9
+ import Utils from "../Utils.mjs";
10
+
11
+ /**
12
+ * To Base45 operation
13
+ */
14
+ class ToBase45 extends Operation {
15
+
16
+ /**
17
+ * ToBase45 constructor
18
+ */
19
+ constructor() {
20
+ super();
21
+
22
+ this.name = "To Base45";
23
+ this.module = "Default";
24
+ this.description = "Base45 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. Base45 is optimized for usage with QR codes.";
25
+ this.infoURL = "https://wikipedia.org/wiki/List_of_numeral_systems";
26
+ this.inputType = "ArrayBuffer";
27
+ this.outputType = "string";
28
+ this.args = [
29
+ {
30
+ name: "Alphabet",
31
+ type: "string",
32
+ value: ALPHABET
33
+ }
34
+ ];
35
+
36
+ this.highlight = highlightToBase45;
37
+ this.highlightReverse = highlightFromBase45;
38
+ }
39
+
40
+ /**
41
+ * @param {ArrayBuffer} input
42
+ * @param {Object[]} args
43
+ * @returns {string}
44
+ */
45
+ run(input, args) {
46
+ input = new Uint8Array(input);
47
+ const alphabet = Utils.expandAlphRange(args[0]);
48
+ if (!input) return "";
49
+
50
+ const res = [];
51
+
52
+ for (const pair of Utils.chunked(input, 2)) {
53
+ let b = 0;
54
+ for (const e of pair) {
55
+ b *= 256;
56
+ b += e;
57
+ }
58
+
59
+ let chars = 0;
60
+ do {
61
+ res.push(alphabet[b % 45]);
62
+ chars++;
63
+ b = Math.floor(b / 45);
64
+ } while (b > 0);
65
+
66
+ if (chars < 2) {
67
+ res.push("0");
68
+ }
69
+ }
70
+
71
+
72
+ return res.join("");
73
+
74
+ }
75
+
76
+ }
77
+
78
+ export default ToBase45;
@@ -120,6 +120,7 @@ import FrequencyDistribution from "./FrequencyDistribution.mjs";
120
120
  import FromBCD from "./FromBCD.mjs";
121
121
  import FromBase from "./FromBase.mjs";
122
122
  import FromBase32 from "./FromBase32.mjs";
123
+ import FromBase45 from "./FromBase45.mjs";
123
124
  import FromBase58 from "./FromBase58.mjs";
124
125
  import FromBase62 from "./FromBase62.mjs";
125
126
  import FromBase64 from "./FromBase64.mjs";
@@ -315,6 +316,7 @@ import TextEncodingBruteForce from "./TextEncodingBruteForce.mjs";
315
316
  import ToBCD from "./ToBCD.mjs";
316
317
  import ToBase from "./ToBase.mjs";
317
318
  import ToBase32 from "./ToBase32.mjs";
319
+ import ToBase45 from "./ToBase45.mjs";
318
320
  import ToBase58 from "./ToBase58.mjs";
319
321
  import ToBase62 from "./ToBase62.mjs";
320
322
  import ToBase64 from "./ToBase64.mjs";
@@ -487,6 +489,7 @@ export {
487
489
  FromBCD,
488
490
  FromBase,
489
491
  FromBase32,
492
+ FromBase45,
490
493
  FromBase58,
491
494
  FromBase62,
492
495
  FromBase64,
@@ -682,6 +685,7 @@ export {
682
685
  ToBCD,
683
686
  ToBase,
684
687
  ToBase32,
688
+ ToBase45,
685
689
  ToBase58,
686
690
  ToBase62,
687
691
  ToBase64,
@@ -127,6 +127,7 @@ import {
127
127
  FromBCD as core_FromBCD,
128
128
  FromBase as core_FromBase,
129
129
  FromBase32 as core_FromBase32,
130
+ FromBase45 as core_FromBase45,
130
131
  FromBase58 as core_FromBase58,
131
132
  FromBase62 as core_FromBase62,
132
133
  FromBase64 as core_FromBase64,
@@ -315,6 +316,7 @@ import {
315
316
  ToBCD as core_ToBCD,
316
317
  ToBase as core_ToBase,
317
318
  ToBase32 as core_ToBase32,
319
+ ToBase45 as core_ToBase45,
318
320
  ToBase58 as core_ToBase58,
319
321
  ToBase62 as core_ToBase62,
320
322
  ToBase64 as core_ToBase64,
@@ -494,6 +496,7 @@ function generateChef() {
494
496
  "fromBCD": _wrap(core_FromBCD),
495
497
  "fromBase": _wrap(core_FromBase),
496
498
  "fromBase32": _wrap(core_FromBase32),
499
+ "fromBase45": _wrap(core_FromBase45),
497
500
  "fromBase58": _wrap(core_FromBase58),
498
501
  "fromBase62": _wrap(core_FromBase62),
499
502
  "fromBase64": _wrap(core_FromBase64),
@@ -682,6 +685,7 @@ function generateChef() {
682
685
  "toBCD": _wrap(core_ToBCD),
683
686
  "toBase": _wrap(core_ToBase),
684
687
  "toBase32": _wrap(core_ToBase32),
688
+ "toBase45": _wrap(core_ToBase45),
685
689
  "toBase58": _wrap(core_ToBase58),
686
690
  "toBase62": _wrap(core_ToBase62),
687
691
  "toBase64": _wrap(core_ToBase64),
@@ -872,6 +876,7 @@ const frequencyDistribution = chef.frequencyDistribution;
872
876
  const fromBCD = chef.fromBCD;
873
877
  const fromBase = chef.fromBase;
874
878
  const fromBase32 = chef.fromBase32;
879
+ const fromBase45 = chef.fromBase45;
875
880
  const fromBase58 = chef.fromBase58;
876
881
  const fromBase62 = chef.fromBase62;
877
882
  const fromBase64 = chef.fromBase64;
@@ -1067,6 +1072,7 @@ const textEncodingBruteForce = chef.textEncodingBruteForce;
1067
1072
  const toBCD = chef.toBCD;
1068
1073
  const toBase = chef.toBase;
1069
1074
  const toBase32 = chef.toBase32;
1075
+ const toBase45 = chef.toBase45;
1070
1076
  const toBase58 = chef.toBase58;
1071
1077
  const toBase62 = chef.toBase62;
1072
1078
  const toBase64 = chef.toBase64;
@@ -1241,6 +1247,7 @@ const operations = [
1241
1247
  fromBCD,
1242
1248
  fromBase,
1243
1249
  fromBase32,
1250
+ fromBase45,
1244
1251
  fromBase58,
1245
1252
  fromBase62,
1246
1253
  fromBase64,
@@ -1436,6 +1443,7 @@ const operations = [
1436
1443
  toBCD,
1437
1444
  toBase,
1438
1445
  toBase32,
1446
+ toBase45,
1439
1447
  toBase58,
1440
1448
  toBase62,
1441
1449
  toBase64,
@@ -1614,6 +1622,7 @@ export {
1614
1622
  fromBCD,
1615
1623
  fromBase,
1616
1624
  fromBase32,
1625
+ fromBase45,
1617
1626
  fromBase58,
1618
1627
  fromBase62,
1619
1628
  fromBase64,
@@ -1809,6 +1818,7 @@ export {
1809
1818
  toBCD,
1810
1819
  toBase,
1811
1820
  toBase32,
1821
+ toBase45,
1812
1822
  toBase58,
1813
1823
  toBase62,
1814
1824
  toBase64,
@@ -20,6 +20,7 @@ import TestRegister from "../lib/TestRegister.mjs";
20
20
  import "./tests/BCD.mjs";
21
21
  import "./tests/BSON.mjs";
22
22
  import "./tests/BaconCipher.mjs";
23
+ import "./tests/Base45.mjs";
23
24
  import "./tests/Base58.mjs";
24
25
  import "./tests/Base64.mjs";
25
26
  import "./tests/Base62.mjs";
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Base45 tests.
3
+ *
4
+ * @author Thomas Weißschuh [thomas@t-8ch.de]
5
+ *
6
+ * @copyright Crown Copyright 2021
7
+ * @license Apache-2.0
8
+ */
9
+
10
+ import TestRegister from "../../lib/TestRegister.mjs";
11
+
12
+ const defaultB45Alph = "0-9A-Z $%*+\\-./:";
13
+
14
+ TestRegister.addTests([
15
+ {
16
+ name: "To Base45: nothing",
17
+ input: "",
18
+ expectedOutput: "",
19
+ recipeConfig: [
20
+ {
21
+ op: "To Base45",
22
+ args: [defaultB45Alph],
23
+ },
24
+ ],
25
+ },
26
+ {
27
+ name: "To Base45: Spec encoding example 1",
28
+ input: "AB",
29
+ expectedOutput: "BB8",
30
+ recipeConfig: [
31
+ {
32
+ op: "To Base45",
33
+ args: [defaultB45Alph],
34
+ },
35
+ ],
36
+ },
37
+ {
38
+ name: "To Base45: Spec encoding example 2",
39
+ input: "Hello!!",
40
+ expectedOutput: "%69 VD92EX0",
41
+ recipeConfig: [
42
+ {
43
+ op: "To Base45",
44
+ args: [defaultB45Alph],
45
+ },
46
+ ],
47
+ },
48
+ {
49
+ name: "To Base45: Spec encoding example 3",
50
+ input: "base-45",
51
+ expectedOutput: "UJCLQE7W581",
52
+ recipeConfig: [
53
+ {
54
+ op: "To Base45",
55
+ args: [defaultB45Alph],
56
+ },
57
+ ],
58
+ },
59
+ {
60
+ name: "From Base45: nothing",
61
+ input: "",
62
+ expectedOutput: "",
63
+ recipeConfig: [
64
+ {
65
+ op: "From Base45",
66
+ args: [defaultB45Alph],
67
+ },
68
+ ],
69
+ },
70
+ {
71
+ name: "From Base45: Spec decoding example 1",
72
+ input: "QED8WEX0",
73
+ expectedOutput: "ietf!",
74
+ recipeConfig: [
75
+ {
76
+ op: "From Base45",
77
+ args: [defaultB45Alph],
78
+ },
79
+ ],
80
+ },
81
+ {
82
+ name: "From Base45: Invalid character",
83
+ input: "!",
84
+ expectedOutput: "Character not in alphabet: '!'",
85
+ recipeConfig: [
86
+ {
87
+ op: "From Base45",
88
+ args: [defaultB45Alph],
89
+ },
90
+ ],
91
+ },
92
+ {
93
+ name: "From Base45: Invalid triplet value",
94
+ input: "ZZZ",
95
+ expectedOutput: "Triplet too large: 'ZZZ'",
96
+ recipeConfig: [
97
+ {
98
+ op: "From Base45",
99
+ args: [defaultB45Alph],
100
+ },
101
+ ],
102
+ },
103
+ ]);