cyberchef 11.2.0 → 11.3.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.
Files changed (134) hide show
  1. package/AGENTS.md +75 -0
  2. package/CHANGELOG.md +147 -1
  3. package/Dockerfile +2 -2
  4. package/Gruntfile.js +1 -0
  5. package/package.json +22 -21
  6. package/src/core/Dish.mjs +1 -5
  7. package/src/core/Ingredient.mjs +92 -0
  8. package/src/core/Operation.mjs +19 -0
  9. package/src/core/Recipe.mjs +4 -0
  10. package/src/core/Utils.mjs +48 -0
  11. package/src/core/config/Categories.json +22 -6
  12. package/src/core/config/OperationConfig.json +4771 -1226
  13. package/src/core/config/modules/Ciphers.mjs +20 -0
  14. package/src/core/config/modules/Crypto.mjs +10 -0
  15. package/src/core/config/modules/Default.mjs +8 -0
  16. package/src/core/config/modules/File.mjs +16 -0
  17. package/src/core/config/modules/OpModules.mjs +2 -0
  18. package/src/core/config/scripts/generateHTMLEntities.mjs +139 -0
  19. package/src/core/config/scripts/htmlEntityOverrides.mjs +86 -0
  20. package/src/core/lib/Arithmetic.mjs +21 -5
  21. package/src/core/lib/BigIntUtils.mjs +0 -1
  22. package/src/core/lib/COBS.mjs +86 -0
  23. package/src/core/lib/Decimal.mjs +5 -5
  24. package/src/core/lib/HTMLEntities.mjs +2068 -0
  25. package/src/core/lib/Present.mjs +422 -0
  26. package/src/core/lib/TEA.mjs +494 -0
  27. package/src/core/lib/TLVParser.mjs +16 -7
  28. package/src/core/lib/Twofish.mjs +608 -0
  29. package/src/core/operations/AsconDecrypt.mjs +112 -0
  30. package/src/core/operations/AsconEncrypt.mjs +108 -0
  31. package/src/core/operations/AsconHash.mjs +49 -0
  32. package/src/core/operations/AsconMAC.mjs +68 -0
  33. package/src/core/operations/AutomatedValidationTestOp.mjs +84 -0
  34. package/src/core/operations/AvroToJSON.mjs +1 -1
  35. package/src/core/operations/BLAKE3.mjs +5 -1
  36. package/src/core/operations/BcryptCompare.mjs +11 -5
  37. package/src/core/operations/BitShiftLeft.mjs +4 -1
  38. package/src/core/operations/Bzip2Compress.mjs +1 -1
  39. package/src/core/operations/DechunkHTTPResponse.mjs +4 -1
  40. package/src/core/operations/ExtendedGCD.mjs +101 -0
  41. package/src/core/operations/FromBase.mjs +2 -1
  42. package/src/core/operations/FromCOBS.mjs +38 -0
  43. package/src/core/operations/FromDecimal.mjs +6 -1
  44. package/src/core/operations/FromHTMLEntity.mjs +2 -1458
  45. package/src/core/operations/GenerateHOTP.mjs +21 -6
  46. package/src/core/operations/GenerateImage.mjs +22 -10
  47. package/src/core/operations/GeneratePrime.mjs +154 -0
  48. package/src/core/operations/GenerateTOTP.mjs +24 -7
  49. package/src/core/operations/Gzip.mjs +1 -3
  50. package/src/core/operations/Jsonata.mjs +12 -0
  51. package/src/core/operations/MIMEDecoding.mjs +1 -1
  52. package/src/core/operations/MOD.mjs +62 -0
  53. package/src/core/operations/ModularInverse.mjs +107 -0
  54. package/src/core/operations/PRESENTDecrypt.mjs +94 -0
  55. package/src/core/operations/PRESENTEncrypt.mjs +94 -0
  56. package/src/core/operations/ParseURI.mjs +18 -5
  57. package/src/core/operations/PseudoRandomNumberGenerator.mjs +2 -1
  58. package/src/core/operations/RandomPrime.mjs +154 -0
  59. package/src/core/operations/RenderPDF.mjs +100 -0
  60. package/src/core/operations/SM4Encrypt.mjs +1 -1
  61. package/src/core/operations/SetDifference.mjs +8 -1
  62. package/src/core/operations/SetIntersection.mjs +8 -1
  63. package/src/core/operations/ShowOnMap.mjs +14 -2
  64. package/src/core/operations/TEADecrypt.mjs +98 -0
  65. package/src/core/operations/TEAEncrypt.mjs +98 -0
  66. package/src/core/operations/ToBase.mjs +4 -4
  67. package/src/core/operations/ToBase32.mjs +20 -4
  68. package/src/core/operations/ToBinary.mjs +4 -1
  69. package/src/core/operations/ToCOBS.mjs +38 -0
  70. package/src/core/operations/ToHTMLEntity.mjs +7 -1430
  71. package/src/core/operations/TwofishDecrypt.mjs +94 -0
  72. package/src/core/operations/TwofishEncrypt.mjs +94 -0
  73. package/src/core/operations/URLEncode.mjs +22 -18
  74. package/src/core/operations/UnescapeUnicodeCharacters.mjs +2 -1
  75. package/src/core/operations/ViewBitPlane.mjs +9 -3
  76. package/src/core/operations/Wrap.mjs +5 -0
  77. package/src/core/operations/XORBruteForce.mjs +4 -1
  78. package/src/core/operations/XORChecksum.mjs +2 -2
  79. package/src/core/operations/XTEADecrypt.mjs +110 -0
  80. package/src/core/operations/XTEAEncrypt.mjs +110 -0
  81. package/src/core/operations/index.mjs +42 -0
  82. package/src/core/vendor/ascon.mjs +162 -0
  83. package/src/core/vendor/htmlEntities/entity.json +2233 -0
  84. package/src/core/vendor/htmlEntities/entity.txt +14 -0
  85. package/src/node/api.mjs +4 -1
  86. package/src/node/index.mjs +105 -0
  87. package/src/web/HTMLOperation.mjs +2 -1
  88. package/src/web/stylesheets/layout/_io.css +8 -0
  89. package/tests/browser/00_nightwatch.js +26 -0
  90. package/tests/browser/02_ops.js +20 -4
  91. package/tests/node/index.mjs +1 -0
  92. package/tests/node/tests/Dish.mjs +19 -0
  93. package/tests/node/tests/NodeDish.mjs +36 -0
  94. package/tests/node/tests/ToHTMLEntity.mjs +82 -0
  95. package/tests/node/tests/Utils.mjs +77 -0
  96. package/tests/node/tests/nodeApi.mjs +33 -1
  97. package/tests/node/tests/operations.mjs +26 -1
  98. package/tests/operations/index.mjs +17 -0
  99. package/tests/operations/tests/Arithmetic.mjs +33 -0
  100. package/tests/operations/tests/Ascon.mjs +501 -0
  101. package/tests/operations/tests/AutomatedValidation.mjs +154 -0
  102. package/tests/operations/tests/BLAKE3.mjs +39 -1
  103. package/tests/operations/tests/Base32.mjs +22 -0
  104. package/tests/operations/tests/COBS.mjs +476 -0
  105. package/tests/operations/tests/CharEnc.mjs +2 -2
  106. package/tests/operations/tests/DechunkHTTPResponse.mjs +66 -0
  107. package/tests/operations/tests/ExtendedGCD.mjs +78 -0
  108. package/tests/operations/tests/FromBase.mjs +66 -0
  109. package/tests/operations/tests/FromDecimal.mjs +55 -0
  110. package/tests/operations/tests/GenerateLoremIpsum.mjs +2 -2
  111. package/tests/operations/tests/Gzip.mjs +60 -0
  112. package/tests/operations/tests/HTMLEntity.mjs +126 -0
  113. package/tests/operations/tests/Hash.mjs +44 -0
  114. package/tests/operations/tests/Hexdump.mjs +1 -1
  115. package/tests/operations/tests/Image.mjs +26 -0
  116. package/tests/operations/tests/Jsonata.mjs +23 -0
  117. package/tests/operations/tests/MIMEDecoding.mjs +33 -0
  118. package/tests/operations/tests/MOD.mjs +208 -0
  119. package/tests/operations/tests/Median.mjs +33 -0
  120. package/tests/operations/tests/ModularInverse.mjs +78 -0
  121. package/tests/operations/tests/OTP.mjs +167 -2
  122. package/tests/operations/tests/PRESENT.mjs +465 -0
  123. package/tests/operations/tests/ParseTLV.mjs +41 -0
  124. package/tests/operations/tests/RenderPDF.mjs +55 -0
  125. package/tests/operations/tests/SM2.mjs +1 -1
  126. package/tests/operations/tests/SetDifference.mjs +22 -0
  127. package/tests/operations/tests/SetIntersection.mjs +23 -1
  128. package/tests/operations/tests/ShowOnMap.mjs +61 -0
  129. package/tests/operations/tests/TEA.mjs +566 -0
  130. package/tests/operations/tests/Twofish.mjs +486 -0
  131. package/tests/operations/tests/URLEncodeDecode.mjs +26 -0
  132. package/tests/operations/tests/UnescapeUnicodeCharacters.mjs +88 -0
  133. package/tests/operations/tests/Wrap.mjs +44 -0
  134. package/webpack.config.js +3 -3
