cyberchef 9.50.10 → 9.50.12

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cyberchef",
3
- "version": "9.50.10",
3
+ "version": "9.50.12",
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",
@@ -13086,7 +13086,8 @@
13086
13086
  "Alphabetical (case insensitive)",
13087
13087
  "IP address",
13088
13088
  "Numeric",
13089
- "Numeric (hexadecimal)"
13089
+ "Numeric (hexadecimal)",
13090
+ "Length"
13090
13091
  ]
13091
13092
  }
13092
13093
  ]
@@ -103,3 +103,15 @@ export function hexadecimalSort(a, b) {
103
103
 
104
104
  return a.localeCompare(b);
105
105
  }
106
+
107
+ /**
108
+ * Comparison operation for sorting by length
109
+ *
110
+ * @param {string} a
111
+ * @param {string} b
112
+ * @returns {number}
113
+ */
114
+ export function lengthSort(a, b) {
115
+ return a.length - b.length;
116
+ }
117
+
@@ -35,10 +35,18 @@ class Fletcher32Checksum extends Operation {
35
35
  run(input, args) {
36
36
  let a = 0,
37
37
  b = 0;
38
- input = new Uint8Array(input);
38
+ if (ArrayBuffer.isView(input)) {
39
+ input = new DataView(input.buffer, input.byteOffset, input.byteLength);
40
+ } else {
41
+ input = new DataView(input);
42
+ }
39
43
 
40
- for (let i = 0; i < input.length; i++) {
41
- a = (a + input[i]) % 0xffff;
44
+ for (let i = 0; i < input.byteLength - 1; i += 2) {
45
+ a = (a + input.getUint16(i, true)) % 0xffff;
46
+ b = (b + a) % 0xffff;
47
+ }
48
+ if (input.byteLength % 2 !== 0) {
49
+ a = (a + input.getUint8(input.byteLength - 1)) % 0xffff;
42
50
  b = (b + a) % 0xffff;
43
51
  }
44
52
 
@@ -35,10 +35,22 @@ class Fletcher64Checksum extends Operation {
35
35
  run(input, args) {
36
36
  let a = 0,
37
37
  b = 0;
38
- input = new Uint8Array(input);
38
+ if (ArrayBuffer.isView(input)) {
39
+ input = new DataView(input.buffer, input.byteOffset, input.byteLength);
40
+ } else {
41
+ input = new DataView(input);
42
+ }
39
43
 
40
- for (let i = 0; i < input.length; i++) {
41
- a = (a + input[i]) % 0xffffffff;
44
+ for (let i = 0; i < input.byteLength - 3; i += 4) {
45
+ a = (a + input.getUint32(i, true)) % 0xffffffff;
46
+ b = (b + a) % 0xffffffff;
47
+ }
48
+ if (input.byteLength % 4 !== 0) {
49
+ let lastValue = 0;
50
+ for (let i = 0; i < input.byteLength % 4; i++) {
51
+ lastValue = (lastValue << 8) | input.getUint8(input.byteLength - 1 - i);
52
+ }
53
+ a = (a + lastValue) % 0xffffffff;
42
54
  b = (b + a) % 0xffffffff;
43
55
  }
44
56
 
@@ -7,7 +7,7 @@
7
7
  import Operation from "../Operation.mjs";
8
8
  import Utils from "../Utils.mjs";
9
9
  import {INPUT_DELIM_OPTIONS} from "../lib/Delim.mjs";
10
- import {caseInsensitiveSort, ipSort, numericSort, hexadecimalSort} from "../lib/Sort.mjs";
10
+ import {caseInsensitiveSort, ipSort, numericSort, hexadecimalSort, lengthSort} from "../lib/Sort.mjs";
11
11
 
12
12
  /**
13
13
  * Sort operation
@@ -39,7 +39,7 @@ class Sort extends Operation {
39
39
  {
40
40
  "name": "Order",
41
41
  "type": "option",
42
- "value": ["Alphabetical (case sensitive)", "Alphabetical (case insensitive)", "IP address", "Numeric", "Numeric (hexadecimal)"]
42
+ "value": ["Alphabetical (case sensitive)", "Alphabetical (case insensitive)", "IP address", "Numeric", "Numeric (hexadecimal)", "Length"]
43
43
  }
44
44
  ];
45
45
  }
@@ -65,6 +65,8 @@ class Sort extends Operation {
65
65
  sorted = sorted.sort(numericSort);
66
66
  } else if (order === "Numeric (hexadecimal)") {
67
67
  sorted = sorted.sort(hexadecimalSort);
68
+ } else if (order === "Length") {
69
+ sorted = sorted.sort(lengthSort);
68
70
  }
69
71
 
70
72
  if (sortReverse) sorted.reverse();
@@ -125,6 +125,7 @@ import "./tests/LS47.mjs";
125
125
  import "./tests/LZString.mjs";
126
126
  import "./tests/NTLM.mjs";
127
127
  import "./tests/Shuffle.mjs";
128
+ import "./tests/FletcherChecksum.mjs";
128
129
 
129
130
  // Cannot test operations that use the File type yet
130
131
  // import "./tests/SplitColourChannels.mjs";
@@ -0,0 +1,108 @@
1
+ /**
2
+ * @author mikecat
3
+ * @copyright Crown Copyright 2022
4
+ * @license Apache-2.0
5
+ */
6
+ import TestRegister from "../../lib/TestRegister.mjs";
7
+
8
+ TestRegister.addTests([
9
+ {
10
+ name: "Fletcher-16 Checksum: abcde",
11
+ input: "abcde",
12
+ expectedOutput: "c8f0",
13
+ recipeConfig: [
14
+ {
15
+ op: "Fletcher-16 Checksum",
16
+ args: [],
17
+ },
18
+ ],
19
+ },
20
+ {
21
+ name: "Fletcher-16 Checksum: abcdef",
22
+ input: "abcdef",
23
+ expectedOutput: "2057",
24
+ recipeConfig: [
25
+ {
26
+ op: "Fletcher-16 Checksum",
27
+ args: [],
28
+ },
29
+ ],
30
+ },
31
+ {
32
+ name: "Fletcher-16 Checksum: abcdefgh",
33
+ input: "abcdefgh",
34
+ expectedOutput: "0627",
35
+ recipeConfig: [
36
+ {
37
+ op: "Fletcher-16 Checksum",
38
+ args: [],
39
+ },
40
+ ],
41
+ },
42
+ {
43
+ name: "Fletcher-32 Checksum: abcde",
44
+ input: "abcde",
45
+ expectedOutput: "f04fc729",
46
+ recipeConfig: [
47
+ {
48
+ op: "Fletcher-32 Checksum",
49
+ args: [],
50
+ },
51
+ ],
52
+ },
53
+ {
54
+ name: "Fletcher-32 Checksum: abcdef",
55
+ input: "abcdef",
56
+ expectedOutput: "56502d2a",
57
+ recipeConfig: [
58
+ {
59
+ op: "Fletcher-32 Checksum",
60
+ args: [],
61
+ },
62
+ ],
63
+ },
64
+ {
65
+ name: "Fletcher-32 Checksum: abcdefgh",
66
+ input: "abcdefgh",
67
+ expectedOutput: "ebe19591",
68
+ recipeConfig: [
69
+ {
70
+ op: "Fletcher-32 Checksum",
71
+ args: [],
72
+ },
73
+ ],
74
+ },
75
+ {
76
+ name: "Fletcher-64 Checksum: abcde",
77
+ input: "abcde",
78
+ expectedOutput: "c8c6c527646362c6",
79
+ recipeConfig: [
80
+ {
81
+ op: "Fletcher-64 Checksum",
82
+ args: [],
83
+ },
84
+ ],
85
+ },
86
+ {
87
+ name: "Fletcher-64 Checksum: abcdef",
88
+ input: "abcdef",
89
+ expectedOutput: "c8c72b276463c8c6",
90
+ recipeConfig: [
91
+ {
92
+ op: "Fletcher-64 Checksum",
93
+ args: [],
94
+ },
95
+ ],
96
+ },
97
+ {
98
+ name: "Fletcher-64 Checksum: abcdefgh",
99
+ input: "abcdefgh",
100
+ expectedOutput: "312e2b28cccac8c6",
101
+ recipeConfig: [
102
+ {
103
+ op: "Fletcher-64 Checksum",
104
+ args: [],
105
+ },
106
+ ],
107
+ },
108
+ ]);
@@ -58,8 +58,8 @@ CTPH: A:E:E
58
58
  Checksums:
59
59
  Fletcher-8: 3d
60
60
  Fletcher-16: 5dc1
61
- Fletcher-32: 045901c0
62
- Fletcher-64: 00000459000001c0
61
+ Fletcher-32: 3f5cd9e7
62
+ Fletcher-64: 7473657474736574
63
63
  Adler-32: 045d01c1
64
64
  CRC-8: b9
65
65
  CRC-16: f82e