@@ -0,0 +1,486 @@
1
+ /**
2
+ * Twofish cipher tests.
3
+ *
4
+ * Test vectors from the official Twofish paper:
5
+ * https://www.schneier.com/academic/twofish/
6
+ *
7
+ * Note: PKCS5 padding adds an extra block when input is exactly block-aligned.
8
+ * Round-trip tests verify correct encryption/decryption behavior.
9
+ *
10
+ * @author Medjedtxm
11
+ * @copyright Crown Copyright 2026
12
+ * @license Apache-2.0
13
+ */
14
+
15
+ import TestRegister from "../../lib/TestRegister.mjs";
16
+
17
+ TestRegister.addTests([
18
+ // ============================================================
19
+ // OFFICIAL TEST VECTORS from Bruce Schneier's Twofish paper:
20
+ // https://www.schneier.com/academic/twofish/
21
+ // https://www.schneier.com/wp-content/uploads/2015/12/ecb_ival.txt
22
+ // ============================================================
23
+ {
24
+ name: "Twofish Official Vector: 128-bit zero key, zero plaintext",
25
+ input: "00000000000000000000000000000000",
26
+ expectedOutput: "9f589f5cf6122c32b6bfec2f2ae8c35a",
27
+ recipeConfig: [
28
+ {
29
+ op: "Twofish Encrypt",
30
+ args: [
31
+ { string: "00000000000000000000000000000000", option: "Hex" },
32
+ { string: "", option: "Hex" },
33
+ "ECB", "Hex", "Hex", "NO"
34
+ ]
35
+ }
36
+ ]
37
+ },
38
+ {
39
+ name: "Twofish Official Vector: 192-bit zero key, zero plaintext",
40
+ input: "00000000000000000000000000000000",
41
+ expectedOutput: "efa71f788965bd4453f860178fc19101",
42
+ recipeConfig: [
43
+ {
44
+ op: "Twofish Encrypt",
45
+ args: [
46
+ { string: "000000000000000000000000000000000000000000000000", option: "Hex" },
47
+ { string: "", option: "Hex" },
48
+ "ECB", "Hex", "Hex", "NO"
49
+ ]
50
+ }
51
+ ]
52
+ },
53
+ {
54
+ name: "Twofish Official Vector: 256-bit zero key, zero plaintext",
55
+ input: "00000000000000000000000000000000",
56
+ expectedOutput: "57ff739d4dc92c1bd7fc01700cc8216f",
57
+ recipeConfig: [
58
+ {
59
+ op: "Twofish Encrypt",
60
+ args: [
61
+ { string: "0000000000000000000000000000000000000000000000000000000000000000", option: "Hex" },
62
+ { string: "", option: "Hex" },
63
+ "ECB", "Hex", "Hex", "NO"
64
+ ]
65
+ }
66
+ ]
67
+ },
68
+ // Decrypt verification of official vectors
69
+ {
70
+ name: "Twofish Official Vector Decrypt: 128-bit zero key",
71
+ input: "9f589f5cf6122c32b6bfec2f2ae8c35a",
72
+ expectedOutput: "00000000000000000000000000000000",
73
+ recipeConfig: [
74
+ {
75
+ op: "Twofish Decrypt",
76
+ args: [
77
+ { string: "00000000000000000000000000000000", option: "Hex" },
78
+ { string: "", option: "Hex" },
79
+ "ECB", "Hex", "Hex", "NO"
80
+ ]
81
+ }
82
+ ]
83
+ },
84
+ // ============================================================
85
+ // Round-trip tests for ECB mode with various key sizes
86
+ // ============================================================
87
+ {
88
+ name: "Twofish Round-trip: ECB 128-bit key",
89
+ input: "Hello, World!!!",
90
+ expectedOutput: "Hello, World!!!",
91
+ recipeConfig: [
92
+ {
93
+ op: "Twofish Encrypt",
94
+ args: [
95
+ { string: "00112233445566778899aabbccddeeff", option: "Hex" },
96
+ { string: "", option: "Hex" },
97
+ "ECB", "Raw", "Hex", "PKCS5"
98
+ ]
99
+ },
100
+ {
101
+ op: "Twofish Decrypt",
102
+ args: [
103
+ { string: "00112233445566778899aabbccddeeff", option: "Hex" },
104
+ { string: "", option: "Hex" },
105
+ "ECB", "Hex", "Raw", "PKCS5"
106
+ ]
107
+ }
108
+ ]
109
+ },
110
+ {
111
+ name: "Twofish Round-trip: ECB 192-bit key",
112
+ input: "Testing Twofish with 192-bit key",
113
+ expectedOutput: "Testing Twofish with 192-bit key",
114
+ recipeConfig: [
115
+ {
116
+ op: "Twofish Encrypt",
117
+ args: [
118
+ { string: "000102030405060708090a0b0c0d0e0f1011121314151617", option: "Hex" },
119
+ { string: "", option: "Hex" },
120
+ "ECB", "Raw", "Hex", "PKCS5"
121
+ ]
122
+ },
123
+ {
124
+ op: "Twofish Decrypt",
125
+ args: [
126
+ { string: "000102030405060708090a0b0c0d0e0f1011121314151617", option: "Hex" },
127
+ { string: "", option: "Hex" },
128
+ "ECB", "Hex", "Raw", "PKCS5"
129
+ ]
130
+ }
131
+ ]
132
+ },
133
+ {
134
+ name: "Twofish Round-trip: ECB 256-bit key",
135
+ input: "Testing Twofish with 256-bit key encryption",
136
+ expectedOutput: "Testing Twofish with 256-bit key encryption",
137
+ recipeConfig: [
138
+ {
139
+ op: "Twofish Encrypt",
140
+ args: [
141
+ { string: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", option: "Hex" },
142
+ { string: "", option: "Hex" },
143
+ "ECB", "Raw", "Hex", "PKCS5"
144
+ ]
145
+ },
146
+ {
147
+ op: "Twofish Decrypt",
148
+ args: [
149
+ { string: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", option: "Hex" },
150
+ { string: "", option: "Hex" },
151
+ "ECB", "Hex", "Raw", "PKCS5"
152
+ ]
153
+ }
154
+ ]
155
+ },
156
+
157
+ // Round-trip tests for CBC mode
158
+ {
159
+ name: "Twofish Round-trip: CBC 128-bit key",
160
+ input: "The quick brown fox jumps over the lazy dog",
161
+ expectedOutput: "The quick brown fox jumps over the lazy dog",
162
+ recipeConfig: [
163
+ {
164
+ op: "Twofish Encrypt",
165
+ args: [
166
+ { string: "00112233445566778899aabbccddeeff", option: "Hex" },
167
+ { string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
168
+ "CBC", "Raw", "Hex", "PKCS5"
169
+ ]
170
+ },
171
+ {
172
+ op: "Twofish Decrypt",
173
+ args: [
174
+ { string: "00112233445566778899aabbccddeeff", option: "Hex" },
175
+ { string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
176
+ "CBC", "Hex", "Raw", "PKCS5"
177
+ ]
178
+ }
179
+ ]
180
+ },
181
+ {
182
+ name: "Twofish Round-trip: CBC 192-bit key",
183
+ input: "Testing Twofish with 192-bit key in CBC mode",
184
+ expectedOutput: "Testing Twofish with 192-bit key in CBC mode",
185
+ recipeConfig: [
186
+ {
187
+ op: "Twofish Encrypt",
188
+ args: [
189
+ { string: "000102030405060708090a0b0c0d0e0f1011121314151617", option: "Hex" },
190
+ { string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
191
+ "CBC", "Raw", "Hex", "PKCS5"
192
+ ]
193
+ },
194
+ {
195
+ op: "Twofish Decrypt",
196
+ args: [
197
+ { string: "000102030405060708090a0b0c0d0e0f1011121314151617", option: "Hex" },
198
+ { string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
199
+ "CBC", "Hex", "Raw", "PKCS5"
200
+ ]
201
+ }
202
+ ]
203
+ },
204
+ {
205
+ name: "Twofish Round-trip: CBC 256-bit key",
206
+ input: "Testing Twofish with 256-bit key in CBC mode",
207
+ expectedOutput: "Testing Twofish with 256-bit key in CBC mode",
208
+ recipeConfig: [
209
+ {
210
+ op: "Twofish Encrypt",
211
+ args: [
212
+ { string: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", option: "Hex" },
213
+ { string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
214
+ "CBC", "Raw", "Hex", "PKCS5"
215
+ ]
216
+ },
217
+ {
218
+ op: "Twofish Decrypt",
219
+ args: [
220
+ { string: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", option: "Hex" },
221
+ { string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
222
+ "CBC", "Hex", "Raw", "PKCS5"
223
+ ]
224
+ }
225
+ ]
226
+ },
227
+
228
+ // Round-trip tests for CFB mode
229
+ {
230
+ name: "Twofish Round-trip: CFB 128-bit key",
231
+ input: "Testing Twofish CFB mode encryption",
232
+ expectedOutput: "Testing Twofish CFB mode encryption",
233
+ recipeConfig: [
234
+ {
235
+ op: "Twofish Encrypt",
236
+ args: [
237
+ { string: "deadbeefcafebabe0123456789abcdef", option: "Hex" },
238
+ { string: "0102030405060708090a0b0c0d0e0f10", option: "Hex" },
239
+ "CFB", "Raw", "Hex", "PKCS5"
240
+ ]
241
+ },
242
+ {
243
+ op: "Twofish Decrypt",
244
+ args: [
245
+ { string: "deadbeefcafebabe0123456789abcdef", option: "Hex" },
246
+ { string: "0102030405060708090a0b0c0d0e0f10", option: "Hex" },
247
+ "CFB", "Hex", "Raw", "PKCS5"
248
+ ]
249
+ }
250
+ ]
251
+ },
252
+
253
+ // Round-trip tests for OFB mode
254
+ {
255
+ name: "Twofish Round-trip: OFB 128-bit key",
256
+ input: "Testing Twofish OFB mode encryption",
257
+ expectedOutput: "Testing Twofish OFB mode encryption",
258
+ recipeConfig: [
259
+ {
260
+ op: "Twofish Encrypt",
261
+ args: [
262
+ { string: "00112233445566778899aabbccddeeff", option: "Hex" },
263
+ { string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
264
+ "OFB", "Raw", "Hex", "PKCS5"
265
+ ]
266
+ },
267
+ {
268
+ op: "Twofish Decrypt",
269
+ args: [
270
+ { string: "00112233445566778899aabbccddeeff", option: "Hex" },
271
+ { string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
272
+ "OFB", "Hex", "Raw", "PKCS5"
273
+ ]
274
+ }
275
+ ]
276
+ },
277
+
278
+ // Round-trip tests for CTR mode
279
+ {
280
+ name: "Twofish Round-trip: CTR 128-bit key",
281
+ input: "Testing Twofish CTR mode encryption",
282
+ expectedOutput: "Testing Twofish CTR mode encryption",
283
+ recipeConfig: [
284
+ {
285
+ op: "Twofish Encrypt",
286
+ args: [
287
+ { string: "00112233445566778899aabbccddeeff", option: "Hex" },
288
+ { string: "00000000000000000000000000000001", option: "Hex" },
289
+ "CTR", "Raw", "Hex", "PKCS5"
290
+ ]
291
+ },
292
+ {
293
+ op: "Twofish Decrypt",
294
+ args: [
295
+ { string: "00112233445566778899aabbccddeeff", option: "Hex" },
296
+ { string: "00000000000000000000000000000001", option: "Hex" },
297
+ "CTR", "Hex", "Raw", "PKCS5"
298
+ ]
299
+ }
300
+ ]
301
+ },
302
+
303
+ // UTF8 key tests
304
+ {
305
+ name: "Twofish Round-trip: UTF8 key (16 bytes)",
306
+ input: "Secret message!",
307
+ expectedOutput: "Secret message!",
308
+ recipeConfig: [
309
+ {
310
+ op: "Twofish Encrypt",
311
+ args: [
312
+ { string: "MySecretPassword", option: "UTF8" },
313
+ { string: "InitVectorHere!!", option: "UTF8" },
314
+ "CBC", "Raw", "Hex", "PKCS5"
315
+ ]
316
+ },
317
+ {
318
+ op: "Twofish Decrypt",
319
+ args: [
320
+ { string: "MySecretPassword", option: "UTF8" },
321
+ { string: "InitVectorHere!!", option: "UTF8" },
322
+ "CBC", "Hex", "Raw", "PKCS5"
323
+ ]
324
+ }
325
+ ]
326
+ },
327
+
328
+ // Various input length tests
329
+ {
330
+ name: "Twofish Round-trip: 1 byte input",
331
+ input: "A",
332
+ expectedOutput: "A",
333
+ recipeConfig: [
334
+ {
335
+ op: "Twofish Encrypt",
336
+ args: [
337
+ { string: "00112233445566778899aabbccddeeff", option: "Hex" },
338
+ { string: "", option: "Hex" },
339
+ "ECB", "Raw", "Hex", "PKCS5"
340
+ ]
341
+ },
342
+ {
343
+ op: "Twofish Decrypt",
344
+ args: [
345
+ { string: "00112233445566778899aabbccddeeff", option: "Hex" },
346
+ { string: "", option: "Hex" },
347
+ "ECB", "Hex", "Raw", "PKCS5"
348
+ ]
349
+ }
350
+ ]
351
+ },
352
+ {
353
+ name: "Twofish Round-trip: 15 byte input",
354
+ input: "123456789012345",
355
+ expectedOutput: "123456789012345",
356
+ recipeConfig: [
357
+ {
358
+ op: "Twofish Encrypt",
359
+ args: [
360
+ { string: "00112233445566778899aabbccddeeff", option: "Hex" },
361
+ { string: "", option: "Hex" },
362
+ "ECB", "Raw", "Hex", "PKCS5"
363
+ ]
364
+ },
365
+ {
366
+ op: "Twofish Decrypt",
367
+ args: [
368
+ { string: "00112233445566778899aabbccddeeff", option: "Hex" },
369
+ { string: "", option: "Hex" },
370
+ "ECB", "Hex", "Raw", "PKCS5"
371
+ ]
372
+ }
373
+ ]
374
+ },
375
+ {
376
+ name: "Twofish Round-trip: 16 byte input (exact block)",
377
+ input: "1234567890123456",
378
+ expectedOutput: "1234567890123456",
379
+ recipeConfig: [
380
+ {
381
+ op: "Twofish Encrypt",
382
+ args: [
383
+ { string: "00112233445566778899aabbccddeeff", option: "Hex" },
384
+ { string: "", option: "Hex" },
385
+ "ECB", "Raw", "Hex", "PKCS5"
386
+ ]
387
+ },
388
+ {
389
+ op: "Twofish Decrypt",
390
+ args: [
391
+ { string: "00112233445566778899aabbccddeeff", option: "Hex" },
392
+ { string: "", option: "Hex" },
393
+ "ECB", "Hex", "Raw", "PKCS5"
394
+ ]
395
+ }
396
+ ]
397
+ },
398
+ {
399
+ name: "Twofish Round-trip: 17 byte input",
400
+ input: "12345678901234567",
401
+ expectedOutput: "12345678901234567",
402
+ recipeConfig: [
403
+ {
404
+ op: "Twofish Encrypt",
405
+ args: [
406
+ { string: "00112233445566778899aabbccddeeff", option: "Hex" },
407
+ { string: "", option: "Hex" },
408
+ "ECB", "Raw", "Hex", "PKCS5"
409
+ ]
410
+ },
411
+ {
412
+ op: "Twofish Decrypt",
413
+ args: [
414
+ { string: "00112233445566778899aabbccddeeff", option: "Hex" },
415
+ { string: "", option: "Hex" },
416
+ "ECB", "Hex", "Raw", "PKCS5"
417
+ ]
418
+ }
419
+ ]
420
+ },
421
+ {
422
+ name: "Twofish Round-trip: 32 byte input (two blocks)",
423
+ input: "12345678901234567890123456789012",
424
+ expectedOutput: "12345678901234567890123456789012",
425
+ recipeConfig: [
426
+ {
427
+ op: "Twofish Encrypt",
428
+ args: [
429
+ { string: "00112233445566778899aabbccddeeff", option: "Hex" },
430
+ { string: "", option: "Hex" },
431
+ "ECB", "Raw", "Hex", "PKCS5"
432
+ ]
433
+ },
434
+ {
435
+ op: "Twofish Decrypt",
436
+ args: [
437
+ { string: "00112233445566778899aabbccddeeff", option: "Hex" },
438
+ { string: "", option: "Hex" },
439
+ "ECB", "Hex", "Raw", "PKCS5"
440
+ ]
441
+ }
442
+ ]
443
+ },
444
+
445
+ // Binary data test
446
+ {
447
+ name: "Twofish Round-trip: Binary data",
448
+ input: "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
449
+ expectedOutput: "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
450
+ recipeConfig: [
451
+ {
452
+ op: "Twofish Encrypt",
453
+ args: [
454
+ { string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
455
+ { string: "00112233445566778899aabbccddeeff", option: "Hex" },
456
+ "CBC", "Raw", "Hex", "PKCS5"
457
+ ]
458
+ },
459
+ {
460
+ op: "Twofish Decrypt",
461
+ args: [
462
+ { string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
463
+ { string: "00112233445566778899aabbccddeeff", option: "Hex" },
464
+ "CBC", "Hex", "Raw", "PKCS5"
465
+ ]
466
+ }
467
+ ]
468
+ },
469
+
470
+ // Consistency test - same input should always produce same output
471
+ {
472
+ name: "Twofish Encrypt: 128-bit key consistency test",
473
+ input: "TestData12345678",
474
+ expectedOutput: "8aed2d3a85dc3e0b663ba1fe1fdaf056771d591428af301d69fa1e227d083527",
475
+ recipeConfig: [
476
+ {
477
+ op: "Twofish Encrypt",
478
+ args: [
479
+ { string: "00000000000000000000000000000000", option: "Hex" },
480
+ { string: "", option: "Hex" },
481
+ "ECB", "Raw", "Hex", "PKCS5"
482
+ ]
483
+ }
484
+ ]
485
+ }
486
+ ]);
@@ -89,4 +89,30 @@ TestRegister.addTests([
89
89
  },
90
90
  ],
91
91
  },
92
+ {
93
+ name: "URLEncode: encodes UTF-8 text as UTF-8 bytes",
94
+ input: "你好",
95
+ expectedOutput: "%E4%BD%A0%E5%A5%BD",
96
+ recipeConfig: [
97
+ {
98
+ op: "URL Encode",
99
+ args: [false],
100
+ },
101
+ ],
102
+ },
103
+ {
104
+ name: "URLEncode: preserves raw bytes from From Hex",
105
+ input: "6c6567697466696c6580000000000000000000000000000000000000000000000000000000000000000000000000000000000000000090746869737761737375706f736564746f6265616e6578706c6f6974",
106
+ expectedOutput: "legitfile%80%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%90thiswassuposedtobeanexploit",
107
+ recipeConfig: [
108
+ {
109
+ op: "From Hex",
110
+ args: ["None"],
111
+ },
112
+ {
113
+ op: "URL Encode",
114
+ args: [false],
115
+ },
116
+ ],
117
+ },
92
118
  ]);
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Unescape Unicode Characters operation tests.
3
+ *
4
+ * @author williballenthin
5
+ * @copyright Crown Copyright 2024
6
+ * @license Apache-2.0
7
+ */
8
+ import TestRegister from "../../lib/TestRegister.mjs";
9
+
10
+ TestRegister.addTests([
11
+ {
12
+ name: "Unescape Unicode Characters: \\u 4-digit BMP",
13
+ input: "\\u03c3\\u03bf\\u03c5",
14
+ expectedOutput: "σου",
15
+ recipeConfig: [
16
+ {
17
+ op: "Unescape Unicode Characters",
18
+ args: ["\\u"],
19
+ },
20
+ ],
21
+ },
22
+ {
23
+ name: "Unescape Unicode Characters: %u 4-digit BMP",
24
+ input: "%u03c3%u03bf%u03c5",
25
+ expectedOutput: "σου",
26
+ recipeConfig: [
27
+ {
28
+ op: "Unescape Unicode Characters",
29
+ args: ["%u"],
30
+ },
31
+ ],
32
+ },
33
+ {
34
+ name: "Unescape Unicode Characters: U+ 4-digit BMP",
35
+ input: "U+0041",
36
+ expectedOutput: "A",
37
+ recipeConfig: [
38
+ {
39
+ op: "Unescape Unicode Characters",
40
+ args: ["U+"],
41
+ },
42
+ ],
43
+ },
44
+ {
45
+ name: "Unescape Unicode Characters: U+ 5-digit astral plane emoji",
46
+ input: "U+1F600",
47
+ expectedOutput: "\u{1F600}",
48
+ recipeConfig: [
49
+ {
50
+ op: "Unescape Unicode Characters",
51
+ args: ["U+"],
52
+ },
53
+ ],
54
+ },
55
+ {
56
+ name: "Unescape Unicode Characters: U+ 6-digit zero-padded",
57
+ input: "U+000041",
58
+ expectedOutput: "A",
59
+ recipeConfig: [
60
+ {
61
+ op: "Unescape Unicode Characters",
62
+ args: ["U+"],
63
+ },
64
+ ],
65
+ },
66
+ {
67
+ name: "Unescape Unicode Characters: U+ mixed lengths",
68
+ input: "U+0041 U+1F600 U+000042",
69
+ expectedOutput: "A \u{1F600} B",
70
+ recipeConfig: [
71
+ {
72
+ op: "Unescape Unicode Characters",
73
+ args: ["U+"],
74
+ },
75
+ ],
76
+ },
77
+ {
78
+ name: "Unescape Unicode Characters: passthrough with no matches",
79
+ input: "hello world",
80
+ expectedOutput: "hello world",
81
+ recipeConfig: [
82
+ {
83
+ op: "Unescape Unicode Characters",
84
+ args: ["\\u"],
85
+ },
86
+ ],
87
+ },
88
+ ]);
@@ -40,5 +40,49 @@ TestRegister.addTests([
40
40
  "args": [10]
41
41
  },
42
42
  ],
43
+ },
44
+ {
45
+ name: "Wrap rejects zero line width",
46
+ input: "hello",
47
+ expectedOutput: "Line Width must be greater than or equal to 1.",
48
+ recipeConfig: [
49
+ {
50
+ "op": "Wrap",
51
+ "args": [0]
52
+ },
53
+ ],
54
+ },
55
+ {
56
+ name: "Wrap rejects negative line width",
57
+ input: "hello",
58
+ expectedOutput: "Line Width must be greater than or equal to 1.",
59
+ recipeConfig: [
60
+ {
61
+ "op": "Wrap",
62
+ "args": [-1]
63
+ },
64
+ ],
65
+ },
66
+ {
67
+ name: "Wrap rejects non-integer line width",
68
+ input: "hello",
69
+ expectedOutput: "Line Width must be an integer.",
70
+ recipeConfig: [
71
+ {
72
+ "op": "Wrap",
73
+ "args": [1.1]
74
+ },
75
+ ],
76
+ },
77
+ {
78
+ name: "Wrap rejects excessive line width",
79
+ input: "hello",
80
+ expectedOutput: "Line Width must be less than or equal to 65536.",
81
+ recipeConfig: [
82
+ {
83
+ "op": "Wrap",
84
+ "args": [65537]
85
+ },
86
+ ],
43
87
  }
44
88
  ]);
package/webpack.config.js CHANGED
@@ -88,8 +88,8 @@ module.exports = {
88
88
  from: "tesseract/**/*",
89
89
  to: "assets/"
90
90
  }, {
91
- context: "node_modules/tesseract.js/",
92
- from: "dist/worker.min.js",
91
+ context: "node_modules/tesseract.js/dist",
92
+ from: "worker.min.js",
93
93
  to: "assets/tesseract"
94
94
  }, {
95
95
  context: "node_modules/tesseract.js-core/",
@@ -221,7 +221,7 @@ module.exports = {
221
221
  },
222
222
  { // Third party images are inlined
223
223
  test: /\.(png|jpg|gif)$/,
224
- exclude: /web\/static/,
224
+ include: /node_modules/,
225
225
  type: "asset/inline",
226
226
  },
227
227
  ]