Merge branch 'master' into argselector-validation-2641

This commit is contained in:
GCHQDeveloper581 2026-07-24 16:47:59 +01:00 committed by GitHub
commit b7c12475ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
57 changed files with 8823 additions and 3132 deletions

View File

@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Close stale unsigned-CLA PRs
uses: actions/stale@eb5cf3af3ac0a1aa4c9c45633dd1ae542a27a899 #v10.3.0
uses: actions/stale@1e223db275d687790206a7acac4d1a11bd6fe629 #v10.4.0
with:
# ---- Guards: only act on PRs carrying the CLA label ----
only-labels: 'awaiting cla'

View File

@ -16,10 +16,10 @@ jobs:
pages: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set node version
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 24
registry-url: "https://registry.npmjs.org"

View File

@ -12,10 +12,10 @@ jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set node version
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 24
registry-url: "https://registry.npmjs.org"
@ -61,14 +61,14 @@ jobs:
- name: Set up Docker Buildx
if: success()
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0
- name: Set up QEMU
uses: docker/setup-qemu-action@06116385d9baf250c9f4dcb4858b16962ea869c3 # v4.1.0
uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8 # v4.2.0
- name: Production Image Build
if: success()
id: build-image
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7

View File

@ -22,10 +22,10 @@ jobs:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set node version
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 24
registry-url: "https://registry.npmjs.org"
@ -61,14 +61,14 @@ jobs:
xvfb-run --server-args="-screen 0 1200x800x24" npx grunt testui
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0
- name: Set up QEMU
uses: docker/setup-qemu-action@06116385d9baf250c9f4dcb4858b16962ea869c3 # v4.1.0
uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8 # v4.2.0
- name: Image Metadata
id: image-metadata
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6.1.0
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
@ -77,14 +77,14 @@ jobs:
type=semver,pattern={{version}}
- name: Log in to GHCR
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
uses: docker/login-action@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4.4.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
- name: Publish to GHCR
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
with:
context: .
push: true
@ -110,10 +110,10 @@ jobs:
needs: main
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set node version
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 24
registry-url: "https://registry.npmjs.org"

1
.gitignore vendored
View File

@ -8,6 +8,7 @@ build
src/core/config/modules/*
src/core/config/OperationConfig.json
src/core/operations/index.mjs
src/core/lib/HTMLEntities.mjs
src/node/config/OperationConfig.json
src/node/index.mjs
tests/operations/index.mjs

View File

@ -13,6 +13,75 @@ All major and minor version changes will be documented in this file. Details of
## Details
### [11.3.0] - 2026-07-24
This release includes a security fix ([#2687])
- Security: Fix pretty recipe parser ReDoS [@zainnadeem786] | [#2687]
- feat: add modulo operation [@thomasnemer] [@GCHQDeveloper581] | [#2103]
- Add HMAC regression tests for Decimal key parsing [@alleria173] | [#2680]
- fix: await Node API operations whose run() returns a non-async Promise [@roberson-io] | [#2659]
- chore (deps): bump morgan from 1.10.1 to 1.11.0 | [#2676]
- fix: fromDecimal Auto delimiter now correctly parses multiple numbers [@min23asdw] | [#2270]
- Add Generate Prime Number operation [@p-leriche] | [#2212]
- Add Modular Inverse operation [@p-leriche] | [#2207]
- Consolidate HTML entity tables into a single spec-generated source (#2645) [@roberson-io] | [#2671]
- Add Extended GCD operation [@p-leriche] | [#2206]
- Add COBS encoding/decoding operations [@giesmininkas] | [#2185]
- chore (deps): bump websocket-driver from 0.7.4 to 0.7.5 | [#2673]
- fix: remove stray punctuation from malformed To HTML Entity table values [@roberson-io] | [#2660]
- chore (deps): bump the actions-dependencies group across 1 directory with 6 updates | [#2668]
- chore (deps): bump the minor-updates group across 1 directory with 3 updates | [#2669]
- chore (deps): bump the patch-updates group with 5 updates | [#2654]
- feat: add TEA and XTEA block ciphers [@thomasxm] | [#2225]
- feat: add PRESENT and Twofish ciphers [@thomasxm] | [#2157]
- fix: support constructor and __proto__ parameters in Parse URI (#2578) [@mansiverma897993] | [#2581]
- feat: Implement automated option-type ingredient validation [@mansiverma897993] | [#2625]
- Add Ascon (NIST SP 800-232) operations: Hash, MAC, Encrypt, Decrypt [@thomasxm] | [#2155]
- chore (deps): bump the patch-updates group across 1 directory with 6 updates | [#2638]
- chore (deps): bump webpack from 5.107.2 to 5.108.3 in the minor-updates group | [#2635]
- chore (deps): bump nginxinc/nginx-unprivileged from `458ecbe` to `fd3314e` in the docker-dependencies group | [#2633]
- Feature: automatically expire PRs if CLA remains unsigned for an extended period [@GCHQDeveloper581] | [#2636]
- fix/2445 HOTP (and 2426 TOTP) type errors [@alleria173] | [#2620]
- Fix base32 unicode alphabet [@loki1205] | [#2380]
- Add a workflow to automatically flag PRs without a signed CLA [@GCHQDeveloper581] | [#2627]
- fix/2444 TOTP input validation for correct otpauth uri generation [@alleria173] | [#2621]
- Validate Wrap line width [@vetrovk] [@GCHQDeveloper581] [@C85297] | [#2606]
- Handle malformed image parser errors in View Bit Plane [@zainnadeem786] | [#2612]
- Fixes #2446 hotp otpauth uri validation [@alleria173] | [#2614]
- Handle invalid bcrypt salt errors in Bcrypt compare [@zainnadeem786] | [#2615]
- Validate empty Show On Map options [@vetrovk] | [#2631]
- Create AGENTS.md file [@C85297] | [#2619]
- Set parameter validation Metadata for GenerateImage operations [@GCHQDeveloper581] | [#2611]
- Update 4 vulnerable dependencies [@GCHQDeveloper581] | [#2616]
- Fix BigNumber deserialisation in Dish, and add tests [@GCHQDeveloper581] | [#2607]
- chore (deps): bump the docker-dependencies group with 2 updates | [#2600]
- chore (deps): bump the patch-updates group with 8 updates | [#2602]
- chore (deps): bump actions/checkout from 6.0.3 to 7.0.0 in the actions-dependencies group | [#2601]
- chore (deps): bump the minor-updates group with 2 updates | [#2603]
- Handle empty Generate Image mode [@vetrovk] | [#2598]
- Fix stale presenter after expected operation errors [@zainnadeem786] [@GCHQDeveloper581] | [#2589]
- Clean up/rationalise webpack paths and thereby increase compatibility for Win… [@GCHQDeveloper581] | [#2585]
- Improve parameter validation for a number of operations where exceptions otherwise caused. [@GCHQDeveloper581] | [#2586]
- Fix uncaught TypeError in "Show on map" operation. [@lzandman] | [#2453]
- fix: jsonata $base64decode/$base64encode in Web Worker [@min23asdw] | [#2275]
- fix Dechunk HTTP Response leaks terminating chunk and trailers into output [@williballenthin] | [#2290]
- fix: MIME Decoding corrupts non-ASCII characters in Base64-encoded words [@williballenthin] | [#2291]
- fix: Gzip comment with header checksum produces corrupt streams [@williballenthin] | [#2288]
- fix TLV Parser BER long-form length parsing [@williballenthin] | [#2289]
- fix: Unescape Unicode Characters accepts 4-6 hex digits for U+ prefix [@williballenthin] | [#2287]
- fix Set Difference and Set Intersection preserve duplicates from first sample [@williballenthin] | [#2286]
- fix: From Base operation produces wrong results for fractional inputs [@williballenthin] | [#2285]
- fix Median operation returns incorrect result for unsorted odd-length inputs [@williballenthin] | [#2284]
- Added RenderPDF functionality [@Shailendra1703] [@GCHQDeveloper581] | [#2105]
- Fix URL encoding incorrectly converting input to UTF-8 [@C85297] | [#2340]
- feat: Add automated parameter validation framework [@mansiverma897993] | [#2561]
- Fix: added viewport styles to img tag in RenderImage Dish [@Shailendra1703] [@C85297] | [#2109]
- chore (deps): bump form-data from 4.0.5 to 4.0.6 | [#2572]
- chore (deps): bump the patch-updates group with 5 updates [@GCHQDeveloper581] | [#2580]
- chore (deps): bump the docker-dependencies group with 2 updates | [#2579]
- Fix operation description rendering [@C85297] | [#2577]
- chore (deps): bump launch-editor from 2.13.1 to 2.14.1 | [#2574]
- chore (deps): bump dompurify from 3.4.8 to 3.4.9 | [#2573]
### [11.2.0] - 2026-06-17
This release includes a security fix ([#2569])
- Security: Chart operation prototype protection [@C85297] | [#2569]
@ -718,6 +787,7 @@ Breaking changes:
## [4.0.0] - 2016-11-28
- Initial open source commit [@n1474335] | [b1d73a72](https://github.com/gchq/CyberChef/commit/b1d73a725dc7ab9fb7eb789296efd2b7e4b08306)
[11.3.0]: https://github.com/gchq/CyberChef/releases/tag/v11.3.0
[11.2.0]: https://github.com/gchq/CyberChef/releases/tag/v11.2.0
[11.1.0]: https://github.com/gchq/CyberChef/releases/tag/v11.1.0
[11.0.0]: https://github.com/gchq/CyberChef/releases/tag/v11.0.0
@ -1018,6 +1088,17 @@ Breaking changes:
[@qa2me]: https://github.com/qa2me
[@heapframe]: https://github.com/heapframe
[@skyswordw]: https://github.com/skyswordw
[@thomasnemer]: https://github.com/thomasnemer
[@alleria173]: https://github.com/alleria173
[@roberson-io]: https://github.com/roberson-io
[@min23asdw]: https://github.com/min23asdw
[@giesmininkas]: https://github.com/giesmininkas
[@mansiverma897993]: https://github.com/mansiverma897993
[@loki1205]: https://github.com/loki1205
[@vetrovk]: https://github.com/vetrovk
[@zainnadeem786]: https://github.com/zainnadeem786
[@williballenthin]: https://github.com/williballenthin
[@Shailendra1703]: https://github.com/Shailendra1703
[8ad18b]: https://github.com/gchq/CyberChef/commit/8ad18bc7db6d9ff184ba3518686293a7685bf7b7
@ -1389,4 +1470,69 @@ Breaking changes:
[#2404]: https://github.com/gchq/CyberChef/pull/2404
[#2458]: https://github.com/gchq/CyberChef/pull/2458
[#2514]: https://github.com/gchq/CyberChef/pull/2514
[#2687]: https://github.com/gchq/CyberChef/pull/2687
[#2103]: https://github.com/gchq/CyberChef/pull/2103
[#2680]: https://github.com/gchq/CyberChef/pull/2680
[#2659]: https://github.com/gchq/CyberChef/pull/2659
[#2676]: https://github.com/gchq/CyberChef/pull/2676
[#2270]: https://github.com/gchq/CyberChef/pull/2270
[#2212]: https://github.com/gchq/CyberChef/pull/2212
[#2207]: https://github.com/gchq/CyberChef/pull/2207
[#2671]: https://github.com/gchq/CyberChef/pull/2671
[#2206]: https://github.com/gchq/CyberChef/pull/2206
[#2185]: https://github.com/gchq/CyberChef/pull/2185
[#2673]: https://github.com/gchq/CyberChef/pull/2673
[#2660]: https://github.com/gchq/CyberChef/pull/2660
[#2668]: https://github.com/gchq/CyberChef/pull/2668
[#2669]: https://github.com/gchq/CyberChef/pull/2669
[#2654]: https://github.com/gchq/CyberChef/pull/2654
[#2225]: https://github.com/gchq/CyberChef/pull/2225
[#2157]: https://github.com/gchq/CyberChef/pull/2157
[#2581]: https://github.com/gchq/CyberChef/pull/2581
[#2625]: https://github.com/gchq/CyberChef/pull/2625
[#2155]: https://github.com/gchq/CyberChef/pull/2155
[#2638]: https://github.com/gchq/CyberChef/pull/2638
[#2635]: https://github.com/gchq/CyberChef/pull/2635
[#2633]: https://github.com/gchq/CyberChef/pull/2633
[#2636]: https://github.com/gchq/CyberChef/pull/2636
[#2620]: https://github.com/gchq/CyberChef/pull/2620
[#2380]: https://github.com/gchq/CyberChef/pull/2380
[#2627]: https://github.com/gchq/CyberChef/pull/2627
[#2621]: https://github.com/gchq/CyberChef/pull/2621
[#2606]: https://github.com/gchq/CyberChef/pull/2606
[#2612]: https://github.com/gchq/CyberChef/pull/2612
[#2614]: https://github.com/gchq/CyberChef/pull/2614
[#2615]: https://github.com/gchq/CyberChef/pull/2615
[#2631]: https://github.com/gchq/CyberChef/pull/2631
[#2619]: https://github.com/gchq/CyberChef/pull/2619
[#2611]: https://github.com/gchq/CyberChef/pull/2611
[#2616]: https://github.com/gchq/CyberChef/pull/2616
[#2607]: https://github.com/gchq/CyberChef/pull/2607
[#2600]: https://github.com/gchq/CyberChef/pull/2600
[#2602]: https://github.com/gchq/CyberChef/pull/2602
[#2601]: https://github.com/gchq/CyberChef/pull/2601
[#2603]: https://github.com/gchq/CyberChef/pull/2603
[#2598]: https://github.com/gchq/CyberChef/pull/2598
[#2589]: https://github.com/gchq/CyberChef/pull/2589
[#2585]: https://github.com/gchq/CyberChef/pull/2585
[#2586]: https://github.com/gchq/CyberChef/pull/2586
[#2453]: https://github.com/gchq/CyberChef/pull/2453
[#2275]: https://github.com/gchq/CyberChef/pull/2275
[#2290]: https://github.com/gchq/CyberChef/pull/2290
[#2291]: https://github.com/gchq/CyberChef/pull/2291
[#2288]: https://github.com/gchq/CyberChef/pull/2288
[#2289]: https://github.com/gchq/CyberChef/pull/2289
[#2287]: https://github.com/gchq/CyberChef/pull/2287
[#2286]: https://github.com/gchq/CyberChef/pull/2286
[#2285]: https://github.com/gchq/CyberChef/pull/2285
[#2284]: https://github.com/gchq/CyberChef/pull/2284
[#2105]: https://github.com/gchq/CyberChef/pull/2105
[#2340]: https://github.com/gchq/CyberChef/pull/2340
[#2561]: https://github.com/gchq/CyberChef/pull/2561
[#2109]: https://github.com/gchq/CyberChef/pull/2109
[#2572]: https://github.com/gchq/CyberChef/pull/2572
[#2580]: https://github.com/gchq/CyberChef/pull/2580
[#2579]: https://github.com/gchq/CyberChef/pull/2579
[#2577]: https://github.com/gchq/CyberChef/pull/2577
[#2574]: https://github.com/gchq/CyberChef/pull/2574
[#2573]: https://github.com/gchq/CyberChef/pull/2573

View File

@ -27,7 +27,7 @@ RUN npm run build
#########################################
# Package static build files into nginx #
#########################################
FROM nginxinc/nginx-unprivileged:stable-alpine@sha256:fd3314e343bad2de4e1127ef58be122abbfa7e09572fa46ae62fcddb6b3f21c5 AS cyberchef
FROM nginxinc/nginx-unprivileged:stable-alpine@sha256:44e36330f74d4f3a1d4e222acca9e23b401fb87811a7597024502bb759c4dd49 AS cyberchef
LABEL maintainer="GCHQ <oss@gchq.gov.uk>"

View File

@ -367,6 +367,7 @@ module.exports = function (grunt) {
command: chainCommands([
"echo '\n--- Regenerating config files. ---'",
"echo [] > src/core/config/OperationConfig.json",
`node ${nodeFlags} src/core/config/scripts/generateHTMLEntities.mjs`,
`node ${nodeFlags} src/core/config/scripts/generateOpsIndex.mjs`,
`node ${nodeFlags} src/core/config/scripts/generateConfig.mjs`,
"echo '--- Config scripts finished. ---\n'"

459
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "cyberchef",
"version": "11.2.0",
"version": "11.3.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "cyberchef",
"version": "11.2.0",
"version": "11.3.0",
"hasInstallScript": true,
"license": "Apache-2.0",
"dependencies": {
@ -21,7 +21,7 @@
"assert": "^2.1.0",
"avsc": "^5.7.9",
"bcryptjs": "^3.0.3",
"bignumber.js": "^11.1.4",
"bignumber.js": "^11.1.5",
"blakejs": "^1.2.1",
"bootstrap": "4.6.2",
"bootstrap-colorpicker": "^3.4.0",
@ -39,7 +39,7 @@
"d3": "7.9.0",
"d3-hexbin": "^0.2.2",
"diff": "^9.0.0",
"dompurify": "^3.4.11",
"dompurify": "^3.4.12",
"es6-promisify": "^7.0.0",
"escodegen": "^2.1.0",
"esprima": "^4.0.1",
@ -59,7 +59,7 @@
"js-sha3": "^0.9.3",
"jsesc": "^3.1.0",
"json5": "^2.2.3",
"jsonata": "^2.2.1",
"jsonata": "^2.2.2",
"jsonpath-plus": "^10.4.0",
"jsonwebtoken": "9.0.3",
"jsqr": "^1.4.0",
@ -72,9 +72,9 @@
"loglevel-message-prefix": "^3.0.0",
"lz-string": "^1.5.0",
"lz4js": "^0.2.0",
"markdown-it": "^14.2.0",
"markdown-it": "^14.3.0",
"moment": "^2.30.1",
"moment-timezone": "^0.6.2",
"moment-timezone": "^0.6.3",
"ngeohash": "^0.6.3",
"node-forge": "^1.4.0",
"node-md6": "^0.1.0",
@ -86,7 +86,7 @@
"path": "^0.12.7",
"popper.js": "^1.16.1",
"process": "^0.11.10",
"protobufjs": "^8.6.5",
"protobufjs": "^8.7.1",
"punycode.js": "^2.3.1",
"qr-image": "^3.2.0",
"reflect-metadata": "^0.2.2",
@ -118,13 +118,13 @@
"@codemirror/commands": "^6.10.4",
"@codemirror/language": "^6.12.4",
"@codemirror/search": "^6.7.1",
"@codemirror/state": "^6.5.4",
"@codemirror/view": "^6.43.4",
"@codemirror/state": "^6.7.1",
"@codemirror/view": "^6.43.6",
"@puppeteer/browsers": "3.0.6",
"autoprefixer": "^10.5.2",
"autoprefixer": "^10.5.4",
"babel-loader": "^10.1.1",
"base64-loader": "^1.0.0",
"chromedriver": "^148.0.4",
"chromedriver": "^150.0.4",
"cli-progress": "^3.12.0",
"colors": "^1.4.0",
"compression-webpack-plugin": "^12.0.0",
@ -132,7 +132,7 @@
"core-js": "^3.49.0",
"cspell": "^10.0.1",
"css-loader": "^7.1.4",
"eslint": "^9.39.4",
"eslint": "^9.39.5",
"eslint-plugin-jsdoc": "^50.8.0",
"globals": "^17.7.0",
"grunt": "^1.6.2",
@ -151,16 +151,16 @@
"mini-css-extract-plugin": "2.10.2",
"modify-source-webpack-plugin": "^4.1.0",
"nightwatch": "^3.16.0",
"postcss": "^8.5.16",
"postcss": "^8.5.21",
"postcss-css-variables": "^0.19.0",
"postcss-import": "^16.1.1",
"postcss-loader": "^8.2.1",
"prompt": "^1.3.0",
"sitemap": "^9.0.1",
"terser": "^5.48.0",
"webpack": "^5.108.3",
"webpack-bundle-analyzer": "^5.3.0",
"webpack-dev-server": "^5.2.5",
"terser": "^5.49.0",
"webpack": "^5.108.4",
"webpack-bundle-analyzer": "^5.3.1",
"webpack-dev-server": "^5.2.6",
"webpack-node-externals": "^3.0.0",
"worker-loader": "^3.0.8"
},
@ -1889,9 +1889,9 @@
}
},
"node_modules/@codemirror/state": {
"version": "6.7.0",
"resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.7.0.tgz",
"integrity": "sha512-Zbl9NyscLMZkfXPQnNAIIAFftidrA1UbcJEIMp24C0Bukc2I5T8wJS0wsXYsnDOqCFJUeJ1BITGNs5CqPDSmSg==",
"version": "6.7.1",
"resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.7.1.tgz",
"integrity": "sha512-9QzNDgE4EYDnAHfrTlR2lwiPciiOymLtwKK+8yHQzCc7GXhAP9xdEbEJFy2IWB1j9UGUl9BsgMmTo/ImA02T7A==",
"dev": true,
"license": "MIT",
"dependencies": {
@ -1899,9 +1899,9 @@
}
},
"node_modules/@codemirror/view": {
"version": "6.43.4",
"resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.43.4.tgz",
"integrity": "sha512-YImu23iyKfncJzT7sRy+rEqEhSc8RhOHqDxwy4WzXRKJwYm6iwf/9OJk5ctCAdZ6yi2ZqaGEvmf55fSVqMDrgg==",
"version": "6.43.6",
"resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.43.6.tgz",
"integrity": "sha512-EVunGSYN1wz1p75WY1s3Xg7t3i8Yol0kGZGizNdX9BUFgMFILYVe8/u6EVpo7Ff5PwbZuILb4QAq7IZoKzIEQA==",
"dev": true,
"license": "MIT",
"dependencies": {
@ -2776,9 +2776,9 @@
}
},
"node_modules/@eslint/eslintrc": {
"version": "3.3.5",
"resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.3.5.tgz",
"integrity": "sha512-4IlJx0X0qftVsN5E+/vGujTRIFtwuLbNsVUe7TO6zYPDR1O6nFwvwhIKEKSrl6dZchmYBITazxKoUYOjdtjlRg==",
"version": "3.3.6",
"resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.3.6.tgz",
"integrity": "sha512-l2Ul9PrHsPCKcEY/ac7VgFj9D80C7S68sOKc618SyHDPK36s1XcFebXY0iTzUVn4Yq+YbwvSnDmCz9yxjX+QrA==",
"dev": true,
"license": "MIT",
"dependencies": {
@ -2788,7 +2788,7 @@
"globals": "^14.0.0",
"ignore": "^5.2.0",
"import-fresh": "^3.2.1",
"js-yaml": "^4.1.1",
"js-yaml": "^4.3.0",
"minimatch": "^3.1.5",
"strip-json-comments": "^3.1.1"
},
@ -2813,9 +2813,9 @@
}
},
"node_modules/@eslint/js": {
"version": "9.39.4",
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.39.4.tgz",
"integrity": "sha512-nE7DEIchvtiFTwBw4Lfbu59PG+kCofhjsKaCWzxTpt4lfRjRMqG6uMBzKXuEcyXhOHoUp9riAm7/aWYGhXZ9cw==",
"version": "9.39.5",
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.39.5.tgz",
"integrity": "sha512-QywQuszQh77pIXCsq998c8hbhSTI/azTty1Z6N53dmAudKHhy573j3yvRLsX2BSp8YpLtoCEG8E9DJe+8zUh4A==",
"dev": true,
"license": "MIT",
"engines": {
@ -5129,9 +5129,9 @@
}
},
"node_modules/adm-zip": {
"version": "0.5.17",
"resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.17.tgz",
"integrity": "sha512-+Ut8d9LLqwEvHHJl1+PIHqoyDxFgVN847JTVM3Izi3xHDWPE4UtzzXysMZQs64DMcrJfBeS/uoEP4AD3HQHnQQ==",
"version": "0.5.18",
"resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.18.tgz",
"integrity": "sha512-ufJnssQGbxzLNS1Ho9bCtX4rQKCCvoVuDLHoJyc3F9dOGDB4BkWs2Ci0kv53lqocAEQ/Cbi+I2XCsNYGqVYqng==",
"dev": true,
"license": "MIT",
"engines": {
@ -5620,9 +5620,9 @@
"license": "MIT"
},
"node_modules/autoprefixer": {
"version": "10.5.2",
"resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.5.2.tgz",
"integrity": "sha512-rD5t5DwOjJdmSORcTq64j8MawTC+tbQ+HHqjR4NDumamy/ambn1UJrlKL+KdwujWxMkFjPM3pPHOEA9tl4767Q==",
"version": "10.5.4",
"resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.5.4.tgz",
"integrity": "sha512-MaU0U/za7N3r6brxD4YB/l4NSrFzLPlANv6wEuQVaIPlD3L4W9rFcQPbL/EilY9BHhHvhfcz3gInDLrEtWT4EA==",
"dev": true,
"funding": [
{
@ -5640,8 +5640,8 @@
],
"license": "MIT",
"dependencies": {
"browserslist": "^4.28.4",
"caniuse-lite": "^1.0.30001799",
"browserslist": "^4.28.6",
"caniuse-lite": "^1.0.30001806",
"fraction.js": "^5.3.4",
"picocolors": "^1.1.1",
"postcss-value-parser": "^4.2.0"
@ -5700,17 +5700,45 @@
}
},
"node_modules/axios": {
"version": "1.16.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.16.0.tgz",
"integrity": "sha512-6hp5CwvTPlN2A31g5dxnwAX0orzM7pmCRDLnZSX772mv8WDqICwFjowHuPs04Mc8deIld1+ejhtaMn5vp6b+1w==",
"version": "1.18.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.18.1.tgz",
"integrity": "sha512-3nTvFlvpn9Zu/RkHUqtc7/+al4UpRW5az71ap5zccp6e8RAYEzhMTecX8Dz1wWDYrPpUoB1HAQEGEAEvUr7S9g==",
"dev": true,
"license": "MIT",
"dependencies": {
"follow-redirects": "^1.16.0",
"form-data": "^4.0.5",
"https-proxy-agent": "^5.0.1",
"proxy-from-env": "^2.1.0"
}
},
"node_modules/axios/node_modules/agent-base": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz",
"integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"debug": "4"
},
"engines": {
"node": ">= 6.0.0"
}
},
"node_modules/axios/node_modules/https-proxy-agent": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz",
"integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==",
"dev": true,
"license": "MIT",
"dependencies": {
"agent-base": "6",
"debug": "4"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/babel-loader": {
"version": "10.1.1",
"resolved": "https://registry.npmjs.org/babel-loader/-/babel-loader-10.1.1.tgz",
@ -5814,9 +5842,9 @@
"license": "MIT"
},
"node_modules/baseline-browser-mapping": {
"version": "2.10.40",
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.10.40.tgz",
"integrity": "sha512-BSSLZ9/Cjjv7Gtj5B68ZzXcXUg8iOf3fme+FCuh8rC/Go+Kmh8cox7M3A8dolou16s64QjLPOSdngh7GxXvkSw==",
"version": "2.11.1",
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.11.1.tgz",
"integrity": "sha512-HYXq73DDpCtNzOmrFsm9eSwCvWCql0RzqjpDzXN9EadiLJ4DNat0nsZ/Bzmy+Ud12mb4/zKDY0cQ805ZzN+i0A==",
"dev": true,
"license": "Apache-2.0",
"bin": {
@ -5883,9 +5911,9 @@
}
},
"node_modules/bignumber.js": {
"version": "11.1.4",
"resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-11.1.4.tgz",
"integrity": "sha512-AJ9dSeaUGj2xu7tEwmdqb51dqdb633xo4njI9K8ZFfcLrNr0XN8/EPkkZUNaF9fkCblGt2zVwZymesUdGynEkQ==",
"version": "11.1.5",
"resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-11.1.5.tgz",
"integrity": "sha512-6WmzCNtUnfKpbozq+hOgWaZMMzORmYBwF1xZScyoIX3QRYWeKTtxxwDOW5tIz7C9BdjkIYHGTcelCLkXg0mndw==",
"license": "MIT"
},
"node_modules/binary-extensions": {
@ -5996,9 +6024,9 @@
}
},
"node_modules/body-parser": {
"version": "1.20.5",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.5.tgz",
"integrity": "sha512-3grm+/2tUOvu2cjJkvsIxrv/wVpfXQW4PsQHYm7yk4vfpu7Ekl6nEsYBoJUL6qDwZUx8wUhQ8tR2qz+ad9c9OA==",
"version": "1.20.6",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.6.tgz",
"integrity": "sha512-p5tAzS57i5MV9fZFDj9LeIiTZEufbSe2eDozP+ElheSUq1m74CRq1jI4mYNDdVs9vQztXFLuk/Gd6BWTdwRJ5g==",
"dev": true,
"license": "MIT",
"dependencies": {
@ -6231,9 +6259,9 @@
}
},
"node_modules/brace-expansion": {
"version": "1.1.13",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.13.tgz",
"integrity": "sha512-9ZLprWS6EENmhEOpjCYW2c8VkmOvckIJZfkr7rBW6dObmfgJ/L1GpSYW5Hpo9lDz4D1+n0Ckz8rU7FwHDQiG/w==",
"version": "1.1.16",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.16.tgz",
"integrity": "sha512-IDw48K2/2kRkg9LdJxurvq3lV3aBgq0REY89duEqFRthjlPdXHKMj7EnQOXVckxzgisinf3nHfrcE2FufFLXMw==",
"dev": true,
"license": "MIT",
"dependencies": {
@ -6348,9 +6376,9 @@
}
},
"node_modules/browserslist": {
"version": "4.28.4",
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.28.4.tgz",
"integrity": "sha512-MTc8i/x9jBQd1iMw2CFGS+rwMa07eYjLR0CCTLDACl9xhxy+nIs3KeML/biicXtk9JrZ6dnnTatmc7ErPXIxqw==",
"version": "4.28.7",
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.28.7.tgz",
"integrity": "sha512-JxV13hNrFxqjOc8alRbq9dK1MM79NEXYpma2B2J4wAtpWS5zIEIKqWPGCl7N4o7Uc7B7itylh7SuDujATRyyTw==",
"dev": true,
"funding": [
{
@ -6368,10 +6396,10 @@
],
"license": "MIT",
"dependencies": {
"baseline-browser-mapping": "^2.10.38",
"caniuse-lite": "^1.0.30001799",
"electron-to-chromium": "^1.5.376",
"node-releases": "^2.0.48",
"baseline-browser-mapping": "^2.10.44",
"caniuse-lite": "^1.0.30001806",
"electron-to-chromium": "^1.5.393",
"node-releases": "^2.0.51",
"update-browserslist-db": "^1.2.3"
},
"bin": {
@ -6563,9 +6591,9 @@
}
},
"node_modules/caniuse-lite": {
"version": "1.0.30001799",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001799.tgz",
"integrity": "sha512-hG1bReV+OUU+MOqK4t/ZWI0tZOyz3rqS9XuhOUz1cIcbwBKjOyJEJuw9ER5JuNyqxNk8u/JUVbGibBOL1yrjFw==",
"version": "1.0.30001806",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001806.tgz",
"integrity": "sha512-72Cuvd95zbSYPKq6Fhg8eDJRlzgWDf7/mtoZv6Qe/DYNCEBdNxoA3+rZAU2ZhGCpZlns3EssFavaZomckT5Uuw==",
"dev": true,
"funding": [
{
@ -6705,20 +6733,20 @@
}
},
"node_modules/chromedriver": {
"version": "148.0.4",
"resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-148.0.4.tgz",
"integrity": "sha512-3UyptFDG4YF1Pyv3fzn95s1CN4K3zCpHSmE6g+6J4f2u9KxxOYzrwN2GApVyM2z02hlbSqzo9Ajn2hMi7LnvCw==",
"version": "150.0.4",
"resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-150.0.4.tgz",
"integrity": "sha512-Yg2oXBONi1mqAMOG2ybwUneSvxIn04NF4qNAJ+yGO2H7WwX1WYLGQRHVHsbySEjIuqIyDmS1ZfAw6p0wtl43zQ==",
"dev": true,
"hasInstallScript": true,
"license": "Apache-2.0",
"dependencies": {
"@testim/chrome-version": "^1.1.4",
"adm-zip": "^0.5.17",
"axios": "^1.16.0",
"compare-versions": "^6.1.0",
"proxy-agent": "^8.0.1",
"proxy-from-env": "^2.0.0",
"tcp-port-used": "^1.0.2"
"adm-zip": "^0.5.18",
"axios": "^1.18.1",
"compare-versions": "^6.1.1",
"proxy-agent": "^8.0.2",
"proxy-from-env": "^2.1.0",
"tcp-port-used": "^1.0.3"
},
"bin": {
"chromedriver": "bin/chromedriver"
@ -8674,9 +8702,9 @@
}
},
"node_modules/dompurify": {
"version": "3.4.11",
"resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.4.11.tgz",
"integrity": "sha512-zhlUV12GsaRzMsf9q5M254YhA4+VuF0fG+QFqu6aYpoGlKtz+w8//jBcGVYBgQkR5GHjUomejY84AV+/uPbWdw==",
"version": "3.4.12",
"resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.4.12.tgz",
"integrity": "sha512-zQvGet8Z2sWbQhCmfFz/T5QWH2oBmjnqK3qvOjaqaNLrLEF912WamU+ohnTp0TCep/MFVHpdJuCZEdFOdTnEFg==",
"license": "(MPL-2.0 OR Apache-2.0)",
"optionalDependencies": {
"@types/trusted-types": "^2.0.7"
@ -8781,9 +8809,9 @@
}
},
"node_modules/electron-to-chromium": {
"version": "1.5.379",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.379.tgz",
"integrity": "sha512-v/qV5aV5EUA2pGilzUCq5/eyOloZAqDZBu9UMBIzgPpLlprjSR6zswsWBTv0KpqxLGUAZEwhO95ZCt7srymNVA==",
"version": "1.5.396",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.396.tgz",
"integrity": "sha512-yHiw2Y3C3H9U6TMbOfoWK/BPreiOPXRfTWPBwQBoZG6/8TB6eOPnsy5oaRYuatR7Fw2SJ4kKforgufeo7fq0EQ==",
"dev": true,
"license": "ISC"
},
@ -9084,9 +9112,9 @@
}
},
"node_modules/eslint": {
"version": "9.39.4",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-9.39.4.tgz",
"integrity": "sha512-XoMjdBOwe/esVgEvLmNsD3IRHkm7fbKIUGvrleloJXUZgDHig2IPWNniv+GwjyJXzuNqVjlr5+4yVUZjycJwfQ==",
"version": "9.39.5",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-9.39.5.tgz",
"integrity": "sha512-DgZS62aPLXKlnxILS/AYCoRvHaZeXceIzlXPkkGGzJWSow1aEk0lbTlxUSlyjC8jcaKxAdOnTDz+o1JFSBsyjw==",
"dev": true,
"license": "MIT",
"dependencies": {
@ -9095,8 +9123,8 @@
"@eslint/config-array": "^0.21.2",
"@eslint/config-helpers": "^0.4.2",
"@eslint/core": "^0.17.0",
"@eslint/eslintrc": "^3.3.5",
"@eslint/js": "9.39.4",
"@eslint/eslintrc": "^3.3.6",
"@eslint/js": "9.39.5",
"@eslint/plugin-kit": "^0.4.1",
"@humanfs/node": "^0.16.6",
"@humanwhocodes/module-importer": "^1.0.1",
@ -9664,9 +9692,9 @@
"license": "MIT"
},
"node_modules/fast-uri": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.2.tgz",
"integrity": "sha512-rVjf7ArG3LTk+FS6Yw81V1DLuZl1bRbNrev6Tmd/9RaroeeRRJhAt7jg/6YFxbvAQXUCavSoZhPPj6oOx+5KjQ==",
"version": "3.1.4",
"resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.4.tgz",
"integrity": "sha512-8JnbkQ4juDyvYs4mgFGQqg4yCYtFDtUtmp2QIQq11ZZe5CFQ5wcqm1rqDgAh/QdMySuBnPzMUiJUNZG5N/AiQw==",
"dev": true,
"funding": [
{
@ -9744,9 +9772,9 @@
}
},
"node_modules/filelist/node_modules/brace-expansion": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.3.tgz",
"integrity": "sha512-MCV/fYJEbqx68aE58kv2cA/kiky1G8vux3OR6/jbS+jIMe/6fJWa0DTzJU7dqijOWYwHi1t29FlfYI9uytqlpA==",
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.2.tgz",
"integrity": "sha512-w5JZcKgdhDOgOwm8H+KgbosopHMuGcl6qbulwjtz3SM7I7P3yW1eAjzMPLrIE+NQ9vjgANKHWeMHnrT0OXW1oA==",
"dev": true,
"license": "MIT",
"dependencies": {
@ -10177,13 +10205,13 @@
}
},
"node_modules/get-uri": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/get-uri/-/get-uri-8.0.0.tgz",
"integrity": "sha512-CqtZlMKvfJeY0Zxv8wazDwXmSKmnMnsmNy8j8+wudi8EyG/pMUB1NqHc+Tv1QaNtpYsK9nOYjb7r7Ufu32RPSw==",
"version": "8.0.1",
"resolved": "https://registry.npmjs.org/get-uri/-/get-uri-8.0.1.tgz",
"integrity": "sha512-/5N/P4Lrh0p/mDwlDRi7Y1+P2o/OyzZI3l6Iz1Ov6XXwwm1y3RlZLuo3gVgML99djrEDtV980bBxSuOeHLk8ww==",
"dev": true,
"license": "MIT",
"dependencies": {
"basic-ftp": "^5.2.0",
"basic-ftp": "^5.3.1",
"data-uri-to-buffer": "8.0.0",
"debug": "^4.3.4"
},
@ -11589,13 +11617,13 @@
}
},
"node_modules/ip-regex": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-4.3.0.tgz",
"integrity": "sha512-B9ZWJxHHOHUhUjCPrMpLD4xEq35bUTClHM1S6CBU5ixQnkZmwipwgc96vAd7AAGM9TGHvJR+Uss+/Ak6UphK+Q==",
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-2.1.0.tgz",
"integrity": "sha512-58yWmlHpp7VYfcdTwMTvwMmqx/Elfxjd9RXTDyMsbL7lLWmhMylLEqiYVLKuLzOZqVgiWXD9MfR62Vv89VRxkw==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
"node": ">=4"
}
},
"node_modules/ipaddr.js": {
@ -12207,15 +12235,15 @@
}
},
"node_modules/is2": {
"version": "2.0.9",
"resolved": "https://registry.npmjs.org/is2/-/is2-2.0.9.tgz",
"integrity": "sha512-rZkHeBn9Zzq52sd9IUIV3a5mfwBY+o2HePMh0wkGBM4z4qjvy2GwVxQ6nNXSfw6MmVP6gf1QIlWjiOavhM3x5g==",
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/is2/-/is2-2.0.1.tgz",
"integrity": "sha512-+WaJvnaA7aJySz2q/8sLjMb2Mw14KTplHmSwcSpZ/fWJPkUmqw3YTzSWbPJ7OAwRvdYTWF2Wg+yYJ1AdP5Z8CA==",
"dev": true,
"license": "MIT",
"dependencies": {
"deep-is": "^0.1.3",
"ip-regex": "^4.1.0",
"is-url": "^1.2.4"
"ip-regex": "^2.1.0",
"is-url": "^1.2.2"
},
"engines": {
"node": ">=v0.10.0"
@ -12507,9 +12535,9 @@
}
},
"node_modules/jsonata": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/jsonata/-/jsonata-2.2.1.tgz",
"integrity": "sha512-xd1uwUrKeIcJbsWhaoS3qAX4Ea8m0Mw0G5nlnAQvPT7TbZ5qaPdzBVTQia9KfyuyQm+nenfyjvzUDTRYHsC2sw==",
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/jsonata/-/jsonata-2.2.2.tgz",
"integrity": "sha512-XDFH2PuaAXv0AXJEWwElXbqADmKFGKMLMkFb+qOz0EhjQW2EIJ6pgtordLU+4u3IVERyBfqy6bi6kZKEncvRqA==",
"license": "MIT",
"engines": {
"node": ">= 8"
@ -12777,9 +12805,9 @@
"license": "MIT"
},
"node_modules/linkify-it": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.1.tgz",
"integrity": "sha512-wVoTjP4Q6R0NW5hiZkVJaFZPWgtXfoGF+6LucL3/FtiNjmcHhYjEr5f1Kqjirc1nBW07J/ZuRFumqr2oqccEWg==",
"version": "5.0.2",
"resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.2.tgz",
"integrity": "sha512-ONTm2jCMAVZjgQa/Fy1kScXsuOoF5NPTsoFBdE1KVIZ2vAh/r9+Bqo+0jINCBYnavTPQZz38QzFTme79ENoN3Q==",
"funding": [
{
"type": "github",
@ -13106,9 +13134,9 @@
}
},
"node_modules/markdown-it": {
"version": "14.2.0",
"resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.2.0.tgz",
"integrity": "sha512-1TGiQiJVRQ3NPmZH6sx5Cfnmg6GQm9jvC1ch4TK511NjSJvjzKLzn5pPfZRNZkRPZP0HqCioSndqH8v2nRaWVQ==",
"version": "14.3.0",
"resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.3.0.tgz",
"integrity": "sha512-RCEsPjR+sr0x+AuYp601tKTkgFG4YEPLCzHST3cQ/fhlJkqAkz1L2/Qbp1j9qw5SBwQHFBoW8+hoN5xssOF0Tw==",
"funding": [
{
"type": "github",
@ -13122,8 +13150,8 @@
"license": "MIT",
"dependencies": {
"argparse": "^2.0.1",
"entities": "^4.4.0",
"linkify-it": "^5.0.1",
"entities": "^4.5.0",
"linkify-it": "^5.0.2",
"mdurl": "^2.0.0",
"punycode.js": "^2.3.1",
"uc.micro": "^2.1.0"
@ -13469,9 +13497,9 @@
}
},
"node_modules/mocha/node_modules/brace-expansion": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.3.tgz",
"integrity": "sha512-MCV/fYJEbqx68aE58kv2cA/kiky1G8vux3OR6/jbS+jIMe/6fJWa0DTzJU7dqijOWYwHi1t29FlfYI9uytqlpA==",
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.2.tgz",
"integrity": "sha512-w5JZcKgdhDOgOwm8H+KgbosopHMuGcl6qbulwjtz3SM7I7P3yW1eAjzMPLrIE+NQ9vjgANKHWeMHnrT0OXW1oA==",
"dev": true,
"license": "MIT",
"dependencies": {
@ -13556,9 +13584,9 @@
}
},
"node_modules/moment-timezone": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.6.2.tgz",
"integrity": "sha512-lDsQv8FoGdBUdf0+TjGsq2orxKuXdwFlQ6Zw6TX3xIcTwTfEpCLyKqvEauvCHJ8iu3KBV8+uPhlv70YsNGdUBQ==",
"version": "0.6.3",
"resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.6.3.tgz",
"integrity": "sha512-pVEPA/HCFHHbwJ130ywnzYuZpkEGcP6Daa/OwNebpA18MybeFHmQilAGGovXgWijQ8vQtmud9jZrziUBgsykfg==",
"license": "MIT",
"dependencies": {
"moment": "^2.29.4"
@ -13582,20 +13610,24 @@
}
},
"node_modules/morgan": {
"version": "1.10.1",
"resolved": "https://registry.npmjs.org/morgan/-/morgan-1.10.1.tgz",
"integrity": "sha512-223dMRJtI/l25dJKWpgij2cMtywuG/WiUKXdvwfbhGKBhy1puASqXwFzmWZ7+K73vUPoR7SS2Qz2cI/g9MKw0A==",
"version": "1.11.0",
"resolved": "https://registry.npmjs.org/morgan/-/morgan-1.11.0.tgz",
"integrity": "sha512-zSkVu3t18r39pw4ixfBKvfZi3y2UOqr7d4WYwcj3m8nXpEQK4rPO6GLzs/CExoRgmX3y9EjmmcXqv6jq0SK46g==",
"dev": true,
"license": "MIT",
"dependencies": {
"basic-auth": "~2.0.1",
"debug": "2.6.9",
"depd": "~2.0.0",
"on-finished": "~2.3.0",
"on-finished": "~2.4.1",
"on-headers": "~1.1.0"
},
"engines": {
"node": ">= 0.8.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/morgan/node_modules/debug": {
@ -13615,6 +13647,19 @@
"dev": true,
"license": "MIT"
},
"node_modules/morgan/node_modules/on-finished": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
"integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
"dev": true,
"license": "MIT",
"dependencies": {
"ee-first": "1.1.1"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/mrmime": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/mrmime/-/mrmime-2.0.1.tgz",
@ -13653,9 +13698,9 @@
"license": "ISC"
},
"node_modules/nanoid": {
"version": "3.3.12",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.12.tgz",
"integrity": "sha512-ZB9RH/39qpq5Vu6Y+NmUaFhQR6pp+M2Xt76XBnEwDaGcVAqhlvxrl3B2bKS5D3NH3QR76v3aSrKaF/Kiy7lEtQ==",
"version": "3.3.16",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.16.tgz",
"integrity": "sha512-bzlKTyNJ7+LdGIIwy8ijFpIqEQIvafahV7eYykJ8Cvh42EdJeODoJ6gUJXpQJvej1BddH8OqTXZNE/KfbWAu8Q==",
"dev": true,
"funding": [
{
@ -13988,9 +14033,9 @@
"license": "CC0-1.0"
},
"node_modules/node-releases": {
"version": "2.0.50",
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.50.tgz",
"integrity": "sha512-J6l92tKHX6w8Jy5nO1Vuc01NoIiRGi/d6qBKVxh+IQ8Cr3b6HbVNfKiF8ZpFKufTwpwxMmce2W3iQZ861ZRyTg==",
"version": "2.0.51",
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.51.tgz",
"integrity": "sha512-wRNIrw4DmVLKQlbgOMdkMx27Wrpzes2hh5Jtbi2bjPd+4wJstWIqP5A+lscnqbm0xxmT5Bpg8Lec5ItEBwx6BQ==",
"dev": true,
"license": "MIT",
"engines": {
@ -14454,20 +14499,20 @@
}
},
"node_modules/pac-proxy-agent": {
"version": "9.0.1",
"resolved": "https://registry.npmjs.org/pac-proxy-agent/-/pac-proxy-agent-9.0.1.tgz",
"integrity": "sha512-3ZOSpLboOlpW4yp8Cuv21KlTULRqyJ5Uuad3wXpSKFrxdNgcHEyoa22GRaZ2UlgCVuR6z+5BiavtYVvbajL/Yw==",
"version": "9.1.0",
"resolved": "https://registry.npmjs.org/pac-proxy-agent/-/pac-proxy-agent-9.1.0.tgz",
"integrity": "sha512-1aU+1mpj3DrQPfo3gh+3Gap3G5x+axnMx1P/y0ZF2ch7kb2meyOCAH8K2k9d27ROsTE7TnAerzxqF9aon2jqnA==",
"dev": true,
"license": "MIT",
"dependencies": {
"agent-base": "9.0.0",
"debug": "^4.3.4",
"get-uri": "8.0.0",
"http-proxy-agent": "9.0.0",
"https-proxy-agent": "9.0.0",
"get-uri": "8.0.1",
"http-proxy-agent": "9.1.0",
"https-proxy-agent": "9.1.0",
"pac-resolver": "9.0.1",
"quickjs-wasi": "^2.2.0",
"socks-proxy-agent": "10.0.0"
"socks-proxy-agent": "10.1.0"
},
"engines": {
"node": ">= 20"
@ -14484,28 +14529,30 @@
}
},
"node_modules/pac-proxy-agent/node_modules/http-proxy-agent": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-9.0.0.tgz",
"integrity": "sha512-FcF8VhXYLQcxWCnt/cCpT2apKsRDUGeVEeMqGu4HSTu29U8Yw0TLOjdYIlDsYk3IkUh+taX4IDWpPcCqKDhCjA==",
"version": "9.1.0",
"resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-9.1.0.tgz",
"integrity": "sha512-2NxoveTT58mjYT4n3RPTEfCZGLMbidoO8XEieXfpSYxu+PQJ1qpx4ypwH6N+uF9twBPIvRRgvkvW5HUTYWENig==",
"dev": true,
"license": "MIT",
"dependencies": {
"agent-base": "9.0.0",
"debug": "^4.3.4"
"debug": "^4.3.4",
"proxy-agent-negotiate": "1.1.0"
},
"engines": {
"node": ">= 20"
}
},
"node_modules/pac-proxy-agent/node_modules/https-proxy-agent": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-9.0.0.tgz",
"integrity": "sha512-/MVmHp58WkOypgFhCLk4fzpPcFQvTJ/e6LBI7irpIO2HfxUbpmYoHF+KzipzJpxxzJu7aJNWQ0xojJ/dzV2G5g==",
"version": "9.1.0",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-9.1.0.tgz",
"integrity": "sha512-ag87y7cJJ9/3+GxFr8Oy4O5faDsGRGnBGsJj/YjOSsSx/5eadKLYTMPlzuR6obgoCDDm0abAAZitXXQkMOPSpA==",
"dev": true,
"license": "MIT",
"dependencies": {
"agent-base": "9.0.0",
"debug": "^4.3.4"
"debug": "^4.3.4",
"proxy-agent-negotiate": "1.1.0"
},
"engines": {
"node": ">= 20"
@ -14994,9 +15041,9 @@
}
},
"node_modules/postcss": {
"version": "8.5.16",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.16.tgz",
"integrity": "sha512-vuwillviilfKZsg0VGj5R/YwwcHx4SLsIOI/7K6mQkWx+l5cUHTjj5g0AasTBcyXsbfTgrwsUNmVUb5xVwyPwg==",
"version": "8.5.21",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.21.tgz",
"integrity": "sha512-v4sDNP3fdNiWMfabO7OwOQdOX8TiQSztKyT1Wj0w+j7LDallJThJRBBBmzVGyYj0crMh7jlV4zepPkiNu9UwDQ==",
"dev": true,
"funding": [
{
@ -15014,7 +15061,7 @@
],
"license": "MIT",
"dependencies": {
"nanoid": "^3.3.12",
"nanoid": "^3.3.16",
"picocolors": "^1.1.1",
"source-map-js": "^1.2.1"
},
@ -15263,9 +15310,9 @@
"license": "MIT"
},
"node_modules/protobufjs": {
"version": "8.6.5",
"resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-8.6.5.tgz",
"integrity": "sha512-zeE5LPpencAGXvsxyOYmEgJhxzHY8IsmPAFzstZVhDSVT8QH03q6gMZwZRaQGApevZbAL6u28ugs4CC+YKB2jQ==",
"version": "8.7.1",
"resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-8.7.1.tgz",
"integrity": "sha512-agdGHrXNTv0IrYscJPDou/PlEJk1c/hBZ9o/B5NH2i/nSPtPqacNxzgwf1CebXxFMjMrZH5sqv9uQuw96aGt/A==",
"license": "BSD-3-Clause",
"dependencies": {
"long": "^5.3.2"
@ -15299,25 +15346,43 @@
}
},
"node_modules/proxy-agent": {
"version": "8.0.1",
"resolved": "https://registry.npmjs.org/proxy-agent/-/proxy-agent-8.0.1.tgz",
"integrity": "sha512-kccqGBqHZXR8onQhY/ganJjoO8QIKKRiFBhPOzbTZK16attzSZ/0XSmp9H7jrRxPKHjhGyx1q32lMPrJ3uLFgA==",
"version": "8.0.2",
"resolved": "https://registry.npmjs.org/proxy-agent/-/proxy-agent-8.0.2.tgz",
"integrity": "sha512-idLLRewuemWd7GH/BDJzGiB0dWGfT2SQs3jy6NtZtGWU9uPTTSdeC1/cdbqLwgzhfv027daGFuXX426e2Eg20A==",
"dev": true,
"license": "MIT",
"dependencies": {
"agent-base": "9.0.0",
"debug": "^4.3.4",
"http-proxy-agent": "9.0.0",
"https-proxy-agent": "9.0.0",
"http-proxy-agent": "9.1.0",
"https-proxy-agent": "9.1.0",
"lru-cache": "^7.14.1",
"pac-proxy-agent": "9.0.1",
"pac-proxy-agent": "9.1.0",
"proxy-from-env": "^2.0.0",
"socks-proxy-agent": "10.0.0"
"socks-proxy-agent": "10.1.0"
},
"engines": {
"node": ">= 20"
}
},
"node_modules/proxy-agent-negotiate": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-agent-negotiate/-/proxy-agent-negotiate-1.1.0.tgz",
"integrity": "sha512-N8IBcM3UgCVzz2L2Lqv8DVntDnnC8/hiV4nEDUPkqq72TPUgYWjQc+bdZlBPZK9LzPAvOY//gAt0S0DApoOXWQ==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">= 20"
},
"peerDependencies": {
"kerberos": "^2.0.0"
},
"peerDependenciesMeta": {
"kerberos": {
"optional": true
}
}
},
"node_modules/proxy-agent/node_modules/agent-base": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-9.0.0.tgz",
@ -15329,28 +15394,30 @@
}
},
"node_modules/proxy-agent/node_modules/http-proxy-agent": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-9.0.0.tgz",
"integrity": "sha512-FcF8VhXYLQcxWCnt/cCpT2apKsRDUGeVEeMqGu4HSTu29U8Yw0TLOjdYIlDsYk3IkUh+taX4IDWpPcCqKDhCjA==",
"version": "9.1.0",
"resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-9.1.0.tgz",
"integrity": "sha512-2NxoveTT58mjYT4n3RPTEfCZGLMbidoO8XEieXfpSYxu+PQJ1qpx4ypwH6N+uF9twBPIvRRgvkvW5HUTYWENig==",
"dev": true,
"license": "MIT",
"dependencies": {
"agent-base": "9.0.0",
"debug": "^4.3.4"
"debug": "^4.3.4",
"proxy-agent-negotiate": "1.1.0"
},
"engines": {
"node": ">= 20"
}
},
"node_modules/proxy-agent/node_modules/https-proxy-agent": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-9.0.0.tgz",
"integrity": "sha512-/MVmHp58WkOypgFhCLk4fzpPcFQvTJ/e6LBI7irpIO2HfxUbpmYoHF+KzipzJpxxzJu7aJNWQ0xojJ/dzV2G5g==",
"version": "9.1.0",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-9.1.0.tgz",
"integrity": "sha512-ag87y7cJJ9/3+GxFr8Oy4O5faDsGRGnBGsJj/YjOSsSx/5eadKLYTMPlzuR6obgoCDDm0abAAZitXXQkMOPSpA==",
"dev": true,
"license": "MIT",
"dependencies": {
"agent-base": "9.0.0",
"debug": "^4.3.4"
"debug": "^4.3.4",
"proxy-agent-negotiate": "1.1.0"
},
"engines": {
"node": ">= 20"
@ -15693,9 +15760,9 @@
}
},
"node_modules/readdir-glob/node_modules/brace-expansion": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.3.tgz",
"integrity": "sha512-MCV/fYJEbqx68aE58kv2cA/kiky1G8vux3OR6/jbS+jIMe/6fJWa0DTzJU7dqijOWYwHi1t29FlfYI9uytqlpA==",
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.2.tgz",
"integrity": "sha512-w5JZcKgdhDOgOwm8H+KgbosopHMuGcl6qbulwjtz3SM7I7P3yW1eAjzMPLrIE+NQ9vjgANKHWeMHnrT0OXW1oA==",
"dev": true,
"license": "MIT",
"dependencies": {
@ -16549,9 +16616,9 @@
}
},
"node_modules/shell-quote": {
"version": "1.8.4",
"resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.4.tgz",
"integrity": "sha512-VsC6n6vz1ihYYyZZwX7YZSF5l5x36ca17OC+a69h94YqB7X6XLwf+5MOgynYir2SLFUbl8gIYvBo8K8RoNQ6bQ==",
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.10.0.tgz",
"integrity": "sha512-w1aiOKwKuRgtwAReIIj89puqg+I7GvX4IbLrvmhXbzQsj1+Zwi4VO3+fa6ZF91TWSjIxoEkKnMeHcLEODK5ZXA==",
"dev": true,
"license": "MIT",
"engines": {
@ -16795,9 +16862,9 @@
}
},
"node_modules/socks-proxy-agent": {
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-10.0.0.tgz",
"integrity": "sha512-pyp2YR3mNxAMu0mGLtzs4g7O3uT4/9sQOLAKcViAkaS9fJWkud7nmaf6ZREFqQEi24IPkBcjfHjXhPTUWjo3uA==",
"version": "10.1.0",
"resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-10.1.0.tgz",
"integrity": "sha512-WlMj/67cEJ6MDI1OcsnjuYKDNDoyPCCYZ249kuuXPiMDw9F8PXkVaQ7YWu3siTydfQ/4BEZcvGzu+aYvz7dDCQ==",
"dev": true,
"license": "MIT",
"dependencies": {
@ -17235,14 +17302,14 @@
}
},
"node_modules/tcp-port-used": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/tcp-port-used/-/tcp-port-used-1.0.2.tgz",
"integrity": "sha512-l7ar8lLUD3XS1V2lfoJlCBaeoaWo/2xfYt81hM7VlvR4RrMVFqfmzfhLVk40hAb368uitje5gPtBRL1m/DGvLA==",
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/tcp-port-used/-/tcp-port-used-1.0.3.tgz",
"integrity": "sha512-4CEQ3qRJYo+mtEbJ+OoQu3dF4TDkwaO3RDVC4UzP5cpAOIUWwuwPjD7sdxDFFqsMUjsXVVYBMlg/boAaloThMA==",
"dev": true,
"license": "MIT",
"dependencies": {
"debug": "4.3.1",
"is2": "^2.0.6"
"is2": "2.0.1"
}
},
"node_modules/tcp-port-used/node_modules/debug": {
@ -17271,9 +17338,9 @@
"license": "MIT"
},
"node_modules/terser": {
"version": "5.48.0",
"resolved": "https://registry.npmjs.org/terser/-/terser-5.48.0.tgz",
"integrity": "sha512-J/9An6vs9Us6wKRriSFXBWdRZapREHqFzdNUKk0pmu804EMR6dr6winwo7e5JDxN4xahxQsuysyYFwlwj4XN/Q==",
"version": "5.49.0",
"resolved": "https://registry.npmjs.org/terser/-/terser-5.49.0.tgz",
"integrity": "sha512-SNiDnXyHSrxVcIOtVbULzcTmniUiwcV7Nwdyj1twVubeTmbjoa8p69KKDpfkdoOavuM4/GRm1+ykI8qqnavHoA==",
"dev": true,
"license": "BSD-2-Clause",
"dependencies": {
@ -18099,9 +18166,9 @@
}
},
"node_modules/webpack": {
"version": "5.108.3",
"resolved": "https://registry.npmjs.org/webpack/-/webpack-5.108.3.tgz",
"integrity": "sha512-hOpaCHmQVVY66IVTjofnH14IgSdmod2aquSGHGuYig/OIdWge01Hk2Wt988DZcwXumFUT4+FvJY5N+ikl8o/ww==",
"version": "5.108.4",
"resolved": "https://registry.npmjs.org/webpack/-/webpack-5.108.4.tgz",
"integrity": "sha512-yur8LyJoeiWh47dErD+Ok7vlbmDsJ3UbbRPAoxbGJ54WpE2y5yVo5G/inUzujnYgw3tPmBRdn+G7PoxXaYC33w==",
"dev": true,
"license": "MIT",
"dependencies": {
@ -18145,9 +18212,9 @@
}
},
"node_modules/webpack-bundle-analyzer": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/webpack-bundle-analyzer/-/webpack-bundle-analyzer-5.3.0.tgz",
"integrity": "sha512-PEhAoqiJ+47d0uLMx/+zo5XOvaU+Vk6N2ZLht7H3n09QLy/fhyvqGNwjdRUHJDgMN8crBR2ZwVHkIswT3Xuawg==",
"version": "5.3.1",
"resolved": "https://registry.npmjs.org/webpack-bundle-analyzer/-/webpack-bundle-analyzer-5.3.1.tgz",
"integrity": "sha512-wP2EusncRGL1tZyMHC/umLkjPdYMkTL9nPEKh8G8dkYCJ9TyF6xnXFqjhdqmv5J900irN/g0P5jMvLT22krEXQ==",
"dev": true,
"license": "MIT",
"dependencies": {
@ -18226,9 +18293,9 @@
}
},
"node_modules/webpack-dev-server": {
"version": "5.2.5",
"resolved": "https://registry.npmjs.org/webpack-dev-server/-/webpack-dev-server-5.2.5.tgz",
"integrity": "sha512-4wZtCquSuv9CKX8oybo+mqxtxZqWz47uM1Ch94lxowBztOhWCbhqvRbfC/mODOwxgV2brY+JGZpHq58/SuVFYg==",
"version": "5.2.6",
"resolved": "https://registry.npmjs.org/webpack-dev-server/-/webpack-dev-server-5.2.6.tgz",
"integrity": "sha512-HNLRmamRvVavZQ+avceZifmv8hmdUjg43t6MI4SqJDwFdW7RPQwH5vzGhDRZSX59SgfbeHhLnq3g+uooWo7pVw==",
"dev": true,
"license": "MIT",
"dependencies": {
@ -18250,7 +18317,7 @@
"graceful-fs": "^4.2.6",
"http-proxy-middleware": "^2.0.9",
"ipaddr.js": "^2.1.0",
"launch-editor": "^2.6.1",
"launch-editor": "^2.14.1",
"open": "^10.0.3",
"p-retry": "^6.2.0",
"schema-utils": "^4.2.0",
@ -18384,9 +18451,9 @@
}
},
"node_modules/websocket-driver": {
"version": "0.7.4",
"resolved": "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.4.tgz",
"integrity": "sha512-b17KeDIQVjvb0ssuSDF2cYXSg2iztliJ4B9WdsuB6J952qCPKmnVq4DyW5motImXHDC1cBT/1UezrJVsKw5zjg==",
"version": "0.7.5",
"resolved": "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.5.tgz",
"integrity": "sha512-ZL2+3c7kMBdIRCMz6l8jQMHyGVxj+UL+xVk74Ombiciboca8rHa15L86B19E5oh1pL9Ii/uj54gtsIrZGMo6zA==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "cyberchef",
"version": "11.2.0",
"version": "11.3.0",
"description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.",
"author": "GCHQ <CyberChef@gchq.gov.uk>",
"homepage": "https://gchq.github.io/CyberChef",
@ -47,13 +47,13 @@
"@codemirror/commands": "^6.10.4",
"@codemirror/language": "^6.12.4",
"@codemirror/search": "^6.7.1",
"@codemirror/state": "^6.5.4",
"@codemirror/view": "^6.43.4",
"@codemirror/state": "^6.7.1",
"@codemirror/view": "^6.43.6",
"@puppeteer/browsers": "3.0.6",
"autoprefixer": "^10.5.2",
"autoprefixer": "^10.5.4",
"babel-loader": "^10.1.1",
"base64-loader": "^1.0.0",
"chromedriver": "^148.0.4",
"chromedriver": "^150.0.4",
"cli-progress": "^3.12.0",
"colors": "^1.4.0",
"compression-webpack-plugin": "^12.0.0",
@ -61,7 +61,7 @@
"core-js": "^3.49.0",
"cspell": "^10.0.1",
"css-loader": "^7.1.4",
"eslint": "^9.39.4",
"eslint": "^9.39.5",
"eslint-plugin-jsdoc": "^50.8.0",
"globals": "^17.7.0",
"grunt": "^1.6.2",
@ -80,16 +80,16 @@
"mini-css-extract-plugin": "2.10.2",
"modify-source-webpack-plugin": "^4.1.0",
"nightwatch": "^3.16.0",
"postcss": "^8.5.16",
"postcss": "^8.5.21",
"postcss-css-variables": "^0.19.0",
"postcss-import": "^16.1.1",
"postcss-loader": "^8.2.1",
"prompt": "^1.3.0",
"sitemap": "^9.0.1",
"terser": "^5.48.0",
"webpack": "^5.108.3",
"webpack-bundle-analyzer": "^5.3.0",
"webpack-dev-server": "^5.2.5",
"terser": "^5.49.0",
"webpack": "^5.108.4",
"webpack-bundle-analyzer": "^5.3.1",
"webpack-dev-server": "^5.2.6",
"webpack-node-externals": "^3.0.0",
"worker-loader": "^3.0.8"
},
@ -105,7 +105,7 @@
"assert": "^2.1.0",
"avsc": "^5.7.9",
"bcryptjs": "^3.0.3",
"bignumber.js": "^11.1.4",
"bignumber.js": "^11.1.5",
"blakejs": "^1.2.1",
"bootstrap": "4.6.2",
"bootstrap-colorpicker": "^3.4.0",
@ -123,7 +123,7 @@
"d3": "7.9.0",
"d3-hexbin": "^0.2.2",
"diff": "^9.0.0",
"dompurify": "^3.4.11",
"dompurify": "^3.4.12",
"es6-promisify": "^7.0.0",
"escodegen": "^2.1.0",
"esprima": "^4.0.1",
@ -143,7 +143,7 @@
"js-sha3": "^0.9.3",
"jsesc": "^3.1.0",
"json5": "^2.2.3",
"jsonata": "^2.2.1",
"jsonata": "^2.2.2",
"jsonpath-plus": "^10.4.0",
"jsonwebtoken": "9.0.3",
"jsqr": "^1.4.0",
@ -156,9 +156,9 @@
"loglevel-message-prefix": "^3.0.0",
"lz-string": "^1.5.0",
"lz4js": "^0.2.0",
"markdown-it": "^14.2.0",
"markdown-it": "^14.3.0",
"moment": "^2.30.1",
"moment-timezone": "^0.6.2",
"moment-timezone": "^0.6.3",
"ngeohash": "^0.6.3",
"node-forge": "^1.4.0",
"node-md6": "^0.1.0",
@ -170,7 +170,7 @@
"path": "^0.12.7",
"popper.js": "^1.16.1",
"process": "^0.11.10",
"protobufjs": "^8.6.5",
"protobufjs": "^8.7.1",
"punycode.js": "^2.3.1",
"qr-image": "^3.2.0",
"reflect-metadata": "^0.2.2",
@ -193,6 +193,14 @@
"xregexp": "^5.1.2",
"zlibjs": "^0.3.1"
},
"allowScripts": {
"@nightwatch/nightwatch-inspector@1.0.1": true,
"chromedriver@150.0.3": true,
"core-js": false,
"core-js-pure": false,
"fsevents": false,
"tesseract.js": false
},
"scripts": {
"start": "npx grunt dev",
"build": "npx grunt prod",

View File

@ -1015,6 +1015,7 @@ class Utils {
// Parse bespoke recipe format
recipe = recipe.replace(/\n/g, "");
Utils._validatePrettyRecipe(recipe);
let m, args;
const recipeRegex = /([^(]+)\(((?:'[^'\\]*(?:\\.[^'\\]*)*'|[^)/'])*)(\/[^)]+)?\)/g,
recipeConfig = [];
@ -1040,6 +1041,53 @@ class Utils {
}
/**
* Performs a linear structural validation pass over pretty recipe syntax.
*
* @param {string} recipe
* @throws {Error} if the recipe is structurally invalid
*/
static _validatePrettyRecipe(recipe) {
let i = 0;
while (i < recipe.length) {
const openParen = recipe.indexOf("(", i);
if (openParen === -1 || openParen === i) {
throw new Error("Invalid recipe");
}
i = openParen + 1;
let inString = false,
escaped = false,
foundCloseParen = false;
for (; i < recipe.length; i++) {
const c = recipe[i];
if (inString) {
if (escaped) {
escaped = false;
} else if (c === "\\") {
escaped = true;
} else if (c === "'") {
inString = false;
}
} else if (c === "'") {
inString = true;
} else if (c === ")") {
foundCloseParen = true;
i++;
break;
}
}
if (!foundCloseParen || inString || escaped) {
throw new Error("Invalid recipe");
}
}
}
/**
* Formats a list of files or directories.
*

View File

@ -83,7 +83,9 @@
"Rison Decode",
"To Modhex",
"From Modhex",
"MIME Decoding"
"MIME Decoding",
"To COBS",
"From COBS"
]
},
{
@ -115,6 +117,10 @@
"RC6 Decrypt",
"Ascon Encrypt",
"Ascon Decrypt",
"PRESENT Encrypt",
"PRESENT Decrypt",
"Twofish Encrypt",
"Twofish Decrypt",
"GOST Encrypt",
"GOST Decrypt",
"GOST Sign",
@ -131,6 +137,10 @@
"XOR Brute Force",
"Vigenère Encode",
"Vigenère Decode",
"TEA Encrypt",
"TEA Decrypt",
"XTEA Encrypt",
"XTEA Decrypt",
"XXTEA Encrypt",
"XXTEA Decrypt",
"To Morse Code",
@ -165,6 +175,7 @@
"AES Key Wrap",
"AES Key Unwrap",
"Pseudo-Random Number Generator",
"Pseudo-Random Prime Generator",
"Enigma",
"Bombe",
"Multiple Bombe",
@ -233,9 +244,9 @@
"Subtract",
"Multiply",
"Divide",
"Modular Exponentiation",
"Modular Inverse",
"MOD",
"Extended GCD",
"Modular Inverse",
"Mean",
"Median",
"Standard Deviation",

View File

@ -0,0 +1,139 @@
/**
* This script automatically generates src/core/lib/HTMLEntities.mjs, the shared
* HTML entity lookup tables used by the "To HTML Entity" and "From HTML Entity"
* operations.
*
* The data is derived from the vendored WHATWG named character reference set
* (src/core/vendor/htmlEntities/entity.json, from
* https://html.spec.whatwg.org/entities.json) so the
* two operations cannot drift apart and every entity is spec-conformant:
*
* - HTML_ENTITY_REVERSE_LOOKUP (decode) is every single-code-point spec name.
* - HTML_ENTITY_LOOKUP (encode) picks one canonical name per code point via a
* deterministic tiebreak, overridden by htmlEntityOverrides.mjs where a
* specific historical name is preferred.
*
* @author roberson-io [michaelroberson@gmail.com]
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
/* eslint no-console: ["off"] */
import path from "path";
import fs from "fs";
import process from "process";
import { fileURLToPath } from "url";
import { HTML_ENTITY_CANONICAL_OVERRIDES } from "./htmlEntityOverrides.mjs";
const scriptDir = path.dirname(fileURLToPath(import.meta.url));
if (!fs.existsSync(path.join(process.cwd(), "src/core/lib"))) {
console.log("\nCWD: " + process.cwd());
console.log("Error: generateHTMLEntities.mjs should be run from the project root");
console.log("Example> node src/core/config/scripts/generateHTMLEntities.mjs");
process.exit(1);
}
const SPEC = JSON.parse(fs.readFileSync(
path.join(scriptDir, "..", "..", "vendor", "htmlEntities", "entity.json"), "utf8"));
// Build code point -> [spec names] for single-code-point, semicolon-terminated
// references (the representable subset; multi-code-point entities are skipped).
const codePointNames = {};
for (const [key, val] of Object.entries(SPEC)) {
if (!key.endsWith(";") || val.codepoints.length !== 1) continue;
const name = key.slice(1, -1); // strip leading "&" and trailing ";"
(codePointNames[val.codepoints[0]] ??= []).push(name);
}
// Deterministic canonical-name tiebreak: prefer a lower-case name, then the
// shortest, then alphabetical. Overridden per code point where a specific
// historical name is preferred.
const isAllUpper = s => s === s.toUpperCase() && s !== s.toLowerCase();
/**
* Choose the single canonical entity name for a code point.
*
* @param {number} codePoint - the Unicode code point being encoded
* @param {string[]} names - all valid WHATWG names for that code point
* @returns {string} the canonical name to emit when encoding
*/
function canonicalName(codePoint, names) {
const override = HTML_ENTITY_CANONICAL_OVERRIDES[codePoint];
if (override !== undefined) {
if (!names.includes(override))
throw new Error(`Override &${override}; is not a spec name for code point ${codePoint} (spec: ${names})`);
return override;
}
return [...names].sort((a, b) =>
(isAllUpper(a) - isAllUpper(b)) ||
(a.length - b.length) ||
(a < b ? -1 : a > b ? 1 : 0)
)[0];
}
const forward = {}; // code point -> canonical name (encode)
const reverse = {}; // name -> code point (decode, every spec name)
for (const [cpStr, names] of Object.entries(codePointNames)) {
const cp = Number(cpStr);
forward[cp] = canonicalName(cp, names);
for (const name of names) reverse[name] = cp;
}
// Decode-only aliases = spec names that are not the canonical encode name.
const aliases = {};
for (const [name, cp] of Object.entries(reverse)) {
if (forward[cp] !== name) aliases[name] = cp;
}
// --- emit -----------------------------------------------------------------
const fwdEntries = Object.keys(forward).map(Number).sort((a, b) => a - b)
.map(cp => ` ${cp}: "${forward[cp]}",`).join("\n").replace(/,$/, "");
const aliasEntries = Object.keys(aliases).sort()
.map(n => ` ${JSON.stringify(n)}: ${aliases[n]},`).join("\n").replace(/,$/, "");
const code = `/**
* THIS FILE IS AUTOMATICALLY GENERATED BY src/core/config/scripts/generateHTMLEntities.mjs
*
* HTML entity lookup tables shared by the "To HTML Entity" and "From HTML Entity"
* operations, derived from the WHATWG named character reference set
* (https://html.spec.whatwg.org/entities.json). Do not edit by hand — change the
* vendored src/core/vendor/htmlEntities/entity.json or htmlEntityOverrides.mjs
* and regenerate.
*
* @author roberson-io [michaelroberson@gmail.com]
* @copyright Crown Copyright ${new Date().getUTCFullYear()}
* @license Apache-2.0
*/
/**
* Canonical lookup: Unicode code point -> entity name (without "&" and ";"),
* used for ENCODING. One canonical name per code point.
*/
export const HTML_ENTITY_LOOKUP = {
${fwdEntries}
};
/**
* Legacy / alias names that only DECODE (spelling variants, deprecated names,
* box-drawing aliases, etc.); not used for encoding.
*/
export const HTML_ENTITY_DECODE_ALIASES = {
${aliasEntries}
};
/**
* Derived reverse lookup: entity name -> code point, used for DECODING. Built
* from the canonical lookup plus the legacy aliases.
*/
export const HTML_ENTITY_REVERSE_LOOKUP = {...HTML_ENTITY_DECODE_ALIASES};
for (const codePoint in HTML_ENTITY_LOOKUP) {
HTML_ENTITY_REVERSE_LOOKUP[HTML_ENTITY_LOOKUP[codePoint]] = Number(codePoint);
}
`;
fs.writeFileSync(path.join(process.cwd(), "src/core/lib/HTMLEntities.mjs"), code);
console.log(`generateHTMLEntities: ${Object.keys(forward).length} encode names, ` +
`${Object.keys(reverse).length} decode names, ${Object.keys(aliases).length} aliases, ` +
`${Object.keys(HTML_ENTITY_CANONICAL_OVERRIDES).length} overrides applied.`);

View File

@ -0,0 +1,86 @@
/**
* Canonical entity-name overrides for generateHTMLEntities.mjs.
*
* The WHATWG named character reference set assigns MANY names to some code
* points (e.g. U+2211 is both &sum; and &Sum;), but does not designate a
* canonical one. The generator therefore needs a rule to pick a single name per
* code point for ENCODING. It uses a deterministic tiebreak (prefer a
* lower-case name, then the shortest, then alphabetical), which reproduces the
* historically-emitted name for ~1355 of the ~1414 encodable code points.
*
* This file pins the canonical name for the code points where the tiebreak
* would otherwise change the emitted entity. Every value here is still a valid
* WHATWG name for that code point (the generator asserts this) these are
* editorial choices, not correctness fixes, kept so "To HTML Entity" output
* stays stable. Trim an entry to let the tiebreak decide instead.
*
* @author roberson-io [michaelroberson@gmail.com]
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
/**
* @constant
* @type {Object.<number, string>}
*/
export const HTML_ENTITY_CANONICAL_OVERRIDES = {
124: "verbar",
168: "uml",
177: "plusmn",
189: "frac12",
247: "divide",
711: "caron",
728: "breve",
937: "Omega",
949: "epsilon",
965: "upsilon",
977: "thetasym",
978: "upsih",
981: "straightphi",
8208: "hyphen",
8214: "Verbar",
8230: "hellip",
8289: "ApplyFunction",
8290: "InvisibleTimes",
8291: "InvisibleComma",
8459: "hamilt",
8461: "quaternions",
8463: "planck",
8465: "image",
8472: "weierp",
8474: "rationals",
8476: "real",
8477: "reals",
8484: "integers",
8492: "bernou",
8499: "phmmat",
8500: "order",
8501: "alefsym",
8518: "DifferentialD",
8519: "ExponentialE",
8520: "ImaginaryI",
8612: "LeftTeeArrow",
8613: "UpTeeArrow",
8615: "DownTeeArrow",
8624: "lsh",
8625: "rsh",
8660: "hArr",
8704: "forall",
8711: "nabla",
8712: "isin",
8721: "sum",
8723: "mnplus",
8730: "radic",
8750: "conint",
8768: "wreath",
8776: "asymp",
8781: "asympeq",
8784: "esdot",
8788: "colone",
8869: "perp",
8896: "xwedge",
8897: "xvee",
8902: "sstarf",
10536: "nesear",
10537: "seswar"
};

View File

@ -124,6 +124,19 @@ export function median(data) {
}
/**
* Computes modulo of two numbers and returns the value.
*
* @param {BigNumber[]} data
* @returns {BigNumber}
*/
export function mod(data) {
if (data.length > 0) {
return data.reduce((acc, curr) => acc.mod(curr));
}
}
/**
* Computes standard deviation of a number array and returns the value.
*

View File

@ -70,4 +70,3 @@ export function modPow(base, exponent, modulus) {
return result;
}

86
src/core/lib/COBS.mjs Normal file
View File

@ -0,0 +1,86 @@
/**
* @author Imantas Lukenskas [imantas@lukenskas.dev]
* @copyright Imantas Lukenskas 2026
* @license Apache-2.0
*/
import OperationError from "../errors/OperationError.mjs";
/**
* COBS-encode a byte array
* @param {Uint8Array} data
* @return {Uint8Array}
*/
export function toCobs(data) {
if (!data || data.length === 0) {
return new Uint8Array();
}
const output = [];
data = [0, ...data];
while (data.length > 0) {
const endIndex = data.findIndex((value, index) => value === 0 && index > 0);
if ((endIndex < 0 || endIndex > 254) && data.length > 254) {
output.push(255);
output.push(...data.slice(1, 255));
data = data.slice(255);
if (data.length !== 0) {
data = [0, ...data];
}
} else if (endIndex < 0) {
output.push(data.length);
output.push(...data.slice(1));
data = [];
} else {
output.push(endIndex);
output.push(...data.slice(1, endIndex));
data = data.slice(endIndex);
}
}
return output;
}
/**
* COBS-decode a byte array
* @param {Uint8Array} data
* @return {Uint8Array}
*/
export function fromCobs(data) {
if (!data || data.length === 0) {
return new Uint8Array();
}
if (data.findIndex((value) => value === 0) >= 0) {
throw new OperationError("Could not decode from COBS: payload must not contain a 0x00 byte");
}
const output = [];
while (data.length > 0) {
if (data[0] === 0xFF) {
output.push(...data.slice(1, 255));
data = data.slice(255);
} else {
const nextZeroIndex = data[0];
output.push(...data.slice(1, nextZeroIndex));
data = data.slice(nextZeroIndex);
let blockSize = data[0];
while (data.length > 0) {
output.push(0, ...data.slice(1, blockSize));
data = data.slice(blockSize);
if (blockSize === 0xFF) {
break;
}
blockSize = data[0];
}
}
}
return output;
}

View File

@ -24,12 +24,12 @@ import Utils from "../Utils.mjs";
* fromDecimal("10:20:30", "Colon");
*/
export function fromDecimal(data, delim="Auto") {
delim = Utils.charRep(delim);
const output = [];
let byteStr = data.split(delim);
if (byteStr[byteStr.length-1] === "")
byteStr = byteStr.slice(0, byteStr.length-1);
const delimRegex = delim === "Auto" ? /[^\d-]+/ : Utils.regexRep(delim);
let byteStr = data.split(delimRegex);
byteStr = byteStr.filter(str => str !== "");
const output = [];
for (let i = 0; i < byteStr.length; i++) {
output[i] = parseInt(byteStr[i], 10);
}

422
src/core/lib/Present.mjs Normal file
View File

@ -0,0 +1,422 @@
/**
* Complete implementation of PRESENT block cipher encryption/decryption with
* ECB and CBC block modes.
*
* PRESENT is an ultra-lightweight block cipher designed for constrained environments.
* Standardised in ISO/IEC 29192-2:2019.
*
* Reference: "PRESENT: An Ultra-Lightweight Block Cipher"
* https://link.springer.com/chapter/10.1007/978-3-540-74735-2_31
*
* @author Medjedtxm
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
import OperationError from "../errors/OperationError.mjs";
/** Number of rounds */
const NROUNDS = 31;
/** Block size in bytes (64 bits) */
const BLOCKSIZE = 8;
/** The 4-bit S-box (16 values) */
const SBOX = [
0xC, 0x5, 0x6, 0xB, 0x9, 0x0, 0xA, 0xD,
0x3, 0xE, 0xF, 0x8, 0x4, 0x7, 0x1, 0x2
];
/** Inverse S-box for decryption */
const SBOX_INV = [
0x5, 0xE, 0xF, 0x8, 0xC, 0x1, 0x2, 0xD,
0xB, 0x4, 0x6, 0x3, 0x0, 0x7, 0x9, 0xA
];
/** P-layer permutation table (bit i goes to position P[i]) */
const PBOX = [
0, 16, 32, 48, 1, 17, 33, 49, 2, 18, 34, 50, 3, 19, 35, 51,
4, 20, 36, 52, 5, 21, 37, 53, 6, 22, 38, 54, 7, 23, 39, 55,
8, 24, 40, 56, 9, 25, 41, 57, 10, 26, 42, 58, 11, 27, 43, 59,
12, 28, 44, 60, 13, 29, 45, 61, 14, 30, 46, 62, 15, 31, 47, 63
];
/** Inverse P-layer permutation for decryption */
const PBOX_INV = new Array(64);
for (let i = 0; i < 64; i++) {
PBOX_INV[PBOX[i]] = i;
}
/**
* Convert byte array to BigInt (big-endian)
* @param {number[]} bytes - Array of bytes
* @returns {bigint} - 64-bit value as BigInt
*/
function bytesToBigInt(bytes) {
let result = 0n;
for (let i = 0; i < bytes.length; i++) {
result = (result << 8n) | BigInt(bytes[i]);
}
return result;
}
/**
* Convert BigInt to byte array (big-endian)
* @param {bigint} value - BigInt value
* @param {number} length - Desired byte array length
* @returns {number[]} - Array of bytes
*/
function bigIntToBytes(value, length) {
const bytes = [];
for (let i = length - 1; i >= 0; i--) {
bytes[i] = Number(value & 0xFFn);
value >>= 8n;
}
return bytes;
}
/**
* Apply S-box substitution layer to 64-bit state
* @param {bigint} state - 64-bit state
* @param {number[]} sbox - S-box to use
* @returns {bigint} - Substituted state
*/
function sBoxLayer(state, sbox) {
let result = 0n;
for (let i = 0; i < 16; i++) {
const nibble = Number((state >> BigInt(i * 4)) & 0xFn);
result |= BigInt(sbox[nibble]) << BigInt(i * 4);
}
return result;
}
/**
* Apply P-layer permutation to 64-bit state
* @param {bigint} state - 64-bit state
* @param {number[]} pbox - Permutation table to use
* @returns {bigint} - Permuted state
*/
function pLayer(state, pbox) {
let result = 0n;
for (let i = 0; i < 64; i++) {
if ((state >> BigInt(i)) & 1n) {
result |= 1n << BigInt(pbox[i]);
}
}
return result;
}
/**
* Generate round keys for 80-bit key
* @param {number[]} key - 10-byte key
* @returns {bigint[]} - Array of 32 round keys (64-bit each)
*/
function generateRoundKeys80(key) {
// Key register is 80 bits
let keyReg = bytesToBigInt(key);
const roundKeys = [];
for (let i = 1; i <= NROUNDS + 1; i++) {
// Extract round key (leftmost 64 bits)
roundKeys.push(keyReg >> 16n);
// Rotate left by 61 positions
keyReg = ((keyReg << 61n) | (keyReg >> 19n)) & ((1n << 80n) - 1n);
// Apply S-box to leftmost 4 bits
const leftNibble = Number(keyReg >> 76n);
keyReg = (keyReg & ((1n << 76n) - 1n)) | (BigInt(SBOX[leftNibble]) << 76n);
// XOR round counter to bits 19-15
keyReg ^= BigInt(i) << 15n;
}
return roundKeys;
}
/**
* Generate round keys for 128-bit key
* @param {number[]} key - 16-byte key
* @returns {bigint[]} - Array of 32 round keys (64-bit each)
*/
function generateRoundKeys128(key) {
// Key register is 128 bits
let keyReg = bytesToBigInt(key);
const roundKeys = [];
for (let i = 1; i <= NROUNDS + 1; i++) {
// Extract round key (leftmost 64 bits)
roundKeys.push(keyReg >> 64n);
// Rotate left by 61 positions
keyReg = ((keyReg << 61n) | (keyReg >> 67n)) & ((1n << 128n) - 1n);
// Apply S-box to leftmost 8 bits (two nibbles: bits 127-124 and 123-120)
const leftByte = Number((keyReg >> 120n) & 0xFFn);
const leftNibble1 = (leftByte >> 4) & 0xF; // bits 127-124
const leftNibble2 = leftByte & 0xF; // bits 123-120
keyReg = (keyReg & ((1n << 120n) - 1n)) |
(BigInt((SBOX[leftNibble1] << 4) | SBOX[leftNibble2]) << 120n);
// XOR round counter to bits 66-62
keyReg ^= BigInt(i) << 62n;
}
return roundKeys;
}
/**
* Encrypt a single 64-bit block
* @param {bigint} block - 64-bit plaintext block
* @param {bigint[]} roundKeys - Round keys
* @returns {bigint} - 64-bit ciphertext block
*/
function encryptBlock(block, roundKeys) {
let state = block;
for (let i = 0; i < NROUNDS; i++) {
// Add round key
state ^= roundKeys[i];
// S-box layer
state = sBoxLayer(state, SBOX);
// P-layer
state = pLayer(state, PBOX);
}
// Final round key addition
state ^= roundKeys[NROUNDS];
return state;
}
/**
* Decrypt a single 64-bit block
* @param {bigint} block - 64-bit ciphertext block
* @param {bigint[]} roundKeys - Round keys
* @returns {bigint} - 64-bit plaintext block
*/
function decryptBlock(block, roundKeys) {
let state = block;
// Reverse key addition
state ^= roundKeys[NROUNDS];
for (let i = NROUNDS - 1; i >= 0; i--) {
// Inverse P-layer
state = pLayer(state, PBOX_INV);
// Inverse S-box layer
state = sBoxLayer(state, SBOX_INV);
// Add round key
state ^= roundKeys[i];
}
return state;
}
/**
* Apply padding to message
* @param {number[]} message - Original message
* @param {string} padding - Padding type ("NO", "PKCS5", "ZERO", "RANDOM", "BIT")
* @param {number} blockSize - Block size in bytes
* @returns {number[]} - Padded message
*/
function applyPadding(message, padding, blockSize) {
const remainder = message.length % blockSize;
let nPadding = remainder === 0 ? 0 : blockSize - remainder;
// For PKCS5, always add at least one byte (full block if already aligned)
if (padding === "PKCS5" && remainder === 0) {
nPadding = blockSize;
}
if (nPadding === 0) return [...message];
const paddedMessage = [...message];
switch (padding) {
case "NO":
throw new OperationError(`No padding requested but input is not a ${blockSize}-byte multiple.`);
case "PKCS5":
for (let i = 0; i < nPadding; i++) {
paddedMessage.push(nPadding);
}
break;
case "ZERO":
for (let i = 0; i < nPadding; i++) {
paddedMessage.push(0);
}
break;
case "RANDOM":
for (let i = 0; i < nPadding; i++) {
paddedMessage.push(Math.floor(Math.random() * 256));
}
break;
case "BIT":
paddedMessage.push(0x80);
for (let i = 1; i < nPadding; i++) {
paddedMessage.push(0);
}
break;
default:
throw new OperationError(`Unknown padding type: ${padding}`);
}
return paddedMessage;
}
/**
* Remove padding from message
* @param {number[]} message - Padded message
* @param {string} padding - Padding type ("NO", "PKCS5", "ZERO", "RANDOM", "BIT")
* @param {number} blockSize - Block size in bytes
* @returns {number[]} - Unpadded message
*/
function removePadding(message, padding, blockSize) {
if (message.length === 0) return message;
switch (padding) {
case "NO":
case "ZERO":
case "RANDOM":
// These padding types cannot be reliably removed
return message;
case "PKCS5": {
const padByte = message[message.length - 1];
if (padByte > 0 && padByte <= blockSize) {
// Verify padding
for (let i = 0; i < padByte; i++) {
if (message[message.length - 1 - i] !== padByte) {
throw new OperationError("Invalid PKCS#5 padding.");
}
}
return message.slice(0, message.length - padByte);
}
throw new OperationError("Invalid PKCS#5 padding.");
}
case "BIT": {
// Find 0x80 byte working backwards, skipping zeros
for (let i = message.length - 1; i >= 0; i--) {
if (message[i] === 0x80) {
return message.slice(0, i);
} else if (message[i] !== 0) {
throw new OperationError("Invalid BIT padding.");
}
}
throw new OperationError("Invalid BIT padding.");
}
default:
throw new OperationError(`Unknown padding type: ${padding}`);
}
}
/**
* Encrypt using PRESENT cipher with specified block mode
*
* @param {number[]} message - Plaintext as byte array
* @param {number[]} key - Key (10 bytes for 80-bit or 16 bytes for 128-bit)
* @param {number[]} iv - IV (8 bytes, not used for ECB)
* @param {string} mode - Block cipher mode ("ECB" or "CBC")
* @param {string} padding - Padding type ("NO", "PKCS5", "ZERO", "RANDOM", "BIT")
* @returns {number[]} - Ciphertext as byte array
*/
export function encryptPRESENT(message, key, iv, mode = "ECB", padding = "PKCS5") {
if (message.length === 0) return [];
// Generate round keys based on key length
const roundKeys = key.length === 10 ?
generateRoundKeys80(key) :
generateRoundKeys128(key);
// Apply padding
const paddedMessage = applyPadding(message, padding, BLOCKSIZE);
const cipherText = [];
switch (mode) {
case "ECB":
for (let i = 0; i < paddedMessage.length; i += BLOCKSIZE) {
const block = bytesToBigInt(paddedMessage.slice(i, i + BLOCKSIZE));
const encrypted = encryptBlock(block, roundKeys);
cipherText.push(...bigIntToBytes(encrypted, BLOCKSIZE));
}
break;
case "CBC": {
let ivBlock = bytesToBigInt(iv);
for (let i = 0; i < paddedMessage.length; i += BLOCKSIZE) {
let block = bytesToBigInt(paddedMessage.slice(i, i + BLOCKSIZE));
block ^= ivBlock;
const encrypted = encryptBlock(block, roundKeys);
cipherText.push(...bigIntToBytes(encrypted, BLOCKSIZE));
ivBlock = encrypted;
}
break;
}
default:
throw new OperationError(`Invalid block cipher mode: ${mode}`);
}
return cipherText;
}
/**
* Decrypt using PRESENT cipher with specified block mode
*
* @param {number[]} cipherText - Ciphertext as byte array
* @param {number[]} key - Key (10 bytes for 80-bit or 16 bytes for 128-bit)
* @param {number[]} iv - IV (8 bytes, not used for ECB)
* @param {string} mode - Block cipher mode ("ECB" or "CBC")
* @param {string} padding - Padding type ("NO", "PKCS5", "ZERO", "RANDOM", "BIT")
* @returns {number[]} - Plaintext as byte array
*/
export function decryptPRESENT(cipherText, key, iv, mode = "ECB", padding = "PKCS5") {
if (cipherText.length === 0) return [];
if (cipherText.length % BLOCKSIZE !== 0) {
throw new OperationError(`Invalid ciphertext length: ${cipherText.length} bytes. Must be a multiple of 8.`);
}
// Generate round keys based on key length
const roundKeys = key.length === 10 ?
generateRoundKeys80(key) :
generateRoundKeys128(key);
const plainText = [];
switch (mode) {
case "ECB":
for (let i = 0; i < cipherText.length; i += BLOCKSIZE) {
const block = bytesToBigInt(cipherText.slice(i, i + BLOCKSIZE));
const decrypted = decryptBlock(block, roundKeys);
plainText.push(...bigIntToBytes(decrypted, BLOCKSIZE));
}
break;
case "CBC": {
let ivBlock = bytesToBigInt(iv);
for (let i = 0; i < cipherText.length; i += BLOCKSIZE) {
const block = bytesToBigInt(cipherText.slice(i, i + BLOCKSIZE));
let decrypted = decryptBlock(block, roundKeys);
decrypted ^= ivBlock;
plainText.push(...bigIntToBytes(decrypted, BLOCKSIZE));
ivBlock = block;
}
break;
}
default:
throw new OperationError(`Invalid block cipher mode: ${mode}`);
}
// Remove padding
return removePadding(plainText, padding, BLOCKSIZE);
}

494
src/core/lib/TEA.mjs Normal file
View File

@ -0,0 +1,494 @@
/**
* TEA and XTEA block cipher implementation.
*
* TEA (Tiny Encryption Algorithm) Wheeler & Needham, 1994.
* XTEA (Extended TEA) Wheeler & Needham, 1997.
*
* Both operate on 64-bit blocks with 128-bit keys.
* TEA uses 32 cycles (64 Feistel rounds).
* XTEA uses 32 cycles (64 Feistel rounds) with improved key schedule.
*
* References:
* https://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm
* https://en.wikipedia.org/wiki/XTEA
* https://www.cix.co.uk/~klockstone/teavect.htm
*
* @author Medjedtxm
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
import OperationError from "../errors/OperationError.mjs";
/** TEA/XTEA constants */
const DELTA = 0x9E3779B9;
const BLOCK_SIZE = 8; // 64-bit block = 8 bytes
const ROUNDS = 32; // 32 cycles
/**
* Convert byte array to array of 32-bit unsigned integers (big-endian)
* @param {number[]} bytes
* @returns {number[]}
*/
function bytesToUint32(bytes) {
const words = [];
for (let i = 0; i < bytes.length; i += 4) {
words.push(
((bytes[i] << 24) | (bytes[i + 1] << 16) |
(bytes[i + 2] << 8) | bytes[i + 3]) >>> 0
);
}
return words;
}
/**
* Convert array of 32-bit unsigned integers to byte array (big-endian)
* @param {number[]} words
* @returns {number[]}
*/
function uint32ToBytes(words) {
const bytes = [];
for (const w of words) {
bytes.push((w >>> 24) & 0xFF);
bytes.push((w >>> 16) & 0xFF);
bytes.push((w >>> 8) & 0xFF);
bytes.push(w & 0xFF);
}
return bytes;
}
/**
* TEA encrypt a single 64-bit block
* Reference: Wheeler & Needham, 1994
*
* @param {number[]} block - 8 bytes (plaintext)
* @param {number[]} key - 16 bytes (128-bit key)
* @returns {number[]} - 8 bytes (ciphertext)
*/
function teaEncryptBlock(block, key) {
const v = bytesToUint32(block);
const k = bytesToUint32(key);
let v0 = v[0], v1 = v[1];
let sum = 0;
for (let i = 0; i < ROUNDS; i++) {
sum = (sum + DELTA) >>> 0;
v0 = (v0 + ((((v1 << 4) + k[0]) ^ (v1 + sum) ^ ((v1 >>> 5) + k[1])))) >>> 0;
v1 = (v1 + ((((v0 << 4) + k[2]) ^ (v0 + sum) ^ ((v0 >>> 5) + k[3])))) >>> 0;
}
return uint32ToBytes([v0, v1]);
}
/**
* TEA decrypt a single 64-bit block
*
* @param {number[]} block - 8 bytes (ciphertext)
* @param {number[]} key - 16 bytes (128-bit key)
* @returns {number[]} - 8 bytes (plaintext)
*/
function teaDecryptBlock(block, key) {
const v = bytesToUint32(block);
const k = bytesToUint32(key);
let v0 = v[0], v1 = v[1];
let sum = (DELTA * ROUNDS) >>> 0;
for (let i = 0; i < ROUNDS; i++) {
v1 = (v1 - ((((v0 << 4) + k[2]) ^ (v0 + sum) ^ ((v0 >>> 5) + k[3])))) >>> 0;
v0 = (v0 - ((((v1 << 4) + k[0]) ^ (v1 + sum) ^ ((v1 >>> 5) + k[1])))) >>> 0;
sum = (sum - DELTA) >>> 0;
}
return uint32ToBytes([v0, v1]);
}
/**
* XTEA encrypt a single 64-bit block
* Reference: Wheeler & Needham, 1997
*
* @param {number[]} block - 8 bytes (plaintext)
* @param {number[]} key - 16 bytes (128-bit key)
* @param {number} rounds - Number of rounds (default 32)
* @returns {number[]} - 8 bytes (ciphertext)
*/
function xteaEncryptBlock(block, key, rounds) {
const v = bytesToUint32(block);
const k = bytesToUint32(key);
let v0 = v[0], v1 = v[1];
let sum = 0;
for (let i = 0; i < rounds; i++) {
v0 = (v0 + ((((v1 << 4) ^ (v1 >>> 5)) + v1) ^ (sum + k[sum & 3]))) >>> 0;
sum = (sum + DELTA) >>> 0;
v1 = (v1 + ((((v0 << 4) ^ (v0 >>> 5)) + v0) ^ (sum + k[(sum >>> 11) & 3]))) >>> 0;
}
return uint32ToBytes([v0, v1]);
}
/**
* XTEA decrypt a single 64-bit block
*
* @param {number[]} block - 8 bytes (ciphertext)
* @param {number[]} key - 16 bytes (128-bit key)
* @param {number} rounds - Number of rounds (default 32)
* @returns {number[]} - 8 bytes (plaintext)
*/
function xteaDecryptBlock(block, key, rounds) {
const v = bytesToUint32(block);
const k = bytesToUint32(key);
let v0 = v[0], v1 = v[1];
let sum = (DELTA * rounds) >>> 0;
for (let i = 0; i < rounds; i++) {
v1 = (v1 - ((((v0 << 4) ^ (v0 >>> 5)) + v0) ^ (sum + k[(sum >>> 11) & 3]))) >>> 0;
sum = (sum - DELTA) >>> 0;
v0 = (v0 - ((((v1 << 4) ^ (v1 >>> 5)) + v1) ^ (sum + k[sum & 3]))) >>> 0;
}
return uint32ToBytes([v0, v1]);
}
/**
* XOR two byte arrays of equal length
* @param {number[]} a
* @param {number[]} b
* @returns {number[]}
*/
function xorBlocks(a, b) {
return a.map((byte, i) => byte ^ b[i]);
}
/**
* Increment a byte array as a big-endian counter
* @param {number[]} counter
* @returns {number[]}
*/
function incrementCounter(counter) {
const result = [...counter];
for (let i = result.length - 1; i >= 0; i--) {
result[i] = (result[i] + 1) & 0xFF;
if (result[i] !== 0) break;
}
return result;
}
/**
* Apply padding to message
* @param {number[]} message
* @param {string} padding - "NO", "PKCS5", "ZERO", "RANDOM", "BIT"
* @returns {number[]}
*/
function applyPadding(message, padding) {
const remainder = message.length % BLOCK_SIZE;
if (remainder === 0 && padding !== "PKCS5") return [...message];
const nPadding = (remainder === 0 && padding === "PKCS5") ?
BLOCK_SIZE :
BLOCK_SIZE - remainder;
if (nPadding === 0) return [...message];
const padded = [...message];
switch (padding) {
case "NO":
throw new OperationError(
`No padding requested but input length (${message.length} bytes) is not a multiple of ${BLOCK_SIZE} bytes.`
);
case "PKCS5":
for (let i = 0; i < nPadding; i++) padded.push(nPadding);
break;
case "ZERO":
for (let i = 0; i < nPadding; i++) padded.push(0);
break;
case "RANDOM":
for (let i = 0; i < nPadding; i++) padded.push(Math.floor(Math.random() * 256));
break;
case "BIT":
padded.push(0x80);
for (let i = 1; i < nPadding; i++) padded.push(0);
break;
default:
throw new OperationError(`Unknown padding type: ${padding}`);
}
return padded;
}
/**
* Remove padding from message
* @param {number[]} message
* @param {string} padding
* @returns {number[]}
*/
function removePadding(message, padding) {
if (message.length === 0) return message;
switch (padding) {
case "NO":
case "ZERO":
case "RANDOM":
return message;
case "PKCS5": {
const padByte = message[message.length - 1];
if (padByte > 0 && padByte <= BLOCK_SIZE) {
for (let i = 0; i < padByte; i++) {
if (message[message.length - 1 - i] !== padByte) {
throw new OperationError("Invalid PKCS#5 padding.");
}
}
return message.slice(0, message.length - padByte);
}
throw new OperationError("Invalid PKCS#5 padding.");
}
case "BIT": {
for (let i = message.length - 1; i >= 0; i--) {
if (message[i] === 0x80) return message.slice(0, i);
if (message[i] !== 0) throw new OperationError("Invalid BIT padding.");
}
throw new OperationError("Invalid BIT padding.");
}
default:
throw new OperationError(`Unknown padding type: ${padding}`);
}
}
/**
* Encrypt with block cipher modes
*
* @param {number[]} message - Plaintext bytes
* @param {number[]} key - 16-byte key
* @param {number[]} iv - 8-byte IV (ignored for ECB)
* @param {string} mode - "ECB", "CBC", "CFB", "OFB", "CTR"
* @param {string} padding - "PKCS5", "NO", "ZERO", "RANDOM", "BIT"
* @param {Function} encryptBlockFn - Block encrypt function
* @returns {number[]} - Ciphertext bytes
*/
function encryptWithMode(message, key, iv, mode, padding, encryptBlockFn) {
const messageLength = message.length;
if (messageLength === 0) return [];
let data;
if (mode === "ECB" || mode === "CBC") {
data = applyPadding(message, padding);
} else {
data = [...message];
}
const cipherText = [];
switch (mode) {
case "ECB":
for (let i = 0; i < data.length; i += BLOCK_SIZE) {
cipherText.push(...encryptBlockFn(data.slice(i, i + BLOCK_SIZE), key));
}
break;
case "CBC": {
let ivBlock = [...iv];
for (let i = 0; i < data.length; i += BLOCK_SIZE) {
const block = data.slice(i, i + BLOCK_SIZE);
const xored = xorBlocks(block, ivBlock);
ivBlock = encryptBlockFn(xored, key);
cipherText.push(...ivBlock);
}
break;
}
case "CFB": {
let ivBlock = [...iv];
for (let i = 0; i < data.length; i += BLOCK_SIZE) {
const encrypted = encryptBlockFn(ivBlock, key);
const block = data.slice(i, i + BLOCK_SIZE);
while (block.length < BLOCK_SIZE) block.push(0);
ivBlock = xorBlocks(encrypted, block);
cipherText.push(...ivBlock);
}
return cipherText.slice(0, messageLength);
}
case "OFB": {
let ivBlock = [...iv];
for (let i = 0; i < data.length; i += BLOCK_SIZE) {
ivBlock = encryptBlockFn(ivBlock, key);
const block = data.slice(i, i + BLOCK_SIZE);
while (block.length < BLOCK_SIZE) block.push(0);
cipherText.push(...xorBlocks(ivBlock, block));
}
return cipherText.slice(0, messageLength);
}
case "CTR": {
let counter = [...iv];
for (let i = 0; i < data.length; i += BLOCK_SIZE) {
const encrypted = encryptBlockFn(counter, key);
const block = data.slice(i, i + BLOCK_SIZE);
while (block.length < BLOCK_SIZE) block.push(0);
cipherText.push(...xorBlocks(encrypted, block));
counter = incrementCounter(counter);
}
return cipherText.slice(0, messageLength);
}
default:
throw new OperationError(`Invalid block cipher mode: ${mode}`);
}
return cipherText;
}
/**
* Decrypt with block cipher modes
*
* @param {number[]} cipherText - Ciphertext bytes
* @param {number[]} key - 16-byte key
* @param {number[]} iv - 8-byte IV (ignored for ECB)
* @param {string} mode - "ECB", "CBC", "CFB", "OFB", "CTR"
* @param {string} padding - "PKCS5", "NO", "ZERO", "RANDOM", "BIT"
* @param {Function} encryptBlockFn - Block encrypt function (used for stream modes)
* @param {Function} decryptBlockFn - Block decrypt function (used for ECB/CBC)
* @returns {number[]} - Plaintext bytes
*/
function decryptWithMode(cipherText, key, iv, mode, padding, encryptBlockFn, decryptBlockFn) {
const originalLength = cipherText.length;
if (originalLength === 0) return [];
if (mode === "ECB" || mode === "CBC") {
if ((originalLength % BLOCK_SIZE) !== 0)
throw new OperationError(
`Invalid ciphertext length: ${originalLength} bytes. Must be a multiple of ${BLOCK_SIZE}.`
);
} else {
while ((cipherText.length % BLOCK_SIZE) !== 0)
cipherText.push(0);
}
const plainText = [];
switch (mode) {
case "ECB":
for (let i = 0; i < cipherText.length; i += BLOCK_SIZE) {
plainText.push(...decryptBlockFn(cipherText.slice(i, i + BLOCK_SIZE), key));
}
break;
case "CBC": {
let ivBlock = [...iv];
for (let i = 0; i < cipherText.length; i += BLOCK_SIZE) {
const block = cipherText.slice(i, i + BLOCK_SIZE);
const decrypted = decryptBlockFn(block, key);
plainText.push(...xorBlocks(decrypted, ivBlock));
ivBlock = block;
}
break;
}
case "CFB": {
let ivBlock = [...iv];
for (let i = 0; i < cipherText.length; i += BLOCK_SIZE) {
const encrypted = encryptBlockFn(ivBlock, key);
const block = cipherText.slice(i, i + BLOCK_SIZE);
plainText.push(...xorBlocks(encrypted, block));
ivBlock = block;
}
return plainText.slice(0, originalLength);
}
case "OFB": {
let ivBlock = [...iv];
for (let i = 0; i < cipherText.length; i += BLOCK_SIZE) {
ivBlock = encryptBlockFn(ivBlock, key);
const block = cipherText.slice(i, i + BLOCK_SIZE);
plainText.push(...xorBlocks(ivBlock, block));
}
return plainText.slice(0, originalLength);
}
case "CTR": {
let counter = [...iv];
for (let i = 0; i < cipherText.length; i += BLOCK_SIZE) {
const encrypted = encryptBlockFn(counter, key);
const block = cipherText.slice(i, i + BLOCK_SIZE);
plainText.push(...xorBlocks(encrypted, block));
counter = incrementCounter(counter);
}
return plainText.slice(0, originalLength);
}
default:
throw new OperationError(`Invalid block cipher mode: ${mode}`);
}
if (mode === "ECB" || mode === "CBC") {
return removePadding(plainText, padding);
}
return plainText.slice(0, originalLength);
}
// ==================== PUBLIC API ====================
/**
* Encrypt using TEA cipher
* @param {number[]} message - Plaintext bytes
* @param {number[]} key - 16-byte key
* @param {number[]} iv - 8-byte IV
* @param {string} mode - Block cipher mode
* @param {string} padding - Padding type
* @returns {number[]} - Ciphertext bytes
*/
export function encryptTEA(message, key, iv, mode = "ECB", padding = "PKCS5") {
return encryptWithMode(message, key, iv, mode, padding, teaEncryptBlock);
}
/**
* Decrypt using TEA cipher
* @param {number[]} cipherText - Ciphertext bytes
* @param {number[]} key - 16-byte key
* @param {number[]} iv - 8-byte IV
* @param {string} mode - Block cipher mode
* @param {string} padding - Padding type
* @returns {number[]} - Plaintext bytes
*/
export function decryptTEA(cipherText, key, iv, mode = "ECB", padding = "PKCS5") {
return decryptWithMode(cipherText, key, iv, mode, padding, teaEncryptBlock, teaDecryptBlock);
}
/**
* Encrypt using XTEA cipher
* @param {number[]} message - Plaintext bytes
* @param {number[]} key - 16-byte key
* @param {number[]} iv - 8-byte IV
* @param {string} mode - Block cipher mode
* @param {string} padding - Padding type
* @param {number} rounds - Number of rounds (default 32)
* @returns {number[]} - Ciphertext bytes
*/
export function encryptXTEA(message, key, iv, mode = "ECB", padding = "PKCS5", rounds = 32) {
const encFn = (block, k) => xteaEncryptBlock(block, k, rounds);
return encryptWithMode(message, key, iv, mode, padding, encFn);
}
/**
* Decrypt using XTEA cipher
* @param {number[]} cipherText - Ciphertext bytes
* @param {number[]} key - 16-byte key
* @param {number[]} iv - 8-byte IV
* @param {string} mode - Block cipher mode
* @param {string} padding - Padding type
* @param {number} rounds - Number of rounds (default 32)
* @returns {number[]} - Plaintext bytes
*/
export function decryptXTEA(cipherText, key, iv, mode = "ECB", padding = "PKCS5", rounds = 32) {
const encFn = (block, k) => xteaEncryptBlock(block, k, rounds);
const decFn = (block, k) => xteaDecryptBlock(block, k, rounds);
return decryptWithMode(cipherText, key, iv, mode, padding, encFn, decFn);
}
/** Block size in bytes (exported for operation validation) */
export const TEA_BLOCK_SIZE = BLOCK_SIZE;

608
src/core/lib/Twofish.mjs Normal file
View File

@ -0,0 +1,608 @@
/**
* Complete implementation of Twofish block cipher encryption/decryption with
* ECB, CBC, CFB, OFB, CTR block modes.
*
* Twofish was an AES finalist designed by Bruce Schneier et al.
* Reference: https://www.schneier.com/academic/twofish/
*
* @author Medjedtxm
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
import OperationError from "../errors/OperationError.mjs";
/** Number of rounds */
const NROUNDS = 16;
/** Block size in bytes (128 bits) */
const BLOCKSIZE = 16;
/** Q0 permutation */
const Q0 = [
0xa9, 0x67, 0xb3, 0xe8, 0x04, 0xfd, 0xa3, 0x76, 0x9a, 0x92, 0x80, 0x78, 0xe4, 0xdd, 0xd1, 0x38,
0x0d, 0xc6, 0x35, 0x98, 0x18, 0xf7, 0xec, 0x6c, 0x43, 0x75, 0x37, 0x26, 0xfa, 0x13, 0x94, 0x48,
0xf2, 0xd0, 0x8b, 0x30, 0x84, 0x54, 0xdf, 0x23, 0x19, 0x5b, 0x3d, 0x59, 0xf3, 0xae, 0xa2, 0x82,
0x63, 0x01, 0x83, 0x2e, 0xd9, 0x51, 0x9b, 0x7c, 0xa6, 0xeb, 0xa5, 0xbe, 0x16, 0x0c, 0xe3, 0x61,
0xc0, 0x8c, 0x3a, 0xf5, 0x73, 0x2c, 0x25, 0x0b, 0xbb, 0x4e, 0x89, 0x6b, 0x53, 0x6a, 0xb4, 0xf1,
0xe1, 0xe6, 0xbd, 0x45, 0xe2, 0xf4, 0xb6, 0x66, 0xcc, 0x95, 0x03, 0x56, 0xd4, 0x1c, 0x1e, 0xd7,
0xfb, 0xc3, 0x8e, 0xb5, 0xe9, 0xcf, 0xbf, 0xba, 0xea, 0x77, 0x39, 0xaf, 0x33, 0xc9, 0x62, 0x71,
0x81, 0x79, 0x09, 0xad, 0x24, 0xcd, 0xf9, 0xd8, 0xe5, 0xc5, 0xb9, 0x4d, 0x44, 0x08, 0x86, 0xe7,
0xa1, 0x1d, 0xaa, 0xed, 0x06, 0x70, 0xb2, 0xd2, 0x41, 0x7b, 0xa0, 0x11, 0x31, 0xc2, 0x27, 0x90,
0x20, 0xf6, 0x60, 0xff, 0x96, 0x5c, 0xb1, 0xab, 0x9e, 0x9c, 0x52, 0x1b, 0x5f, 0x93, 0x0a, 0xef,
0x91, 0x85, 0x49, 0xee, 0x2d, 0x4f, 0x8f, 0x3b, 0x47, 0x87, 0x6d, 0x46, 0xd6, 0x3e, 0x69, 0x64,
0x2a, 0xce, 0xcb, 0x2f, 0xfc, 0x97, 0x05, 0x7a, 0xac, 0x7f, 0xd5, 0x1a, 0x4b, 0x0e, 0xa7, 0x5a,
0x28, 0x14, 0x3f, 0x29, 0x88, 0x3c, 0x4c, 0x02, 0xb8, 0xda, 0xb0, 0x17, 0x55, 0x1f, 0x8a, 0x7d,
0x57, 0xc7, 0x8d, 0x74, 0xb7, 0xc4, 0x9f, 0x72, 0x7e, 0x15, 0x22, 0x12, 0x58, 0x07, 0x99, 0x34,
0x6e, 0x50, 0xde, 0x68, 0x65, 0xbc, 0xdb, 0xf8, 0xc8, 0xa8, 0x2b, 0x40, 0xdc, 0xfe, 0x32, 0xa4,
0xca, 0x10, 0x21, 0xf0, 0xd3, 0x5d, 0x0f, 0x00, 0x6f, 0x9d, 0x36, 0x42, 0x4a, 0x5e, 0xc1, 0xe0
];
/** Q1 permutation */
const Q1 = [
0x75, 0xf3, 0xc6, 0xf4, 0xdb, 0x7b, 0xfb, 0xc8, 0x4a, 0xd3, 0xe6, 0x6b, 0x45, 0x7d, 0xe8, 0x4b,
0xd6, 0x32, 0xd8, 0xfd, 0x37, 0x71, 0xf1, 0xe1, 0x30, 0x0f, 0xf8, 0x1b, 0x87, 0xfa, 0x06, 0x3f,
0x5e, 0xba, 0xae, 0x5b, 0x8a, 0x00, 0xbc, 0x9d, 0x6d, 0xc1, 0xb1, 0x0e, 0x80, 0x5d, 0xd2, 0xd5,
0xa0, 0x84, 0x07, 0x14, 0xb5, 0x90, 0x2c, 0xa3, 0xb2, 0x73, 0x4c, 0x54, 0x92, 0x74, 0x36, 0x51,
0x38, 0xb0, 0xbd, 0x5a, 0xfc, 0x60, 0x62, 0x96, 0x6c, 0x42, 0xf7, 0x10, 0x7c, 0x28, 0x27, 0x8c,
0x13, 0x95, 0x9c, 0xc7, 0x24, 0x46, 0x3b, 0x70, 0xca, 0xe3, 0x85, 0xcb, 0x11, 0xd0, 0x93, 0xb8,
0xa6, 0x83, 0x20, 0xff, 0x9f, 0x77, 0xc3, 0xcc, 0x03, 0x6f, 0x08, 0xbf, 0x40, 0xe7, 0x2b, 0xe2,
0x79, 0x0c, 0xaa, 0x82, 0x41, 0x3a, 0xea, 0xb9, 0xe4, 0x9a, 0xa4, 0x97, 0x7e, 0xda, 0x7a, 0x17,
0x66, 0x94, 0xa1, 0x1d, 0x3d, 0xf0, 0xde, 0xb3, 0x0b, 0x72, 0xa7, 0x1c, 0xef, 0xd1, 0x53, 0x3e,
0x8f, 0x33, 0x26, 0x5f, 0xec, 0x76, 0x2a, 0x49, 0x81, 0x88, 0xee, 0x21, 0xc4, 0x1a, 0xeb, 0xd9,
0xc5, 0x39, 0x99, 0xcd, 0xad, 0x31, 0x8b, 0x01, 0x18, 0x23, 0xdd, 0x1f, 0x4e, 0x2d, 0xf9, 0x48,
0x4f, 0xf2, 0x65, 0x8e, 0x78, 0x5c, 0x58, 0x19, 0x8d, 0xe5, 0x98, 0x57, 0x67, 0x7f, 0x05, 0x64,
0xaf, 0x63, 0xb6, 0xfe, 0xf5, 0xb7, 0x3c, 0xa5, 0xce, 0xe9, 0x68, 0x44, 0xe0, 0x4d, 0x43, 0x69,
0x29, 0x2e, 0xac, 0x15, 0x59, 0xa8, 0x0a, 0x9e, 0x6e, 0x47, 0xdf, 0x34, 0x35, 0x6a, 0xcf, 0xdc,
0x22, 0xc9, 0xc0, 0x9b, 0x89, 0xd4, 0xed, 0xab, 0x12, 0xa2, 0x0d, 0x52, 0xbb, 0x02, 0x2f, 0xa9,
0xd7, 0x61, 0x1e, 0xb4, 0x50, 0x04, 0xf6, 0xc2, 0x16, 0x25, 0x86, 0x56, 0x55, 0x09, 0xbe, 0x91
];
/** Reed-Solomon matrix for key schedule */
const RS = [
[0x01, 0xA4, 0x55, 0x87, 0x5A, 0x58, 0xDB, 0x9E],
[0xA4, 0x56, 0x82, 0xF3, 0x1E, 0xC6, 0x68, 0xE5],
[0x02, 0xA1, 0xFC, 0xC1, 0x47, 0xAE, 0x3D, 0x19],
[0xA4, 0x55, 0x87, 0x5A, 0x58, 0xDB, 0x9E, 0x03]
];
/**
* Galois Field multiplication in GF(2^8) with polynomial 0x169
*/
function gfMult(a, b, poly) {
let result = 0;
while (b) {
if (b & 1) result ^= a;
a <<= 1;
if (a & 0x100) a ^= poly;
b >>>= 1;
}
return result & 0xFF;
}
/**
* MDS multiplication
*/
function mdsMultiply(x) {
const b0 = x & 0xFF;
const b1 = (x >>> 8) & 0xFF;
const b2 = (x >>> 16) & 0xFF;
const b3 = (x >>> 24) & 0xFF;
// MDS matrix multiplication in GF(2^8) with polynomial 0x169
const r0 = gfMult(b0, 0x01, 0x169) ^ gfMult(b1, 0xEF, 0x169) ^ gfMult(b2, 0x5B, 0x169) ^ gfMult(b3, 0x5B, 0x169);
const r1 = gfMult(b0, 0x5B, 0x169) ^ gfMult(b1, 0xEF, 0x169) ^ gfMult(b2, 0xEF, 0x169) ^ gfMult(b3, 0x01, 0x169);
const r2 = gfMult(b0, 0xEF, 0x169) ^ gfMult(b1, 0x5B, 0x169) ^ gfMult(b2, 0x01, 0x169) ^ gfMult(b3, 0xEF, 0x169);
const r3 = gfMult(b0, 0xEF, 0x169) ^ gfMult(b1, 0x01, 0x169) ^ gfMult(b2, 0xEF, 0x169) ^ gfMult(b3, 0x5B, 0x169);
return (r3 << 24) | (r2 << 16) | (r1 << 8) | r0;
}
/**
* Reed-Solomon multiplication for key schedule
*/
function rsMultiply(key8) {
let result = 0;
for (let i = 0; i < 4; i++) {
let x = 0;
for (let j = 0; j < 8; j++) {
x ^= gfMult(RS[i][j], key8[j], 0x14D);
}
result |= x << (i * 8);
}
return result;
}
/**
* Apply h function (the main keyed permutation)
*/
function h(x, L, k) {
const y = new Array(4);
y[0] = x & 0xFF;
y[1] = (x >>> 8) & 0xFF;
y[2] = (x >>> 16) & 0xFF;
y[3] = (x >>> 24) & 0xFF;
if (k === 4) {
y[0] = Q1[y[0]] ^ (L[3] & 0xFF);
y[1] = Q0[y[1]] ^ ((L[3] >>> 8) & 0xFF);
y[2] = Q0[y[2]] ^ ((L[3] >>> 16) & 0xFF);
y[3] = Q1[y[3]] ^ ((L[3] >>> 24) & 0xFF);
}
if (k >= 3) {
y[0] = Q1[y[0]] ^ (L[2] & 0xFF);
y[1] = Q1[y[1]] ^ ((L[2] >>> 8) & 0xFF);
y[2] = Q0[y[2]] ^ ((L[2] >>> 16) & 0xFF);
y[3] = Q0[y[3]] ^ ((L[2] >>> 24) & 0xFF);
}
// Always do k >= 2
y[0] = Q0[Q0[y[0]] ^ (L[1] & 0xFF)] ^ (L[0] & 0xFF);
y[1] = Q0[Q1[y[1]] ^ ((L[1] >>> 8) & 0xFF)] ^ ((L[0] >>> 8) & 0xFF);
y[2] = Q1[Q0[y[2]] ^ ((L[1] >>> 16) & 0xFF)] ^ ((L[0] >>> 16) & 0xFF);
y[3] = Q1[Q1[y[3]] ^ ((L[1] >>> 24) & 0xFF)] ^ ((L[0] >>> 24) & 0xFF);
// Final q-box lookup
y[0] = Q1[y[0]];
y[1] = Q0[y[1]];
y[2] = Q1[y[2]];
y[3] = Q0[y[3]];
return mdsMultiply((y[3] << 24) | (y[2] << 16) | (y[1] << 8) | y[0]);
}
/**
* Rotate left 32-bit
*/
function ROL(x, n) {
return ((x << n) | (x >>> (32 - n))) >>> 0;
}
/**
* Rotate right 32-bit
*/
function ROR(x, n) {
return ((x >>> n) | (x << (32 - n))) >>> 0;
}
/**
* Generate subkeys from the key
*/
function generateSubkeys(key) {
const keyLen = key.length;
const k = keyLen / 8; // 2, 3, or 4
// Split key into Me (even words) and Mo (odd words)
const Me = new Array(k);
const Mo = new Array(k);
for (let i = 0; i < k; i++) {
const offset = i * 8;
Me[i] = (key[offset]) | (key[offset + 1] << 8) |
(key[offset + 2] << 16) | (key[offset + 3] << 24);
Mo[i] = (key[offset + 4]) | (key[offset + 5] << 8) |
(key[offset + 6] << 16) | (key[offset + 7] << 24);
}
// Generate S-box keys using Reed-Solomon
const S = new Array(k);
for (let i = 0; i < k; i++) {
const offset = (k - 1 - i) * 8;
S[i] = rsMultiply(key.slice(offset, offset + 8));
}
// Generate round subkeys
const subkeys = new Array(40);
const rho = 0x01010101;
for (let i = 0; i < 20; i++) {
const A = h(2 * i * rho, Me, k);
const B = ROL(h((2 * i + 1) * rho, Mo, k), 8);
subkeys[2 * i] = (A + B) >>> 0;
subkeys[2 * i + 1] = ROL((A + 2 * B) >>> 0, 9);
}
return { subkeys, S, k };
}
/**
* g function using precomputed S-box keys
*/
function g(x, S, k) {
return h(x, S, k);
}
/**
* Encrypt a single 128-bit block
*/
function encryptBlock(block, keyData) {
const { subkeys, S, k } = keyData;
// Split block into 4 words (little-endian)
let R0 = (block[0]) | (block[1] << 8) | (block[2] << 16) | (block[3] << 24);
let R1 = (block[4]) | (block[5] << 8) | (block[6] << 16) | (block[7] << 24);
let R2 = (block[8]) | (block[9] << 8) | (block[10] << 16) | (block[11] << 24);
let R3 = (block[12]) | (block[13] << 8) | (block[14] << 16) | (block[15] << 24);
// Input whitening
R0 ^= subkeys[0];
R1 ^= subkeys[1];
R2 ^= subkeys[2];
R3 ^= subkeys[3];
// 16 rounds
for (let r = 0; r < NROUNDS; r += 2) {
let T0 = g(R0, S, k);
let T1 = g(ROL(R1, 8), S, k);
R2 = ROR(R2 ^ ((T0 + T1 + subkeys[8 + 2 * r]) >>> 0), 1);
R3 = ROL(R3, 1) ^ ((T0 + 2 * T1 + subkeys[9 + 2 * r]) >>> 0);
T0 = g(R2, S, k);
T1 = g(ROL(R3, 8), S, k);
R0 = ROR(R0 ^ ((T0 + T1 + subkeys[8 + 2 * r + 2]) >>> 0), 1);
R1 = ROL(R1, 1) ^ ((T0 + 2 * T1 + subkeys[9 + 2 * r + 2]) >>> 0);
}
// Output whitening (with undo of last swap)
R2 ^= subkeys[4];
R3 ^= subkeys[5];
R0 ^= subkeys[6];
R1 ^= subkeys[7];
// Convert back to bytes (little-endian)
return [
R2 & 0xFF, (R2 >>> 8) & 0xFF, (R2 >>> 16) & 0xFF, (R2 >>> 24) & 0xFF,
R3 & 0xFF, (R3 >>> 8) & 0xFF, (R3 >>> 16) & 0xFF, (R3 >>> 24) & 0xFF,
R0 & 0xFF, (R0 >>> 8) & 0xFF, (R0 >>> 16) & 0xFF, (R0 >>> 24) & 0xFF,
R1 & 0xFF, (R1 >>> 8) & 0xFF, (R1 >>> 16) & 0xFF, (R1 >>> 24) & 0xFF
];
}
/**
* Decrypt a single 128-bit block
*/
function decryptBlock(block, keyData) {
const { subkeys, S, k } = keyData;
// Split block into 4 words (little-endian)
let R0 = (block[0]) | (block[1] << 8) | (block[2] << 16) | (block[3] << 24);
let R1 = (block[4]) | (block[5] << 8) | (block[6] << 16) | (block[7] << 24);
let R2 = (block[8]) | (block[9] << 8) | (block[10] << 16) | (block[11] << 24);
let R3 = (block[12]) | (block[13] << 8) | (block[14] << 16) | (block[15] << 24);
// Input whitening (reverse of output whitening)
R0 ^= subkeys[4];
R1 ^= subkeys[5];
R2 ^= subkeys[6];
R3 ^= subkeys[7];
// 16 rounds in reverse
for (let r = NROUNDS - 2; r >= 0; r -= 2) {
let T0 = g(R0, S, k);
let T1 = g(ROL(R1, 8), S, k);
R2 = ROL(R2, 1) ^ ((T0 + T1 + subkeys[8 + 2 * r + 2]) >>> 0);
R3 = ROR(R3 ^ ((T0 + 2 * T1 + subkeys[9 + 2 * r + 2]) >>> 0), 1);
T0 = g(R2, S, k);
T1 = g(ROL(R3, 8), S, k);
R0 = ROL(R0, 1) ^ ((T0 + T1 + subkeys[8 + 2 * r]) >>> 0);
R1 = ROR(R1 ^ ((T0 + 2 * T1 + subkeys[9 + 2 * r]) >>> 0), 1);
}
// Output whitening (reverse of input whitening)
R2 ^= subkeys[0];
R3 ^= subkeys[1];
R0 ^= subkeys[2];
R1 ^= subkeys[3];
// Convert back to bytes (little-endian)
return [
R2 & 0xFF, (R2 >>> 8) & 0xFF, (R2 >>> 16) & 0xFF, (R2 >>> 24) & 0xFF,
R3 & 0xFF, (R3 >>> 8) & 0xFF, (R3 >>> 16) & 0xFF, (R3 >>> 24) & 0xFF,
R0 & 0xFF, (R0 >>> 8) & 0xFF, (R0 >>> 16) & 0xFF, (R0 >>> 24) & 0xFF,
R1 & 0xFF, (R1 >>> 8) & 0xFF, (R1 >>> 16) & 0xFF, (R1 >>> 24) & 0xFF
];
}
/**
* XOR two 16-byte blocks
*/
function xorBlocks(a, b) {
const result = new Array(16);
for (let i = 0; i < 16; i++) {
result[i] = a[i] ^ b[i];
}
return result;
}
/**
* Increment counter (little-endian)
*/
function incrementCounter(counter) {
const result = [...counter];
for (let i = 0; i < 16; i++) {
result[i]++;
if (result[i] <= 255) break;
result[i] = 0;
}
return result;
}
/**
* Apply padding to message
* @param {number[]} message - Original message
* @param {string} padding - Padding type ("NO", "PKCS5", "ZERO", "RANDOM", "BIT")
* @param {number} blockSize - Block size in bytes
* @returns {number[]} - Padded message
*/
function applyPadding(message, padding, blockSize) {
const remainder = message.length % blockSize;
let nPadding = remainder === 0 ? 0 : blockSize - remainder;
// For PKCS5, always add at least one byte (full block if already aligned)
if (padding === "PKCS5" && remainder === 0) {
nPadding = blockSize;
}
if (nPadding === 0) return [...message];
const paddedMessage = [...message];
switch (padding) {
case "NO":
throw new OperationError(`No padding requested but input is not a ${blockSize}-byte multiple.`);
case "PKCS5":
for (let i = 0; i < nPadding; i++) {
paddedMessage.push(nPadding);
}
break;
case "ZERO":
for (let i = 0; i < nPadding; i++) {
paddedMessage.push(0);
}
break;
case "RANDOM":
for (let i = 0; i < nPadding; i++) {
paddedMessage.push(Math.floor(Math.random() * 256));
}
break;
case "BIT":
paddedMessage.push(0x80);
for (let i = 1; i < nPadding; i++) {
paddedMessage.push(0);
}
break;
default:
throw new OperationError(`Unknown padding type: ${padding}`);
}
return paddedMessage;
}
/**
* Remove padding from message
* @param {number[]} message - Padded message
* @param {string} padding - Padding type ("NO", "PKCS5", "ZERO", "RANDOM", "BIT")
* @param {number} blockSize - Block size in bytes
* @returns {number[]} - Unpadded message
*/
function removePadding(message, padding, blockSize) {
if (message.length === 0) return message;
switch (padding) {
case "NO":
case "ZERO":
case "RANDOM":
// These padding types cannot be reliably removed
return message;
case "PKCS5": {
const padByte = message[message.length - 1];
if (padByte > 0 && padByte <= blockSize) {
// Verify padding
for (let i = 0; i < padByte; i++) {
if (message[message.length - 1 - i] !== padByte) {
throw new OperationError("Invalid PKCS#5 padding.");
}
}
return message.slice(0, message.length - padByte);
}
throw new OperationError("Invalid PKCS#5 padding.");
}
case "BIT": {
// Find 0x80 byte working backwards, skipping zeros
for (let i = message.length - 1; i >= 0; i--) {
if (message[i] === 0x80) {
return message.slice(0, i);
} else if (message[i] !== 0) {
throw new OperationError("Invalid BIT padding.");
}
}
throw new OperationError("Invalid BIT padding.");
}
default:
throw new OperationError(`Unknown padding type: ${padding}`);
}
}
/**
* Encrypt using Twofish cipher with specified block mode
*
* @param {number[]} message - Plaintext as byte array
* @param {number[]} key - Key (16, 24, or 32 bytes)
* @param {number[]} iv - IV (16 bytes, not used for ECB)
* @param {string} mode - Block cipher mode ("ECB", "CBC", "CFB", "OFB", "CTR")
* @param {string} padding - Padding type ("NO", "PKCS5", "ZERO", "RANDOM", "BIT")
* @returns {number[]} - Ciphertext as byte array
*/
export function encryptTwofish(message, key, iv, mode = "ECB", padding = "PKCS5") {
const messageLength = message.length;
if (messageLength === 0) return [];
const keyData = generateSubkeys(key);
// Apply padding for ECB/CBC modes
let paddedMessage;
if (mode === "ECB" || mode === "CBC") {
paddedMessage = applyPadding(message, padding, BLOCKSIZE);
} else {
// Stream modes (CFB, OFB, CTR) don't need padding
paddedMessage = [...message];
}
const cipherText = [];
switch (mode) {
case "ECB":
for (let i = 0; i < paddedMessage.length; i += BLOCKSIZE) {
const block = paddedMessage.slice(i, i + BLOCKSIZE);
cipherText.push(...encryptBlock(block, keyData));
}
break;
case "CBC": {
let ivBlock = [...iv];
for (let i = 0; i < paddedMessage.length; i += BLOCKSIZE) {
const block = paddedMessage.slice(i, i + BLOCKSIZE);
const xored = xorBlocks(block, ivBlock);
ivBlock = encryptBlock(xored, keyData);
cipherText.push(...ivBlock);
}
break;
}
case "CFB": {
let ivBlock = [...iv];
for (let i = 0; i < paddedMessage.length; i += BLOCKSIZE) {
const encrypted = encryptBlock(ivBlock, keyData);
const block = paddedMessage.slice(i, i + BLOCKSIZE);
ivBlock = xorBlocks(encrypted, block);
cipherText.push(...ivBlock);
}
return cipherText.slice(0, messageLength);
}
case "OFB": {
let ivBlock = [...iv];
for (let i = 0; i < paddedMessage.length; i += BLOCKSIZE) {
ivBlock = encryptBlock(ivBlock, keyData);
const block = paddedMessage.slice(i, i + BLOCKSIZE);
cipherText.push(...xorBlocks(ivBlock, block));
}
return cipherText.slice(0, messageLength);
}
case "CTR": {
let counter = [...iv];
for (let i = 0; i < paddedMessage.length; i += BLOCKSIZE) {
const encrypted = encryptBlock(counter, keyData);
const block = paddedMessage.slice(i, i + BLOCKSIZE);
cipherText.push(...xorBlocks(encrypted, block));
counter = incrementCounter(counter);
}
return cipherText.slice(0, messageLength);
}
default:
throw new OperationError(`Invalid block cipher mode: ${mode}`);
}
return cipherText;
}
/**
* Decrypt using Twofish cipher with specified block mode
*
* @param {number[]} cipherText - Ciphertext as byte array
* @param {number[]} key - Key (16, 24, or 32 bytes)
* @param {number[]} iv - IV (16 bytes, not used for ECB)
* @param {string} mode - Block cipher mode ("ECB", "CBC", "CFB", "OFB", "CTR")
* @param {string} padding - Padding type ("NO", "PKCS5", "ZERO", "RANDOM", "BIT")
* @returns {number[]} - Plaintext as byte array
*/
export function decryptTwofish(cipherText, key, iv, mode = "ECB", padding = "PKCS5") {
const originalLength = cipherText.length;
if (originalLength === 0) return [];
const keyData = generateSubkeys(key);
if (mode === "ECB" || mode === "CBC") {
if ((originalLength % BLOCKSIZE) !== 0)
throw new OperationError(`Invalid ciphertext length: ${originalLength} bytes. Must be a multiple of 16.`);
} else {
// Pad for stream modes
while ((cipherText.length % BLOCKSIZE) !== 0)
cipherText.push(0);
}
const plainText = [];
switch (mode) {
case "ECB":
for (let i = 0; i < cipherText.length; i += BLOCKSIZE) {
const block = cipherText.slice(i, i + BLOCKSIZE);
plainText.push(...decryptBlock(block, keyData));
}
break;
case "CBC": {
let ivBlock = [...iv];
for (let i = 0; i < cipherText.length; i += BLOCKSIZE) {
const block = cipherText.slice(i, i + BLOCKSIZE);
const decrypted = decryptBlock(block, keyData);
plainText.push(...xorBlocks(decrypted, ivBlock));
ivBlock = block;
}
break;
}
case "CFB": {
let ivBlock = [...iv];
for (let i = 0; i < cipherText.length; i += BLOCKSIZE) {
const encrypted = encryptBlock(ivBlock, keyData);
const block = cipherText.slice(i, i + BLOCKSIZE);
plainText.push(...xorBlocks(encrypted, block));
ivBlock = block;
}
return plainText.slice(0, originalLength);
}
case "OFB": {
let ivBlock = [...iv];
for (let i = 0; i < cipherText.length; i += BLOCKSIZE) {
ivBlock = encryptBlock(ivBlock, keyData);
const block = cipherText.slice(i, i + BLOCKSIZE);
plainText.push(...xorBlocks(ivBlock, block));
}
return plainText.slice(0, originalLength);
}
case "CTR": {
let counter = [...iv];
for (let i = 0; i < cipherText.length; i += BLOCKSIZE) {
const encrypted = encryptBlock(counter, keyData);
const block = cipherText.slice(i, i + BLOCKSIZE);
plainText.push(...xorBlocks(encrypted, block));
counter = incrementCounter(counter);
}
return plainText.slice(0, originalLength);
}
default:
throw new OperationError(`Invalid block cipher mode: ${mode}`);
}
// Remove padding for ECB/CBC modes
if (mode === "ECB" || mode === "CBC") {
return removePadding(plainText, padding, BLOCKSIZE);
}
return plainText.slice(0, originalLength);
}

View File

@ -39,7 +39,7 @@ class AvroToJSON extends Operation {
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
async run(input, args) {
if (input.byteLength <= 0) {
throw new OperationError("Please provide an input.");
}

View File

@ -47,7 +47,7 @@ class Bzip2Compress extends Operation {
* @param {Object[]} args
* @returns {File}
*/
run(input, args) {
async run(input, args) {
const [blockSize, workFactor] = args;
if (input.byteLength <= 0) {
throw new OperationError("Please provide an input.");

View File

@ -0,0 +1,101 @@
/**
* @author p-leriche [philip.leriche@cantab.net]
* @copyright Crown Copyright 2025
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import { parseBigInt, egcd } from "../lib/BigIntUtils.mjs";
/* ---------- operation class ---------- */
/**
* Extended GCD operation
*/
class ExtendedGCD extends Operation {
/**
* ExtendedGCD constructor
*/
constructor() {
super();
this.name = "Extended GCD";
this.module = "Crypto";
this.description =
"Computes the Extended Euclidean Algorithm for integers <i>a</i> and <i>b</i>.<br><br>" +
"Finds integers <i>x</i> and <i>y</i> (Bezout coefficients) such that:<br>" +
"a*x + b*y = gcd(a, b)<br><br>" +
"This is fundamental to many number theory algorithms including modular inverse, " +
"solving linear Diophantine equations, and cryptographic operations.<br><br>" +
"<b>Input handling:</b> If either <i>a</i> or <i>b</i> is left blank, " +
"its value is taken from the Input field.";
this.infoURL = "https://wikipedia.org/wiki/Extended_Euclidean_algorithm";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
name: "Value a",
type: "string",
value: ""
},
{
name: "Value b",
type: "string",
value: ""
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const [aStr, bStr] = args;
// Trim everything so "" and " " count as empty
const aParam = aStr?.trim();
const bParam = bStr?.trim();
const inputVal = input?.trim();
let a, b;
if (aParam && bParam) {
// Case 1: both values given as parameters
a = aParam;
b = bParam;
} else if (!aParam && bParam) {
// Case 2: a missing - take from input
a = inputVal;
b = bParam;
if (!a) throw new OperationError("Value a must be defined");
} else if (aParam && !bParam) {
// Case 3: b missing - take from input
a = aParam;
b = inputVal;
if (!b) throw new OperationError("Value b must be defined");
} else if (!aParam && !bParam) {
// Case 4: both values missing
throw new OperationError("Values a and b must be defined");
}
const aBI = parseBigInt(a, "Value a");
const bBI = parseBigInt(b, "Value b");
const [g, x, y] = egcd(aBI, bBI);
const gcd = g < 0n ? -g : g;
// Format output string bearing in mind that crypto-grade numbers
// may greatly exceed the line length.
let output = "gcd: " + gcd.toString() + "\n\n";
output += "Bezout coefficients:\n";
output += "x = " + x.toString() + "\n";
output += "y = " + y.toString() + "\n\n";
return output;
}
}
export default ExtendedGCD;

View File

@ -0,0 +1,38 @@
/**
* @author Imantas Lukenskas [imantas@lukenskas.dev]
* @copyright Imantas Lukenskas 2026
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import {fromCobs} from "../lib/COBS.mjs";
/**
* From COBS operation
*/
class FromCOBS extends Operation {
/**
* FromCOBS constructor
*/
constructor() {
super();
this.name = "From COBS";
this.module = "Default";
this.description = "Decodes COBS encoded bytes";
this.infoURL = "https://wikipedia.org/wiki/Consistent_Overhead_Byte_Stuffing";
this.inputType = "byteArray";
this.outputType = "byteArray";
}
/**
* @param {byteArray} input
* @param {Object[]} args
* @returns {byteArray}
*/
run(input, args) {
return fromCobs(input);
}
}
export default FromCOBS;

View File

@ -8,6 +8,11 @@ import Operation from "../Operation.mjs";
import {DELIM_OPTIONS} from "../lib/Delim.mjs";
import {fromDecimal} from "../lib/Decimal.mjs";
/**
* From Decimal delimiters, plus auto-detection.
*/
const FROM_DECIMAL_DELIM_OPTIONS = [...DELIM_OPTIONS, "Auto"];
/**
* From Decimal operation
*/
@ -28,7 +33,7 @@ class FromDecimal extends Operation {
{
"name": "Delimiter",
"type": "option",
"value": DELIM_OPTIONS
"value": FROM_DECIMAL_DELIM_OPTIONS
},
{
"name": "Support signed values",

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,154 @@
/**
* @author p-leriche [philip.leriche@cantab.net]
* @copyright Crown Copyright 2025
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import { modPow } from "../lib/BigIntUtils.mjs";
/* ---------- helper functions ---------- */
/**
* Generate random BigInt with specified bit length
*/
function randBigInt(bits) {
const bytes = Math.ceil(bits / 8);
const a = new Uint8Array(bytes);
crypto.getRandomValues(a);
// Set high bit to ensure correct bit length
a[0] |= 1 << (7 - ((8 * bytes - bits)));
// Set low bit to ensure odd (primes > 2 are odd)
a[bytes - 1] |= 1;
let h = "";
for (const b of a) h += b.toString(16).padStart(2, "0");
return BigInt("0x" + h);
}
/**
* Miller-Rabin primality test
*/
function isProbablePrime(n, rounds) {
if (n < 2n) return false;
if (n === 2n || n === 3n) return true;
if (n % 2n === 0n) return false;
// Write n-1 as 2^r * d
let d = n - 1n;
let r = 0n;
while (d % 2n === 0n) {
d /= 2n;
r++;
}
// Witness loop
for (let i = 0; i < rounds; i++) {
const a = randBigInt(n.toString(2).length - 1) % (n - 3n) + 2n;
let x = modPow(a, d, n);
if (x === 1n || x === n - 1n) continue;
let composite = true;
for (let j = 0n; j < r - 1n; j++) {
x = modPow(x, 2n, n);
if (x === n - 1n) {
composite = false;
break;
}
}
if (composite) return false;
}
return true;
}
/* ---------- operation class ---------- */
/**
* Generate Prime Number operation
*/
class GeneratePrime extends Operation {
/**
* GeneratePrime constructor
*/
constructor() {
super();
this.name = "Pseudo-Random Prime Generator";
this.module = "Crypto";
this.description =
"Generates a random probable prime number of specified bit length using the Miller-Rabin primality test.<br><br>" +
"<b>Primality guarantee:</b><br>" +
"For numbers . 3,317, the result is guaranteed prime (deterministic test).<br>" +
"For larger numbers, uses probabilistic testing:<br>" +
"- <b>Standard (7 rounds):</b> Probability of composite approx 1 in 16,000)<br><br>" +
"- <b>Crypto grade (40 rounds):</b> Probability of composite(approx 1 in 10^24)<br>" +
"Crypto grade is recommended for cryptographic applications (RSA, Diffie-Hellman, etc.).<br><br>" ;
this.infoURL = "https://wikipedia.org/wiki/Miller-Rabin_primality_test";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
name: "Bit length",
type: "number",
value: 512,
min: 2
},
{
name: "Crypto grade",
type: "boolean",
value: false
},
{
name: "Output format",
type: "option",
value: ["Decimal", "Hexadecimal"]
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const [bits, cryptoGrade, outputFormat] = args;
if (bits < 2) {
throw new OperationError("Bit length must be at least 2");
}
if (bits > 4096) {
throw new OperationError("Bit length limited to 4096 bits for performance reasons");
}
const rounds = cryptoGrade ? 40 : 7;
let attempts = 0;
const maxAttempts = 10000;
let n = randBigInt(bits);
while (!isProbablePrime(n, rounds)) {
n = randBigInt(bits);
attempts++;
if (attempts > maxAttempts) {
throw new OperationError(`Failed to generate prime after ${maxAttempts} attempts. Try a different bit length.`);
}
}
// Return only the prime for pipeability
if (outputFormat === "Hexadecimal") {
return "0x" + n.toString(16);
} else {
return n.toString();
}
}
}
export default GeneratePrime;

View File

@ -0,0 +1,62 @@
/**
* @license Apache-2.0
*/
import BigNumber from "bignumber.js";
import Operation from "../Operation.mjs";
import { createNumArray } from "../lib/Arithmetic.mjs";
import { ARITHMETIC_DELIM_OPTIONS } from "../lib/Delim.mjs";
/**
* MOD operation
*/
class MOD extends Operation {
/**
* MOD constructor
*/
constructor() {
super();
this.name = "MOD";
this.module = "Default";
this.description = "Computes the modulo of each number in a list with a given modulus value. Numbers are extracted from the input based on the delimiter, and non-numeric values are ignored.<br><br>e.g. <code>15 4 7</code> with modulus <code>3</code> becomes <code>0 1 1</code>";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": "Modulus",
"type": "number",
"value": 2
},
{
"name": "Delimiter",
"type": "option",
"value": ARITHMETIC_DELIM_OPTIONS,
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const modulus = new BigNumber(args[0]);
const delimiter = args[1];
if (modulus.isZero()) {
throw new Error("Modulus cannot be zero");
}
const numbers = createNumArray(input, delimiter);
const results = numbers.map(num => num.mod(modulus));
return results.join(" ");
}
}
export default MOD;

View File

@ -0,0 +1,107 @@
/**
* @author p-leriche [philip.leriche@cantab.net]
* @copyright Crown Copyright 2025
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import { parseBigInt, egcd } from "../lib/BigIntUtils.mjs";
/* ---------- operation class ---------- */
/**
* Modular Inverse operation
*/
class ModularInverse extends Operation {
/**
* ModularInverse constructor
*/
constructor() {
super();
this.name = "Modular Inverse";
this.module = "Crypto";
this.description =
"Computes the modular multiplicative inverse of <i>a</i> modulo <i>m</i>.<br><br>" +
"Finds <i>x</i> such that a*x = 1 (mod m).<br><br>" +
"<b>Input handling:</b> If either <i>a</i> or <i>m</i> is left blank, " +
"its value is taken from the Input field.";
this.infoURL = "https://wikipedia.org/wiki/Modular_multiplicative_inverse";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
name: "Value (a)",
type: "string",
value: ""
},
{
name: "Modulus (m)",
type: "string",
value: ""
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const [aStr, mStr] = args;
// Trim everything so "" and " " count as empty
const aParam = aStr?.trim();
const mParam = mStr?.trim();
const inputVal = input?.trim();
let a, m;
if (aParam && mParam) {
// Case 1: value and modulus both given as parameters
a = aParam;
m = mParam;
} else if (!aParam && mParam) {
// Case 2: value missing - take from input
a = inputVal;
m = mParam;
if (!a) throw new OperationError("Value (a) must be defined");
} else if (aParam && !mParam) {
// Case 3: modulus missing - take from input
a = aParam;
m = inputVal;
if (!m) throw new OperationError("Modulus (m) must be defined");
} else if (!aParam && !mParam) {
// Case 4: value and modulus both missing
throw new OperationError("Value (a) and Modulus (m) must be defined");
}
const aBI = parseBigInt(a, "Value (a)");
const mBI = parseBigInt(m, "Modulus (m)");
if (mBI <= 0n) {
throw new OperationError("Modulus must be greater than zero");
}
const aNorm = ((aBI % mBI) + mBI) % mBI;
const [g, x] = egcd(aNorm, mBI);
if (g !== 1n && g !== -1n) {
throw new OperationError("Inverse does not exist because gcd(a, m) ≠ 1");
}
let inv = x;
if (g === -1n) inv = -inv;
inv = ((inv % mBI) + mBI) % mBI;
return inv.toString();
}
}
export default ModularInverse;

View File

@ -0,0 +1,94 @@
/**
* @author Medjedtxm
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs";
import OperationError from "../errors/OperationError.mjs";
import { toHex } from "../lib/Hex.mjs";
import { decryptPRESENT } from "../lib/Present.mjs";
/**
* PRESENT Decrypt operation
*/
class PRESENTDecrypt extends Operation {
/**
* PRESENTDecrypt constructor
*/
constructor() {
super();
this.name = "PRESENT Decrypt";
this.module = "Ciphers";
this.description = "PRESENT is an ultra-lightweight block cipher designed for constrained environments such as RFID tags and sensor networks. It operates on 64-bit blocks and supports 80-bit or 128-bit keys with 31 rounds. Standardised in ISO/IEC 29192-2:2019.<br><br>When using CBC mode, the PKCS#7 padding scheme is used.";
this.infoURL = "https://wikipedia.org/wiki/PRESENT_(cipher)";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": "Key",
"type": "toggleString",
"value": "",
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
},
{
"name": "IV",
"type": "toggleString",
"value": "",
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
},
{
"name": "Mode",
"type": "option",
"value": ["CBC", "ECB"]
},
{
"name": "Input",
"type": "option",
"value": ["Hex", "Raw"]
},
{
"name": "Output",
"type": "option",
"value": ["Raw", "Hex"]
},
{
"name": "Padding",
"type": "option",
"value": ["PKCS5", "NO", "ZERO", "RANDOM", "BIT"]
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const key = Utils.convertToByteArray(args[0].string, args[0].option),
iv = Utils.convertToByteArray(args[1].string, args[1].option),
[,, mode, inputType, outputType, padding] = args;
if (key.length !== 10 && key.length !== 16)
throw new OperationError(`Invalid key length: ${key.length} bytes
PRESENT uses a key length of 10 bytes (80 bits) or 16 bytes (128 bits).`);
if (iv.length !== 8 && mode !== "ECB")
throw new OperationError(`Invalid IV length: ${iv.length} bytes
PRESENT uses an IV length of 8 bytes (64 bits).
Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
input = Utils.convertToByteArray(input, inputType);
const output = decryptPRESENT(input, key, iv, mode, padding);
return outputType === "Hex" ? toHex(output, "") : Utils.byteArrayToUtf8(output);
}
}
export default PRESENTDecrypt;

View File

@ -0,0 +1,94 @@
/**
* @author Medjedtxm
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs";
import OperationError from "../errors/OperationError.mjs";
import { toHex } from "../lib/Hex.mjs";
import { encryptPRESENT } from "../lib/Present.mjs";
/**
* PRESENT Encrypt operation
*/
class PRESENTEncrypt extends Operation {
/**
* PRESENTEncrypt constructor
*/
constructor() {
super();
this.name = "PRESENT Encrypt";
this.module = "Ciphers";
this.description = "PRESENT is an ultra-lightweight block cipher designed for constrained environments such as RFID tags and sensor networks. It operates on 64-bit blocks and supports 80-bit or 128-bit keys with 31 rounds. Standardised in ISO/IEC 29192-2:2019.<br><br>When using CBC mode, the PKCS#7 padding scheme is used.";
this.infoURL = "https://wikipedia.org/wiki/PRESENT_(cipher)";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": "Key",
"type": "toggleString",
"value": "",
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
},
{
"name": "IV",
"type": "toggleString",
"value": "",
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
},
{
"name": "Mode",
"type": "option",
"value": ["CBC", "ECB"]
},
{
"name": "Input",
"type": "option",
"value": ["Raw", "Hex"]
},
{
"name": "Output",
"type": "option",
"value": ["Hex", "Raw"]
},
{
"name": "Padding",
"type": "option",
"value": ["PKCS5", "NO", "ZERO", "RANDOM", "BIT"]
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const key = Utils.convertToByteArray(args[0].string, args[0].option),
iv = Utils.convertToByteArray(args[1].string, args[1].option),
[,, mode, inputType, outputType, padding] = args;
if (key.length !== 10 && key.length !== 16)
throw new OperationError(`Invalid key length: ${key.length} bytes
PRESENT uses a key length of 10 bytes (80 bits) or 16 bytes (128 bits).`);
if (iv.length !== 8 && mode !== "ECB")
throw new OperationError(`Invalid IV length: ${iv.length} bytes
PRESENT uses an IV length of 8 bytes (64 bits).
Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
input = Utils.convertToByteArray(input, inputType);
const output = encryptPRESENT(input, key, iv, mode, padding);
return outputType === "Hex" ? toHex(output, "") : Utils.byteArrayToUtf8(output);
}
}
export default PRESENTEncrypt;

View File

@ -0,0 +1,154 @@
/**
* @author p-leriche [philip.leriche@cantab.net]
* @copyright Crown Copyright 2025
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import { modPow } from "../lib/BigIntUtils.mjs";
/* ---------- helper functions ---------- */
/**
* Generate random BigInt with specified bit length
*/
function randBigInt(bits) {
const bytes = Math.ceil(bits / 8);
const a = new Uint8Array(bytes);
crypto.getRandomValues(a);
// Set high bit to ensure correct bit length
a[0] |= 1 << (7 - ((8 * bytes - bits)));
// Set low bit to ensure odd (primes > 2 are odd)
a[bytes - 1] |= 1;
let h = "";
for (const b of a) h += b.toString(16).padStart(2, "0");
return BigInt("0x" + h);
}
/**
* Miller-Rabin primality test
*/
function isProbablePrime(n, rounds) {
if (n < 2n) return false;
if (n === 2n || n === 3n) return true;
if (n % 2n === 0n) return false;
// Write n-1 as 2^r * d
let d = n - 1n;
let r = 0n;
while (d % 2n === 0n) {
d /= 2n;
r++;
}
// Witness loop
for (let i = 0; i < rounds; i++) {
const a = randBigInt(n.toString(2).length - 1) % (n - 3n) + 2n;
let x = modPow(a, d, n);
if (x === 1n || x === n - 1n) continue;
let composite = true;
for (let j = 0n; j < r - 1n; j++) {
x = modPow(x, 2n, n);
if (x === n - 1n) {
composite = false;
break;
}
}
if (composite) return false;
}
return true;
}
/* ---------- operation class ---------- */
/**
* Generate Prime Number operation
*/
class GeneratePrime extends Operation {
/**
* GeneratePrime constructor
*/
constructor() {
super();
this.name = "Pseudo-Random Prime Generator";
this.module = "Crypto";
this.description =
"Generates a random probable prime number of specified bit length using the Miller-Rabin primality test.<br><br>" +
"<b>Primality guarantee:</b><br>" +
"For numbers . 3,317, the result is guaranteed prime (deterministic test).<br>" +
"For larger numbers, uses probabilistic testing:<br>" +
"- <b>Standard (7 rounds):</b> Probability of composite approx 1 in 16,000)<br><br>" +
"- <b>Crypto grade (40 rounds):</b> Probability of composite(approx 1 in 10^24)<br>" +
"Crypto grade is recommended for cryptographic applications (RSA, Diffie-Hellman, etc.).<br><br>" ;
this.infoURL = "https://wikipedia.org/wiki/Miller-Rabin_primality_test";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
name: "Bit length",
type: "number",
value: 512,
min: 2
},
{
name: "Crypto grade",
type: "boolean",
value: false
},
{
name: "Output format",
type: "option",
value: ["Decimal", "Hexadecimal"]
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const [bits, cryptoGrade, outputFormat] = args;
if (bits < 2) {
throw new OperationError("Bit length must be at least 2");
}
if (bits > 4096) {
throw new OperationError("Bit length limited to 4096 bits for performance reasons");
}
const rounds = cryptoGrade ? 40 : 7;
let attempts = 0;
const maxAttempts = 10000;
let n = randBigInt(bits);
while (!isProbablePrime(n, rounds)) {
n = randBigInt(bits);
attempts++;
if (attempts > maxAttempts) {
throw new OperationError(`Failed to generate prime after ${maxAttempts} attempts. Try a different bit length.`);
}
}
// Return only the prime for pipeability
if (outputFormat === "Hexadecimal") {
return "0x" + n.toString(16);
} else {
return n.toString();
}
}
}
export default GeneratePrime;

View File

@ -0,0 +1,98 @@
/**
* @author Medjedtxm
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs";
import OperationError from "../errors/OperationError.mjs";
import { toHex } from "../lib/Hex.mjs";
import { decryptTEA, TEA_BLOCK_SIZE } from "../lib/TEA.mjs";
/**
* TEA Decrypt operation
*/
class TEADecrypt extends Operation {
/**
* TEADecrypt constructor
*/
constructor() {
super();
this.name = "TEA Decrypt";
this.module = "Ciphers";
this.description = "TEA (Tiny Encryption Algorithm) is a block cipher designed by David Wheeler and Roger Needham in 1994. It operates on 64-bit blocks using a 128-bit key and performs 32 cycles (64 Feistel rounds) with the DELTA constant 0x9E3779B9 derived from the golden ratio.<br><br>TEA is notable for its simplicity and compact implementation, making it frequently encountered in malware analysis and CTF challenges. Despite its elegance, TEA has known weaknesses including equivalent keys and susceptibility to related-key attacks, leading to successors XTEA and XXTEA.<br><br><b>Key:</b> Must be exactly 16 bytes (128 bits).<br><br><b>IV:</b> The Initialisation Vector should be 8 bytes (64 bits). If not entered, it will default to null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, the PKCS#5 padding scheme is used.";
this.infoURL = "https://wikipedia.org/wiki/Tiny_Encryption_Algorithm";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": "Key",
"type": "toggleString",
"value": "",
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
},
{
"name": "IV",
"type": "toggleString",
"value": "",
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
},
{
"name": "Mode",
"type": "option",
"value": ["CBC", "CFB", "OFB", "CTR", "ECB"]
},
{
"name": "Input",
"type": "option",
"value": ["Hex", "Raw"]
},
{
"name": "Output",
"type": "option",
"value": ["Raw", "Hex"]
},
{
"name": "Padding",
"type": "option",
"value": ["PKCS5", "NO", "ZERO", "RANDOM", "BIT"]
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const key = Utils.convertToByteArray(args[0].string, args[0].option),
iv = Utils.convertToByteArray(args[1].string, args[1].option),
[,, mode, inputType, outputType, padding] = args;
if (key.length !== 16)
throw new OperationError(`Invalid key length: ${key.length} bytes
TEA requires a key length of 16 bytes (128 bits).
Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
if (iv.length !== TEA_BLOCK_SIZE && iv.length !== 0 && mode !== "ECB")
throw new OperationError(`Invalid IV length: ${iv.length} bytes
TEA uses an IV length of ${TEA_BLOCK_SIZE} bytes (${TEA_BLOCK_SIZE * 8} bits).
Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
// Default IV to null bytes if empty (like AES)
const actualIv = iv.length === 0 ? new Array(TEA_BLOCK_SIZE).fill(0) : iv;
input = Utils.convertToByteArray(input, inputType);
const output = decryptTEA(input, key, actualIv, mode, padding);
return outputType === "Hex" ? toHex(output, "") : Utils.byteArrayToUtf8(output);
}
}
export default TEADecrypt;

View File

@ -0,0 +1,98 @@
/**
* @author Medjedtxm
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs";
import OperationError from "../errors/OperationError.mjs";
import { toHex } from "../lib/Hex.mjs";
import { encryptTEA, TEA_BLOCK_SIZE } from "../lib/TEA.mjs";
/**
* TEA Encrypt operation
*/
class TEAEncrypt extends Operation {
/**
* TEAEncrypt constructor
*/
constructor() {
super();
this.name = "TEA Encrypt";
this.module = "Ciphers";
this.description = "TEA (Tiny Encryption Algorithm) is a block cipher designed by David Wheeler and Roger Needham in 1994. It operates on 64-bit blocks using a 128-bit key and performs 32 cycles (64 Feistel rounds) with the DELTA constant 0x9E3779B9 derived from the golden ratio.<br><br>TEA is notable for its simplicity and compact implementation, making it frequently encountered in malware analysis and CTF challenges. Despite its elegance, TEA has known weaknesses including equivalent keys and susceptibility to related-key attacks, leading to successors XTEA and XXTEA.<br><br><b>Key:</b> Must be exactly 16 bytes (128 bits).<br><br><b>IV:</b> The Initialisation Vector should be 8 bytes (64 bits). If not entered, it will default to null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, the PKCS#5 padding scheme is used.";
this.infoURL = "https://wikipedia.org/wiki/Tiny_Encryption_Algorithm";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": "Key",
"type": "toggleString",
"value": "",
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
},
{
"name": "IV",
"type": "toggleString",
"value": "",
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
},
{
"name": "Mode",
"type": "option",
"value": ["CBC", "CFB", "OFB", "CTR", "ECB"]
},
{
"name": "Input",
"type": "option",
"value": ["Raw", "Hex"]
},
{
"name": "Output",
"type": "option",
"value": ["Hex", "Raw"]
},
{
"name": "Padding",
"type": "option",
"value": ["PKCS5", "NO", "ZERO", "RANDOM", "BIT"]
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const key = Utils.convertToByteArray(args[0].string, args[0].option),
iv = Utils.convertToByteArray(args[1].string, args[1].option),
[,, mode, inputType, outputType, padding] = args;
if (key.length !== 16)
throw new OperationError(`Invalid key length: ${key.length} bytes
TEA requires a key length of 16 bytes (128 bits).
Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
if (iv.length !== TEA_BLOCK_SIZE && iv.length !== 0 && mode !== "ECB")
throw new OperationError(`Invalid IV length: ${iv.length} bytes
TEA uses an IV length of ${TEA_BLOCK_SIZE} bytes (${TEA_BLOCK_SIZE * 8} bits).
Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
// Default IV to null bytes if empty (like AES)
const actualIv = iv.length === 0 ? new Array(TEA_BLOCK_SIZE).fill(0) : iv;
input = Utils.convertToByteArray(input, inputType);
const output = encryptTEA(input, key, actualIv, mode, padding);
return outputType === "Hex" ? toHex(output, "") : Utils.byteArrayToUtf8(output);
}
}
export default TEAEncrypt;

View File

@ -0,0 +1,38 @@
/**
* @author Imantas Lukenskas [imantas@lukenskas.dev]
* @copyright Imantas Lukenskas 2026
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import {toCobs} from "../lib/COBS.mjs";
/**
* To COBS operation
*/
class ToCOBS extends Operation {
/**
* ToCOBS constructor
*/
constructor() {
super();
this.name = "To COBS";
this.module = "Default";
this.description = "Encodes bytes in COBS format";
this.infoURL = "https://wikipedia.org/wiki/Consistent_Overhead_Byte_Stuffing";
this.inputType = "byteArray";
this.outputType = "byteArray";
}
/**
* @param {byteArray} input
* @param {Object[]} args
* @returns {byteArray}
*/
run(input, args) {
return toCobs(input);
}
}
export default ToCOBS;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,94 @@
/**
* @author Medjedtxm
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs";
import OperationError from "../errors/OperationError.mjs";
import { toHex } from "../lib/Hex.mjs";
import { decryptTwofish } from "../lib/Twofish.mjs";
/**
* Twofish Decrypt operation
*/
class TwofishDecrypt extends Operation {
/**
* TwofishDecrypt constructor
*/
constructor() {
super();
this.name = "Twofish Decrypt";
this.module = "Ciphers";
this.description = "Twofish is a symmetric key block cipher designed by Bruce Schneier. It was one of the five AES finalists. Twofish operates on 128-bit blocks and supports key sizes of 128, 192, or 256 bits with 16 rounds of a Feistel network.<br><br>When using CBC or ECB mode, the PKCS#7 padding scheme is used.";
this.infoURL = "https://wikipedia.org/wiki/Twofish";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": "Key",
"type": "toggleString",
"value": "",
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
},
{
"name": "IV",
"type": "toggleString",
"value": "",
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
},
{
"name": "Mode",
"type": "option",
"value": ["CBC", "CFB", "OFB", "CTR", "ECB"]
},
{
"name": "Input",
"type": "option",
"value": ["Hex", "Raw"]
},
{
"name": "Output",
"type": "option",
"value": ["Raw", "Hex"]
},
{
"name": "Padding",
"type": "option",
"value": ["PKCS5", "NO", "ZERO", "RANDOM", "BIT"]
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const key = Utils.convertToByteArray(args[0].string, args[0].option),
iv = Utils.convertToByteArray(args[1].string, args[1].option),
[,, mode, inputType, outputType, padding] = args;
if (key.length !== 16 && key.length !== 24 && key.length !== 32)
throw new OperationError(`Invalid key length: ${key.length} bytes
Twofish uses a key length of 16 bytes (128 bits), 24 bytes (192 bits), or 32 bytes (256 bits).`);
if (iv.length !== 16 && mode !== "ECB")
throw new OperationError(`Invalid IV length: ${iv.length} bytes
Twofish uses an IV length of 16 bytes (128 bits).
Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
input = Utils.convertToByteArray(input, inputType);
const output = decryptTwofish(input, key, iv, mode, padding);
return outputType === "Hex" ? toHex(output, "") : Utils.byteArrayToUtf8(output);
}
}
export default TwofishDecrypt;

View File

@ -0,0 +1,94 @@
/**
* @author Medjedtxm
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs";
import OperationError from "../errors/OperationError.mjs";
import { toHex } from "../lib/Hex.mjs";
import { encryptTwofish } from "../lib/Twofish.mjs";
/**
* Twofish Encrypt operation
*/
class TwofishEncrypt extends Operation {
/**
* TwofishEncrypt constructor
*/
constructor() {
super();
this.name = "Twofish Encrypt";
this.module = "Ciphers";
this.description = "Twofish is a symmetric key block cipher designed by Bruce Schneier. It was one of the five AES finalists. Twofish operates on 128-bit blocks and supports key sizes of 128, 192, or 256 bits with 16 rounds of a Feistel network.<br><br>When using CBC or ECB mode, the PKCS#7 padding scheme is used.";
this.infoURL = "https://wikipedia.org/wiki/Twofish";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": "Key",
"type": "toggleString",
"value": "",
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
},
{
"name": "IV",
"type": "toggleString",
"value": "",
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
},
{
"name": "Mode",
"type": "option",
"value": ["CBC", "CFB", "OFB", "CTR", "ECB"]
},
{
"name": "Input",
"type": "option",
"value": ["Raw", "Hex"]
},
{
"name": "Output",
"type": "option",
"value": ["Hex", "Raw"]
},
{
"name": "Padding",
"type": "option",
"value": ["PKCS5", "NO", "ZERO", "RANDOM", "BIT"]
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const key = Utils.convertToByteArray(args[0].string, args[0].option),
iv = Utils.convertToByteArray(args[1].string, args[1].option),
[,, mode, inputType, outputType, padding] = args;
if (key.length !== 16 && key.length !== 24 && key.length !== 32)
throw new OperationError(`Invalid key length: ${key.length} bytes
Twofish uses a key length of 16 bytes (128 bits), 24 bytes (192 bits), or 32 bytes (256 bits).`);
if (iv.length !== 16 && mode !== "ECB")
throw new OperationError(`Invalid IV length: ${iv.length} bytes
Twofish uses an IV length of 16 bytes (128 bits).
Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
input = Utils.convertToByteArray(input, inputType);
const output = encryptTwofish(input, key, iv, mode, padding);
return outputType === "Hex" ? toHex(output, "") : Utils.byteArrayToUtf8(output);
}
}
export default TwofishEncrypt;

View File

@ -0,0 +1,110 @@
/**
* @author Medjedtxm
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs";
import OperationError from "../errors/OperationError.mjs";
import { toHex } from "../lib/Hex.mjs";
import { decryptXTEA, TEA_BLOCK_SIZE } from "../lib/TEA.mjs";
/**
* XTEA Decrypt operation
*/
class XTEADecrypt extends Operation {
/**
* XTEADecrypt constructor
*/
constructor() {
super();
this.name = "XTEA Decrypt";
this.module = "Ciphers";
this.description = "XTEA (eXtended Tiny Encryption Algorithm) is a block cipher designed by David Wheeler and Roger Needham in 1997 as a successor to TEA, correcting several weaknesses identified in the original algorithm. It operates on 64-bit blocks using a 128-bit key with an improved key schedule that uses sum-dependent key word selection to resist related-key attacks.<br><br>XTEA retains the simplicity and compact implementation of TEA whilst providing significantly improved security. It is frequently encountered in malware analysis and CTF challenges due to its straightforward implementation.<br><br><b>Key:</b> Must be exactly 16 bytes (128 bits).<br><br><b>IV:</b> The Initialisation Vector should be 8 bytes (64 bits). If not entered, it will default to null bytes.<br><br><b>Rounds:</b> The recommended number of rounds is 32 (default). The reference implementation by Wheeler &amp; Needham accepts a configurable round count.<br><br><b>Padding:</b> In CBC and ECB mode, the PKCS#5 padding scheme is used.";
this.infoURL = "https://wikipedia.org/wiki/XTEA";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": "Key",
"type": "toggleString",
"value": "",
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
},
{
"name": "IV",
"type": "toggleString",
"value": "",
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
},
{
"name": "Mode",
"type": "option",
"value": ["CBC", "CFB", "OFB", "CTR", "ECB"]
},
{
"name": "Input",
"type": "option",
"value": ["Hex", "Raw"]
},
{
"name": "Output",
"type": "option",
"value": ["Raw", "Hex"]
},
{
"name": "Padding",
"type": "option",
"value": ["PKCS5", "NO", "ZERO", "RANDOM", "BIT"]
},
{
"name": "Rounds",
"type": "number",
"value": 32,
"min": 1,
"max": 255
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const key = Utils.convertToByteArray(args[0].string, args[0].option),
iv = Utils.convertToByteArray(args[1].string, args[1].option),
[,, mode, inputType, outputType, padding, rounds] = args;
if (key.length !== 16)
throw new OperationError(`Invalid key length: ${key.length} bytes
XTEA requires a key length of 16 bytes (128 bits).
Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
if (iv.length !== TEA_BLOCK_SIZE && iv.length !== 0 && mode !== "ECB")
throw new OperationError(`Invalid IV length: ${iv.length} bytes
XTEA uses an IV length of ${TEA_BLOCK_SIZE} bytes (${TEA_BLOCK_SIZE * 8} bits).
Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
if (!Number.isInteger(rounds) || rounds < 1 || rounds > 255)
throw new OperationError(`Invalid number of rounds: ${rounds}
Rounds must be an integer between 1 and 255. Standard XTEA uses 32 rounds.`);
// Default IV to null bytes if empty (like AES)
const actualIv = iv.length === 0 ? new Array(TEA_BLOCK_SIZE).fill(0) : iv;
input = Utils.convertToByteArray(input, inputType);
const output = decryptXTEA(input, key, actualIv, mode, padding, rounds);
return outputType === "Hex" ? toHex(output, "") : Utils.byteArrayToUtf8(output);
}
}
export default XTEADecrypt;

View File

@ -0,0 +1,110 @@
/**
* @author Medjedtxm
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs";
import OperationError from "../errors/OperationError.mjs";
import { toHex } from "../lib/Hex.mjs";
import { encryptXTEA, TEA_BLOCK_SIZE } from "../lib/TEA.mjs";
/**
* XTEA Encrypt operation
*/
class XTEAEncrypt extends Operation {
/**
* XTEAEncrypt constructor
*/
constructor() {
super();
this.name = "XTEA Encrypt";
this.module = "Ciphers";
this.description = "XTEA (eXtended Tiny Encryption Algorithm) is a block cipher designed by David Wheeler and Roger Needham in 1997 as a successor to TEA, correcting several weaknesses identified in the original algorithm. It operates on 64-bit blocks using a 128-bit key with an improved key schedule that uses sum-dependent key word selection to resist related-key attacks.<br><br>XTEA retains the simplicity and compact implementation of TEA whilst providing significantly improved security. It is frequently encountered in malware analysis and CTF challenges due to its straightforward implementation.<br><br><b>Key:</b> Must be exactly 16 bytes (128 bits).<br><br><b>IV:</b> The Initialisation Vector should be 8 bytes (64 bits). If not entered, it will default to null bytes.<br><br><b>Rounds:</b> The recommended number of rounds is 32 (default). The reference implementation by Wheeler &amp; Needham accepts a configurable round count.<br><br><b>Padding:</b> In CBC and ECB mode, the PKCS#5 padding scheme is used.";
this.infoURL = "https://wikipedia.org/wiki/XTEA";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": "Key",
"type": "toggleString",
"value": "",
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
},
{
"name": "IV",
"type": "toggleString",
"value": "",
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
},
{
"name": "Mode",
"type": "option",
"value": ["CBC", "CFB", "OFB", "CTR", "ECB"]
},
{
"name": "Input",
"type": "option",
"value": ["Raw", "Hex"]
},
{
"name": "Output",
"type": "option",
"value": ["Hex", "Raw"]
},
{
"name": "Padding",
"type": "option",
"value": ["PKCS5", "NO", "ZERO", "RANDOM", "BIT"]
},
{
"name": "Rounds",
"type": "number",
"value": 32,
"min": 1,
"max": 255
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const key = Utils.convertToByteArray(args[0].string, args[0].option),
iv = Utils.convertToByteArray(args[1].string, args[1].option),
[,, mode, inputType, outputType, padding, rounds] = args;
if (key.length !== 16)
throw new OperationError(`Invalid key length: ${key.length} bytes
XTEA requires a key length of 16 bytes (128 bits).
Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
if (iv.length !== TEA_BLOCK_SIZE && iv.length !== 0 && mode !== "ECB")
throw new OperationError(`Invalid IV length: ${iv.length} bytes
XTEA uses an IV length of ${TEA_BLOCK_SIZE} bytes (${TEA_BLOCK_SIZE * 8} bits).
Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
if (!Number.isInteger(rounds) || rounds < 1 || rounds > 255)
throw new OperationError(`Invalid number of rounds: ${rounds}
Rounds must be an integer between 1 and 255. Standard XTEA uses 32 rounds.`);
// Default IV to null bytes if empty (like AES)
const actualIv = iv.length === 0 ? new Array(TEA_BLOCK_SIZE).fill(0) : iv;
input = Utils.convertToByteArray(input, inputType);
const output = encryptXTEA(input, key, actualIv, mode, padding, rounds);
return outputType === "Hex" ? toHex(output, "") : Utils.byteArrayToUtf8(output);
}
}
export default XTEAEncrypt;

2233
src/core/vendor/htmlEntities/entity.json vendored Normal file

File diff suppressed because it is too large Load Diff

14
src/core/vendor/htmlEntities/entity.txt vendored Normal file
View File

@ -0,0 +1,14 @@
entity.json is the WHATWG named character reference set, retrieved verbatim from:
https://html.spec.whatwg.org/entities.json
It is used by src/core/config/scripts/generateHTMLEntities.mjs to generate the
shared HTML entity lookup tables (src/core/lib/HTMLEntities.mjs) consumed by the
"To HTML Entity" and "From HTML Entity" operations.
Source: HTML Standard — 13.5 Named character references
https://html.spec.whatwg.org/multipage/named-characters.html
Copyright and licence
---------------------
Copyright © WHATWG (Apple, Google, Mozilla, Microsoft). This work is licensed under a Creative Commons Attribution 4.0 International License. To the extent portions of it are incorporated into source code, such portions in the source code are licensed under the BSD 3-Clause License instead.

View File

@ -24,6 +24,7 @@ import "./tests/Dish.mjs";
import "./tests/NodeDish.mjs";
import "./tests/Utils.mjs";
import "./tests/Categories.mjs";
import "./tests/ToHTMLEntity.mjs";
import "./tests/lib/BigIntUtils.mjs";
import "./tests/lib/ChartsProtocolPrototypePollution.mjs";

View File

@ -0,0 +1,82 @@
import TestRegister from "../../lib/TestRegister.mjs";
import ToHTMLEntity from "../../../src/core/operations/ToHTMLEntity.mjs";
import FromHTMLEntity from "../../../src/core/operations/FromHTMLEntity.mjs";
import { HTML_ENTITY_LOOKUP, HTML_ENTITY_REVERSE_LOOKUP } from "../../../src/core/lib/HTMLEntities.mjs";
import it from "../assertionHandler.mjs";
import assert from "assert";
import { readFileSync } from "fs";
import { fileURLToPath } from "url";
import path from "path";
// Vendored WHATWG named character reference set (https://html.spec.whatwg.org/entities.json).
const SPEC = JSON.parse(readFileSync(path.join(
path.dirname(fileURLToPath(import.meta.url)),
"../../../src/core/vendor/htmlEntities/entity.json"), "utf8"));
const specByName = {};
for (const [key, val] of Object.entries(SPEC))
if (key.endsWith(";")) specByName[key.slice(1, -1)] = val.codepoints;
TestRegister.addApiTests([
it("To HTML Entity: every named entity in the table is well-formed", () => {
// "Convert all characters" emits an entity for every code point, so a
// correct table yields an unbroken stream of entity tokens. A malformed
// value such as "&nge;;" or "&epsi;," leaves stray characters between
// tokens, which the walk below flags and reports with surrounding context.
let input = "";
for (let cp = 0; cp <= 0xFFFF; cp++) {
if (cp >= 0xD800 && cp <= 0xDFFF) continue; // skip surrogate range
input += String.fromCodePoint(cp);
}
const output = new ToHTMLEntity().run(input, [true, "Named entities"]);
const tokenRe = /&#[0-9]+;|&#x[0-9a-fA-F]+;|&[A-Za-z][A-Za-z0-9]*;/y;
const malformed = [];
let pos = 0;
while (pos < output.length) {
tokenRe.lastIndex = pos;
if (tokenRe.exec(output)) {
pos = tokenRe.lastIndex;
} else {
malformed.push(output.slice(Math.max(0, pos - 12), pos + 12));
pos++;
}
}
assert.deepStrictEqual(malformed, [], `Malformed entity value(s) near: ${JSON.stringify(malformed)}`);
}),
it("HTML Entity: named encoding round-trips through From HTML Entity", () => {
// Because both operations share one lookup table, encoding a character to
// a named entity and decoding it must return the original character for
// every BMP code point: FromHTMLEntity(ToHTMLEntity(x)) === x.
const toOp = new ToHTMLEntity(),
fromOp = new FromHTMLEntity();
const mismatches = [];
for (let cp = 0; cp <= 0xFFFF; cp++) {
if (cp >= 0xD800 && cp <= 0xDFFF) continue; // skip surrogate range
const char = String.fromCodePoint(cp);
const encoded = toOp.run(char, [true, "Named entities"]);
const decoded = fromOp.run(encoded, []);
if (decoded !== char)
mismatches.push(`U+${cp.toString(16).toUpperCase().padStart(4, "0")} -> ${encoded} -> U+${decoded.codePointAt(0).toString(16).toUpperCase()}`);
}
assert.deepStrictEqual(mismatches, [], `Round-trip failed for: ${JSON.stringify(mismatches.slice(0, 20))}`);
}),
it("HTML Entity: every table entry is conformant with the WHATWG spec", () => {
// Both lookup tables must agree with entities.json: every encode name is a
// real spec name mapping to exactly that code point, and every decode name
// maps to the spec code point.
const violations = [];
for (const [cp, name] of Object.entries(HTML_ENTITY_LOOKUP)) {
const spec = specByName[name];
if (!spec || spec.length !== 1 || spec[0] !== Number(cp))
violations.push(`encode ${cp} -> &${name}; (spec: ${spec ? JSON.stringify(spec) : "none"})`);
}
for (const [name, cp] of Object.entries(HTML_ENTITY_REVERSE_LOOKUP)) {
const spec = specByName[name];
if (!spec || spec.length !== 1 || spec[0] !== cp)
violations.push(`decode &${name}; -> ${cp} (spec: ${spec ? JSON.stringify(spec) : "none"})`);
}
assert.deepStrictEqual(violations, [], `Spec violations: ${JSON.stringify(violations.slice(0, 20))}`);
}),
]);

View File

@ -26,4 +26,81 @@ TestRegister.addApiTests([
"\x7e...",
);
}),
it("Utils: should parse normal pretty recipes", () => {
assert.deepStrictEqual(
Utils.parseRecipeConfig("From_Base64('A-Za-z0-9+/=',true)To_Hex('Space')"),
[
{
op: "From Base64",
args: ["A-Za-z0-9+/=", true],
},
{
op: "To Hex",
args: ["Space"],
},
],
);
}),
it("Utils: should parse pretty recipe options", () => {
assert.deepStrictEqual(
Utils.parseRecipeConfig("A(/disabled/breakpoint)"),
[
{
op: "A",
args: [],
disabled: true,
breakpoint: true,
},
],
);
}),
it("Utils: should parse escaped quotes and backslashes in pretty recipes", () => {
assert.deepStrictEqual(
Utils.parseRecipeConfig("A('\\'\\\\')"),
[
{
op: "A",
args: ["'\\"],
},
],
);
}),
it("Utils: should parse large valid quoted pretty recipe arguments", () => {
const value = "x".repeat(10000);
assert.deepStrictEqual(
Utils.parseRecipeConfig(`A('${value}')`),
[
{
op: "A",
args: [value],
},
],
);
}),
it("Utils: should reject malformed pretty recipes with unmatched quotes", () => {
assert.throws(
() => Utils.parseRecipeConfig("A(" + "'".repeat(10000)),
/Invalid recipe/,
);
}),
it("Utils: should reject malformed pretty recipes with malformed parentheses", () => {
assert.throws(
() => Utils.parseRecipeConfig("A("),
/Invalid recipe/,
);
}),
it("Utils: should reject malformed pretty recipes with malformed escapes", () => {
assert.throws(
() => Utils.parseRecipeConfig("A('" + "\\".repeat(10000)),
/Invalid recipe/,
);
}),
]);

View File

@ -264,6 +264,18 @@ Full hash: $2a$10$ODeP1.6fMsb.ENk2ngPUCO7qTGVPyHA9TqDVcyupyed8FjsiF65L6`;
assert.strictEqual(result.toString(), "Fit as a Fiddle");
}),
it("Bzip2 Compress: round-trips through the Node API", async () => {
const compressed = await chef.bzip2Compress("The quick brown fox.");
const result = await chef.bzip2Decompress(compressed);
assert.strictEqual(result.toString(), "The quick brown fox.");
}),
it("Avro to JSON: decodes an object container file through the Node API", async () => {
const avro = chef.fromHex("4f626a0104166176726f2e736368656d6196017b2274797065223a227265636f7264222c226e616d65223a22736d616c6c222c226669656c6473223a5b7b226e616d65223a226e616d65222c2274797065223a22737472696e67227d5d7d146176726f2e636f646563086e756c6c004e0247632e3702e5b75cdab9a62f1541020e0c6d796e616d654e0247632e3702e5b75cdab9a62f1541");
const result = await chef.avroToJSON(avro);
assert.strictEqual(result.toString(), "{\n \"name\": \"myname\"\n}");
}),
it("cartesianProduct: binary string", () => {
const result = cartesianProduct("1:2\\n\\n3:4", {
itemDelimiter: ":",

View File

@ -0,0 +1,476 @@
/**
* @author Imantas Lukenskas [imantas@lukenskas.dev]
* @copyright Imantas Lukenskas 2026
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
// values in "COBS" testcases are taken from here:
// https://en.wikipedia.org/wiki/Consistent_Overhead_Byte_Stuffing
TestRegister.addTests([
{
"name": "To COBS Example #1",
"input": "00",
"expectedOutput": "01 01",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "To COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "To COBS Example #2",
"input": "00 00",
"expectedOutput": "01 01 01",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "To COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "To COBS Example #3",
"input": "00 11 00",
"expectedOutput": "01 02 11 01",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "To COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "To COBS Example #4",
"input": "11 22 00 33",
"expectedOutput": "03 11 22 02 33",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "To COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "To COBS Example #5",
"input": "11 22 33 44",
"expectedOutput": "05 11 22 33 44",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "To COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "To COBS Example #6",
"input": "11 00 00 00",
"expectedOutput": "02 11 01 01 01",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "To COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "To COBS Example #7",
"input": "01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe",
"expectedOutput": "ff 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "To COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "To COBS Example #8",
"input": "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe",
"expectedOutput": "01 ff 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "To COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "To COBS Example #9",
"input": "01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff",
"expectedOutput": "ff 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe 02 ff",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "To COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "To COBS Example #10",
"input": "02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff 00",
"expectedOutput": "ff 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff 01 01",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "To COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "To COBS Example #11",
"input": "03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff 00 01",
"expectedOutput": "fe 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff 02 01",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "To COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "From COBS Example #1",
"input": "01 01",
"expectedOutput": "00",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "From COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "From COBS Example #2",
"input": "01 01 01",
"expectedOutput": "00 00",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "From COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "From COBS Example #3",
"input": "01 02 11 01",
"expectedOutput": "00 11 00",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "From COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "From COBS Example #4",
"input": "03 11 22 02 33",
"expectedOutput": "11 22 00 33",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "From COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "From COBS Example #5",
"input": "05 11 22 33 44",
"expectedOutput": "11 22 33 44",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "From COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "From COBS Example #6",
"input": "02 11 01 01 01",
"expectedOutput": "11 00 00 00",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "From COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "From COBS Example #7",
"input": "ff 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe",
"expectedOutput": "01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "From COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "From COBS Example #8",
"input": "01 ff 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe",
"expectedOutput": "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "From COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "From COBS Example #9",
"input": "ff 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe 02 ff",
"expectedOutput": "01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "From COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "From COBS Example #10",
"input": "ff 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff 01 01",
"expectedOutput": "02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff 00",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "From COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "From COBS Example #11",
"input": "fe 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff 02 01",
"expectedOutput": "03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff 00 01",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "From COBS",
"args": []
},
{
"op": "To Hex",
"args": ["Space"]
}
]
},
{
"name": "From COBS Invalid input #1",
"input": "00 48 45 4C 4C 4F",
"expectedOutput": "Could not decode from COBS: payload must not contain a 0x00 byte",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "From COBS",
"args": []
}
],
},
{
"name": "From COBS Invalid input #2",
"input": "48 45 00 4C 4C 4F",
"expectedOutput": "Could not decode from COBS: payload must not contain a 0x00 byte",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "From COBS",
"args": []
}
],
},
{
"name": "From COBS Invalid input #3",
"input": "48 45 4C 4C 4F 00",
"expectedOutput": "Could not decode from COBS: payload must not contain a 0x00 byte",
"recipeConfig": [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "From COBS",
"args": []
}
],
},
]);

View File

@ -0,0 +1,78 @@
/**
* Extended GCD tests.
*
* @author p-leriche [philip.leriche@cantab.net]
*
* @copyright Crown Copyright 2025
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "Extended GCD: coprime numbers (3, 11)",
input: "",
expectedOutput: "gcd: 1\n\nBezout coefficients:\nx = 4\ny = -1\n\n",
recipeConfig: [
{
op: "Extended GCD",
args: ["3", "11"],
},
],
},
{
name: "Extended GCD: non-coprime numbers (240, 46)",
input: "",
expectedOutput: "gcd: 2\n\nBezout coefficients:\nx = -9\ny = 47\n\n",
recipeConfig: [
{
op: "Extended GCD",
args: ["240", "46"],
},
],
},
{
name: "Extended GCD: with zero (17, 0)",
input: "",
expectedOutput: "gcd: 17\n\nBezout coefficients:\nx = 1\ny = 0\n\n",
recipeConfig: [
{
op: "Extended GCD",
args: ["17", "0"],
},
],
},
{
name: "Extended GCD: hexadecimal input (0xFF, 0x11)",
input: "",
expectedOutput: "gcd: 17\n\nBezout coefficients:\nx = 0\ny = 1\n\n",
recipeConfig: [
{
op: "Extended GCD",
args: ["0xFF", "0x11"],
},
],
},
{
name: "Extended GCD: using input field for value a",
input: "42",
expectedOutput: "gcd: 7\n\nBezout coefficients:\nx = 1\ny = -1\n\n",
recipeConfig: [
{
op: "Extended GCD",
args: ["", "35"],
},
],
},
{
name: "Extended GCD: large numbers",
input: "",
expectedOutput: "gcd: 2\n\nBezout coefficients:\nx = 12703973750415151\ny = -1577756566311408967124629843\n\n",
recipeConfig: [
{
op: "Extended GCD",
args: ["123456789012345678901234567890", "994064509324197316"],
},
],
},
]);

View File

@ -30,4 +30,59 @@ TestRegister.addTests([
},
],
},
{
name: "From Decimal with Auto delimiter (space)",
input: "72 101 108 108 111",
expectedOutput: "Hello",
recipeConfig: [
{
op: "From Decimal",
args: ["Auto", false]
},
],
},
{
name: "From Decimal with Auto delimiter (comma)",
input: "72,101,108,108,111",
expectedOutput: "Hello",
recipeConfig: [
{
op: "From Decimal",
args: ["Auto", false]
},
],
},
{
name: "From Decimal with Auto delimiter (mixed)",
input: "72, 101 : 108; 108\t111",
expectedOutput: "Hello",
recipeConfig: [
{
op: "From Decimal",
args: ["Auto", false]
},
],
},
{
name: "From Decimal with Auto delimiter (newline)",
input: "72\n101\n108\n108\n111",
expectedOutput: "Hello",
recipeConfig: [
{
op: "From Decimal",
args: ["Auto", false]
},
],
},
{
name: "From Decimal with Auto delimiter and signed values",
input: "-130 -140 -152 -151 115 33 0 -1",
expectedOutput: "~this!\u0000\u00ff",
recipeConfig: [
{
op: "From Decimal",
args: ["Auto", true]
},
],
},
]);

View File

@ -0,0 +1,126 @@
/**
* To/From HTML Entity tests.
*
* @author roberson-io [michaelroberson@gmail.com]
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "To HTML Entity: named",
input: "<a href='#'>\"&\"</a>",
expectedOutput: "&lt;a href&equals;&apos;&num;&apos;&gt;&quot;&amp;&quot;&lt;&sol;a&gt;",
recipeConfig: [
{ op: "To HTML Entity", args: [false, "Named entities"] },
],
},
{
// Regression: this value was "&rlhar;;" (stray trailing semicolon) in the
// original byteToEntity table. See issue #2645.
name: "To HTML Entity: malformed value fixed (U+21CC)",
input: "⇌",
expectedOutput: "&rlhar;",
recipeConfig: [
{ op: "To HTML Entity", args: [false, "Named entities"] },
],
},
{
// Regression: U+03F5 emitted "&epsi;," before; the spec name is &epsiv;
// (&epsi; is U+03B5). See issue #2645.
name: "To HTML Entity: spec-conformant name (U+03F5)",
input: "ϵ",
expectedOutput: "&epsiv;",
recipeConfig: [
{ op: "To HTML Entity", args: [false, "Named entities"] },
],
},
{
// Regression: the OHM SIGN previously emitted the non-conformant &ohm;
// (spec &ohm; is U+03A9). It now encodes numerically.
name: "To HTML Entity: non-conformant name dropped (U+2126 ohm sign)",
input: "Ω",
expectedOutput: "&#8486;",
recipeConfig: [
{ op: "To HTML Entity", args: [false, "Named entities"] },
],
},
{
// The FULL BLOCK previously decoded to &block; but never encoded to it.
// Generating both tables from the spec fixes this asymmetry.
name: "To HTML Entity: encode/decode symmetry (U+2588 block)",
input: "█",
expectedOutput: "&block;",
recipeConfig: [
{ op: "To HTML Entity", args: [false, "Named entities"] },
],
},
{
name: "To HTML Entity: numeric, convert all",
input: "A<",
expectedOutput: "&#65;&#60;",
recipeConfig: [
{ op: "To HTML Entity", args: [true, "Numeric entities"] },
],
},
{
name: "To HTML Entity: hex, convert all",
input: "A<",
expectedOutput: "&#x41;&#x3c;",
recipeConfig: [
{ op: "To HTML Entity", args: [true, "Hex entities"] },
],
},
{
name: "From HTML Entity: named",
input: "&lt;a href=&apos;#&apos;&gt;&quot;&amp;&quot;&lt;/a&gt;",
expectedOutput: "<a href='#'>\"&\"</a>",
recipeConfig: [
{ op: "From HTML Entity", args: [] },
],
},
{
// Legacy/alias names still decode, now to the spec code point.
name: "From HTML Entity: alias to spec code point (&ohm;)",
input: "&ohm;",
expectedOutput: "Ω",
recipeConfig: [
{ op: "From HTML Entity", args: [] },
],
},
{
name: "From HTML Entity: decimal numeric entity",
input: "&#65;",
expectedOutput: "A",
recipeConfig: [
{ op: "From HTML Entity", args: [] },
],
},
{
name: "From HTML Entity: hex numeric entity",
input: "&#x41;",
expectedOutput: "A",
recipeConfig: [
{ op: "From HTML Entity", args: [] },
],
},
{
// Unknown entities are passed through unchanged.
name: "From HTML Entity: invalid entity passed through",
input: "a &notreal; b",
expectedOutput: "a &notreal; b",
recipeConfig: [
{ op: "From HTML Entity", args: [] },
],
},
{
name: "HTML Entity: round-trips through both operations",
input: "Hello <World> & \"friends\" — ⇌ █",
expectedOutput: "Hello <World> & \"friends\" — ⇌ █",
recipeConfig: [
{ op: "To HTML Entity", args: [true, "Named entities"] },
{ op: "From HTML Entity", args: [] },
],
},
]);

View File

@ -722,6 +722,39 @@ TestRegister.addTests([
}
]
},
{
name: "HMAC: Decimal key space-delimited matches Latin1 key (fromDecimal Auto delimiter regression)",
input: "Hello, World!",
expectedOutput: "9b641a008211bb0464a10899d5b37a24ab08ffcf839f5e74d17d99f856530957",
recipeConfig: [
{
"op": "HMAC",
"args": [{"option": "Decimal", "string": "65 65"}, "SHA256"]
}
]
},
{
name: "HMAC: Latin1 key matches space-delimited Decimal key (fromDecimal Auto delimiter regression)",
input: "Hello, World!",
expectedOutput: "9b641a008211bb0464a10899d5b37a24ab08ffcf839f5e74d17d99f856530957",
recipeConfig: [
{
"op": "HMAC",
"args": [{"option": "Latin1", "string": "AA"}, "SHA256"]
}
]
},
{
name: "HMAC: Decimal key comma-delimited matches Latin1 key (fromDecimal Auto delimiter regression)",
input: "Hello, World!",
expectedOutput: "9b641a008211bb0464a10899d5b37a24ab08ffcf839f5e74d17d99f856530957",
recipeConfig: [
{
"op": "HMAC",
"args": [{"option": "Decimal", "string": "65,65"}, "SHA256"]
}
]
},
{
name: "MD5: Complex bytes",
input: "10dc10e32010de10d010dc10d810d910d010e12e",

View File

@ -0,0 +1,208 @@
/**
* MOD tests
*
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "MOD: Basic modulo operation",
input: "15 4 7",
expectedOutput: "0 1 1",
recipeConfig: [
{
"op": "MOD",
"args": [3, "Space"]
}
],
},
{
name: "MOD: Single number",
input: "10",
expectedOutput: "1",
recipeConfig: [
{
"op": "MOD",
"args": [3, "Space"]
}
],
},
{
name: "MOD: Comma-separated numbers",
input: "15,8,23,16,5",
expectedOutput: "1 1 2 2 5",
recipeConfig: [
{
"op": "MOD",
"args": [7, "Comma"]
}
],
},
{
name: "MOD: Line feed separated numbers",
input: "25\n13\n44\n7",
expectedOutput: "0 3 4 2",
recipeConfig: [
{
"op": "MOD",
"args": [5, "Line feed"]
}
],
},
{
name: "MOD: Large numbers",
input: "123456789012345 987654321098765",
expectedOutput: "123456789012345 987654321098765",
recipeConfig: [
{
"op": "MOD",
"args": [1234567890123456, "Space"]
}
],
},
{
name: "MOD: Mixed with non-numeric values",
input: "15 abc 4 def 7 xyz 23",
expectedOutput: "0 1 1 2",
recipeConfig: [
{
"op": "MOD",
"args": [3, "Space"]
}
],
},
{
name: "MOD: Decimal numbers",
input: "10.5 15.7 8.2",
expectedOutput: "1.5 0.7 2.2",
recipeConfig: [
{
"op": "MOD",
"args": [3, "Space"]
}
],
},
{
name: "MOD: Negative numbers",
input: "-15 -8 25 -10",
expectedOutput: "0 -2 1 -1",
recipeConfig: [
{
"op": "MOD",
"args": [3, "Space"]
}
],
},
{
name: "MOD: Zero in input",
input: "0 5 10 15 20",
expectedOutput: "0 2 1 0 2",
recipeConfig: [
{
"op": "MOD",
"args": [3, "Space"]
}
],
},
{
name: "MOD: Modulus of 2 (even/odd check)",
input: "1 2 3 4 5 6 7 8 9 10",
expectedOutput: "1 0 1 0 1 0 1 0 1 0",
recipeConfig: [
{
"op": "MOD",
"args": [2, "Space"]
}
],
},
{
name: "MOD: Numbers with extra whitespace",
input: " 15 4 7 ",
expectedOutput: "0 1 1",
recipeConfig: [
{
"op": "MOD",
"args": [3, "Space"]
}
],
},
{
name: "MOD: Empty input",
input: "",
expectedOutput: "",
recipeConfig: [
{
"op": "MOD",
"args": [3, "Space"]
}
],
},
{
name: "MOD: Scientific notation",
input: "1e3 2e2 5e1",
expectedOutput: "1 2 2",
recipeConfig: [
{
"op": "MOD",
"args": [3, "Space"]
}
],
},
{
name: "MOD: Floating point precision",
input: "10.123456789 20.987654321",
expectedOutput: "1.123456789 2.987654321",
recipeConfig: [
{
"op": "MOD",
"args": [3, "Space"]
}
],
},
{
name: "MOD: Zero modulus error",
input: "15 4 7",
expectedError: true,
expectedOutput: "MOD - Modulus cannot be zero",
recipeConfig: [
{
"op": "MOD",
"args": [0, "Space"]
}
],
},
{
name: "MOD: Semi-colon separated numbers",
input: "17;5;8;13",
expectedOutput: "2 0 3 3",
recipeConfig: [
{
"op": "MOD",
"args": [5, "Semi-colon"]
}
],
},
{
name: "MOD: Colon separated numbers",
input: "25:9:14:7",
expectedOutput: "1 1 2 3",
recipeConfig: [
{
"op": "MOD",
"args": [4, "Colon"]
}
],
},
{
name: "MOD: CRLF separated numbers",
input: "30\r\n18\r\n22\r\n11",
expectedOutput: "0 0 4 5",
recipeConfig: [
{
"op": "MOD",
"args": [6, "CRLF"]
}
],
},
]);

View File

@ -0,0 +1,78 @@
/**
* Modular Inverse tests.
*
* @author p-leriche [philip.leriche@cantab.net]
*
* @copyright Crown Copyright 2025
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "Modular Inverse: basic example (3 mod 11)",
input: "",
expectedOutput: "4",
recipeConfig: [
{
op: "Modular Inverse",
args: ["3", "11"],
},
],
},
{
name: "Modular Inverse: another coprime pair (7 mod 26)",
input: "",
expectedOutput: "15",
recipeConfig: [
{
op: "Modular Inverse",
args: ["7", "26"],
},
],
},
{
name: "Modular Inverse: hexadecimal input (0x10 mod 0x11)",
input: "",
expectedOutput: "16",
recipeConfig: [
{
op: "Modular Inverse",
args: ["0x10", "0x11"],
},
],
},
{
name: "Modular Inverse: using input field for value",
input: "5",
expectedOutput: "21",
recipeConfig: [
{
op: "Modular Inverse",
args: ["", "26"],
},
],
},
{
name: "Modular Inverse: using input field for modulus",
input: "17",
expectedOutput: "7",
recipeConfig: [
{
op: "Modular Inverse",
args: ["5", ""],
},
],
},
{
name: "Modular Inverse: large number (RSA-like)",
input: "",
expectedOutput: "934281398294",
recipeConfig: [
{
op: "Modular Inverse",
args: ["65537", "9999999999999"],
},
],
},
]);

View File

@ -0,0 +1,465 @@
/**
* PRESENT cipher tests.
*
* Test vectors from the original PRESENT paper:
* "PRESENT: An Ultra-Lightweight Block Cipher"
* https://link.springer.com/chapter/10.1007/978-3-540-74735-2_31
* https://www.iacr.org/archive/ches2007/47270450/47270450.pdf
*
* Note: PKCS5 padding adds an extra block when input is exactly block-aligned.
* Round-trip tests verify correct encryption/decryption behavior.
*
* @author Medjedtxm
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
// ============================================================
// OFFICIAL TEST VECTORS from the original PRESENT paper:
// "PRESENT: An Ultra-Lightweight Block Cipher" (Bogdanov et al., CHES 2007)
// https://link.springer.com/chapter/10.1007/978-3-540-74735-2_31
// Table 3: Test Vectors
// ============================================================
{
name: "PRESENT Official Vector 1: 80-bit zero key, zero plaintext",
input: "0000000000000000",
expectedOutput: "5579c1387b228445",
recipeConfig: [
{
op: "PRESENT Encrypt",
args: [
{ string: "00000000000000000000", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Hex", "NO"
]
}
]
},
{
name: "PRESENT Official Vector 2: 80-bit all-ones key, zero plaintext",
input: "0000000000000000",
expectedOutput: "e72c46c0f5945049",
recipeConfig: [
{
op: "PRESENT Encrypt",
args: [
{ string: "ffffffffffffffffffff", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Hex", "NO"
]
}
]
},
{
name: "PRESENT Official Vector 3: 80-bit zero key, all-ones plaintext",
input: "ffffffffffffffff",
expectedOutput: "a112ffc72f68417b",
recipeConfig: [
{
op: "PRESENT Encrypt",
args: [
{ string: "00000000000000000000", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Hex", "NO"
]
}
]
},
{
name: "PRESENT Official Vector 4: 80-bit all-ones key, all-ones plaintext",
input: "ffffffffffffffff",
expectedOutput: "3333dcd3213210d2",
recipeConfig: [
{
op: "PRESENT Encrypt",
args: [
{ string: "ffffffffffffffffffff", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Hex", "NO"
]
}
]
},
{
name: "PRESENT Official Vector 5: 128-bit zero key, zero plaintext",
input: "0000000000000000",
expectedOutput: "96db702a2e6900af",
recipeConfig: [
{
op: "PRESENT Encrypt",
args: [
{ string: "00000000000000000000000000000000", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Hex", "NO"
]
}
]
},
{
name: "PRESENT Official Vector 6: 128-bit key (SageMath reference)",
input: "0123456789abcdef",
expectedOutput: "0e9d28685e671dd6",
recipeConfig: [
{
op: "PRESENT Encrypt",
args: [
{ string: "0123456789abcdef0123456789abcdef", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Hex", "NO"
]
}
]
},
// Decrypt verification of official vectors
{
name: "PRESENT Official Vector 1 Decrypt: 80-bit zero key",
input: "5579c1387b228445",
expectedOutput: "0000000000000000",
recipeConfig: [
{
op: "PRESENT Decrypt",
args: [
{ string: "00000000000000000000", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Hex", "NO"
]
}
]
},
{
name: "PRESENT Official Vector 4 Decrypt: 80-bit all-ones key",
input: "3333dcd3213210d2",
expectedOutput: "ffffffffffffffff",
recipeConfig: [
{
op: "PRESENT Decrypt",
args: [
{ string: "ffffffffffffffffffff", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Hex", "NO"
]
}
]
},
{
name: "PRESENT Official Vector 5 Decrypt: 128-bit zero key",
input: "96db702a2e6900af",
expectedOutput: "0000000000000000",
recipeConfig: [
{
op: "PRESENT Decrypt",
args: [
{ string: "00000000000000000000000000000000", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Hex", "NO"
]
}
]
},
{
name: "PRESENT Official Vector 6 Decrypt: 128-bit key (SageMath reference)",
input: "0e9d28685e671dd6",
expectedOutput: "0123456789abcdef",
recipeConfig: [
{
op: "PRESENT Decrypt",
args: [
{ string: "0123456789abcdef0123456789abcdef", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Hex", "NO"
]
}
]
},
// ============================================================
// Round-trip tests - These verify encryption and decryption work correctly
// ============================================================
{
name: "PRESENT Round-trip: ECB 80-bit key, short message",
input: "Hello!!!",
expectedOutput: "Hello!!!",
recipeConfig: [
{
op: "PRESENT Encrypt",
args: [
{ string: "00112233445566778899", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Raw", "Hex", "PKCS5"
]
},
{
op: "PRESENT Decrypt",
args: [
{ string: "00112233445566778899", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Raw", "PKCS5"
]
}
]
},
{
name: "PRESENT Round-trip: CBC 80-bit key, long message",
input: "The quick brown fox jumps over the lazy dog",
expectedOutput: "The quick brown fox jumps over the lazy dog",
recipeConfig: [
{
op: "PRESENT Encrypt",
args: [
{ string: "aabbccddeeff00112233", option: "Hex" },
{ string: "0011223344556677", option: "Hex" },
"CBC", "Raw", "Hex", "PKCS5"
]
},
{
op: "PRESENT Decrypt",
args: [
{ string: "aabbccddeeff00112233", option: "Hex" },
{ string: "0011223344556677", option: "Hex" },
"CBC", "Hex", "Raw", "PKCS5"
]
}
]
},
{
name: "PRESENT Round-trip: ECB 128-bit key",
input: "Testing PRESENT cipher with 128-bit key",
expectedOutput: "Testing PRESENT cipher with 128-bit key",
recipeConfig: [
{
op: "PRESENT Encrypt",
args: [
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Raw", "Hex", "PKCS5"
]
},
{
op: "PRESENT Decrypt",
args: [
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Raw", "PKCS5"
]
}
]
},
{
name: "PRESENT Round-trip: CBC 128-bit key",
input: "PRESENT is an ultra-lightweight block cipher!",
expectedOutput: "PRESENT is an ultra-lightweight block cipher!",
recipeConfig: [
{
op: "PRESENT Encrypt",
args: [
{ string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
{ string: "8877665544332211", option: "Hex" },
"CBC", "Raw", "Hex", "PKCS5"
]
},
{
op: "PRESENT Decrypt",
args: [
{ string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
{ string: "8877665544332211", option: "Hex" },
"CBC", "Hex", "Raw", "PKCS5"
]
}
]
},
{
name: "PRESENT Round-trip: UTF8 key (10 bytes)",
input: "Secret message",
expectedOutput: "Secret message",
recipeConfig: [
{
op: "PRESENT Encrypt",
args: [
{ string: "mypassword", option: "UTF8" },
{ string: "initvect", option: "UTF8" },
"CBC", "Raw", "Hex", "PKCS5"
]
},
{
op: "PRESENT Decrypt",
args: [
{ string: "mypassword", option: "UTF8" },
{ string: "initvect", option: "UTF8" },
"CBC", "Hex", "Raw", "PKCS5"
]
}
]
},
// Encryption consistency tests - verify same input always produces same output
{
name: "PRESENT Encrypt: 80-bit zero key consistency",
input: "TestData",
expectedOutput: "b78cfea5ffcd89f265585a6ce7312131",
recipeConfig: [
{
op: "PRESENT Encrypt",
args: [
{ string: "00000000000000000000", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Raw", "Hex", "PKCS5"
]
}
]
},
{
name: "PRESENT Encrypt: 128-bit zero key consistency",
input: "TestData",
expectedOutput: "e127a24e38de2c36407e794ef5dffefd",
recipeConfig: [
{
op: "PRESENT Encrypt",
args: [
{ string: "00000000000000000000000000000000", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Raw", "Hex", "PKCS5"
]
}
]
},
{
name: "PRESENT Round-trip: Various lengths 1 byte",
input: "A",
expectedOutput: "A",
recipeConfig: [
{
op: "PRESENT Encrypt",
args: [
{ string: "00112233445566778899", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Raw", "Hex", "PKCS5"
]
},
{
op: "PRESENT Decrypt",
args: [
{ string: "00112233445566778899", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Raw", "PKCS5"
]
}
]
},
{
name: "PRESENT Round-trip: Various lengths 7 bytes",
input: "1234567",
expectedOutput: "1234567",
recipeConfig: [
{
op: "PRESENT Encrypt",
args: [
{ string: "00112233445566778899", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Raw", "Hex", "PKCS5"
]
},
{
op: "PRESENT Decrypt",
args: [
{ string: "00112233445566778899", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Raw", "PKCS5"
]
}
]
},
{
name: "PRESENT Round-trip: Various lengths 8 bytes (exact block)",
input: "12345678",
expectedOutput: "12345678",
recipeConfig: [
{
op: "PRESENT Encrypt",
args: [
{ string: "00112233445566778899", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Raw", "Hex", "PKCS5"
]
},
{
op: "PRESENT Decrypt",
args: [
{ string: "00112233445566778899", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Raw", "PKCS5"
]
}
]
},
{
name: "PRESENT Round-trip: Various lengths 9 bytes",
input: "123456789",
expectedOutput: "123456789",
recipeConfig: [
{
op: "PRESENT Encrypt",
args: [
{ string: "00112233445566778899", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Raw", "Hex", "PKCS5"
]
},
{
op: "PRESENT Decrypt",
args: [
{ string: "00112233445566778899", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Raw", "PKCS5"
]
}
]
},
{
name: "PRESENT Round-trip: Various lengths 16 bytes (two blocks)",
input: "1234567890ABCDEF",
expectedOutput: "1234567890ABCDEF",
recipeConfig: [
{
op: "PRESENT Encrypt",
args: [
{ string: "00112233445566778899", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Raw", "Hex", "PKCS5"
]
},
{
op: "PRESENT Decrypt",
args: [
{ string: "00112233445566778899", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Raw", "PKCS5"
]
}
]
},
{
name: "PRESENT Round-trip: Binary data",
input: "\x00\x01\x02\x03\x04\x05\x06\x07",
expectedOutput: "\x00\x01\x02\x03\x04\x05\x06\x07",
recipeConfig: [
{
op: "PRESENT Encrypt",
args: [
{ string: "ffeeddccbbaa99887766", option: "Hex" },
{ string: "0011223344556677", option: "Hex" },
"CBC", "Raw", "Hex", "PKCS5"
]
},
{
op: "PRESENT Decrypt",
args: [
{ string: "ffeeddccbbaa99887766", option: "Hex" },
{ string: "0011223344556677", option: "Hex" },
"CBC", "Hex", "Raw", "PKCS5"
]
}
]
}
]);

View File

@ -0,0 +1,566 @@
/**
* TEA and XTEA cipher tests.
*
* Test vectors sourced from:
* - TEA: https://www.cix.co.uk/~klockstone/teavect.htm (Wheeler & Needham reference)
* - XTEA: https://github.com/golang/crypto/blob/master/xtea/xtea_test.go (Go standard library)
* Bouncy Castle XTEA test vectors (big-endian)
*
* @author Medjedtxm
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
/**
* TEA ECB Tests Official test vectors from Wheeler & Needham
*
* From teavect.htm: TEA uses a fixed 32 cycles (64 Feistel rounds).
* Row 1: plaintext 00000000 00000000, key 00000000 00000000 00000000 00000000
* -> ciphertext 41ea3a0a 94baa940
*/
TestRegister.addTests([
// ==================== TEA ECB TESTS ====================
{
name: "TEA Encrypt: ECB, all-zero key and plaintext",
input: "0000000000000000",
expectedOutput: "41ea3a0a94baa940",
recipeConfig: [
{
"op": "TEA Encrypt",
"args": [
{"option": "Hex", "string": "00000000000000000000000000000000"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Hex", "NO"
]
}
],
},
{
name: "TEA Decrypt: ECB, all-zero key",
input: "41ea3a0a94baa940",
expectedOutput: "0000000000000000",
recipeConfig: [
{
"op": "TEA Decrypt",
"args": [
{"option": "Hex", "string": "00000000000000000000000000000000"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Hex", "NO"
]
}
],
},
{
name: "TEA Encrypt then Decrypt: round-trip ECB",
input: "48656c6c6f212121",
expectedOutput: "48656c6c6f212121",
recipeConfig: [
{
"op": "TEA Encrypt",
"args": [
{"option": "Hex", "string": "0123456789abcdef0123456789abcdef"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Hex", "NO"
]
},
{
"op": "TEA Decrypt",
"args": [
{"option": "Hex", "string": "0123456789abcdef0123456789abcdef"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Hex", "NO"
]
}
],
},
// ==================== TEA CBC TEST ====================
{
name: "TEA Encrypt then Decrypt: round-trip CBC with PKCS5",
input: "Hello TEA cipher!",
expectedOutput: "Hello TEA cipher!",
recipeConfig: [
{
"op": "TEA Encrypt",
"args": [
{"option": "Hex", "string": "0123456789abcdef0123456789abcdef"},
{"option": "Hex", "string": "0000000000000000"},
"CBC", "Raw", "Hex", "PKCS5"
]
},
{
"op": "TEA Decrypt",
"args": [
{"option": "Hex", "string": "0123456789abcdef0123456789abcdef"},
{"option": "Hex", "string": "0000000000000000"},
"CBC", "Hex", "Raw", "PKCS5"
]
}
],
},
// ==================== TEA CTR TEST ====================
{
name: "TEA Encrypt then Decrypt: round-trip CTR",
input: "Short",
expectedOutput: "Short",
recipeConfig: [
{
"op": "TEA Encrypt",
"args": [
{"option": "Hex", "string": "deadbeefdeadbeefdeadbeefdeadbeef"},
{"option": "Hex", "string": "0102030405060708"},
"CTR", "Raw", "Hex", "NO"
]
},
{
"op": "TEA Decrypt",
"args": [
{"option": "Hex", "string": "deadbeefdeadbeefdeadbeefdeadbeef"},
{"option": "Hex", "string": "0102030405060708"},
"CTR", "Hex", "Raw", "NO"
]
}
],
},
// ==================== TEA CFB TEST ====================
{
name: "TEA Encrypt then Decrypt: round-trip CFB",
input: "CFB mode testing with TEA",
expectedOutput: "CFB mode testing with TEA",
recipeConfig: [
{
"op": "TEA Encrypt",
"args": [
{"option": "Hex", "string": "0123456789abcdef0123456789abcdef"},
{"option": "Hex", "string": "aabbccddeeff0011"},
"CFB", "Raw", "Hex", "NO"
]
},
{
"op": "TEA Decrypt",
"args": [
{"option": "Hex", "string": "0123456789abcdef0123456789abcdef"},
{"option": "Hex", "string": "aabbccddeeff0011"},
"CFB", "Hex", "Raw", "NO"
]
}
],
},
// ==================== TEA OFB TEST ====================
{
name: "TEA Encrypt then Decrypt: round-trip OFB",
input: "OFB mode testing with TEA",
expectedOutput: "OFB mode testing with TEA",
recipeConfig: [
{
"op": "TEA Encrypt",
"args": [
{"option": "Hex", "string": "0123456789abcdef0123456789abcdef"},
{"option": "Hex", "string": "1122334455667788"},
"OFB", "Raw", "Hex", "NO"
]
},
{
"op": "TEA Decrypt",
"args": [
{"option": "Hex", "string": "0123456789abcdef0123456789abcdef"},
{"option": "Hex", "string": "1122334455667788"},
"OFB", "Hex", "Raw", "NO"
]
}
],
},
// ==================== XTEA ECB TESTS ====================
// Go standard library + Bouncy Castle test vectors (big-endian)
{
name: "XTEA Encrypt: ECB, sequential key, 'ABCDEFGH'",
input: "4142434445464748",
expectedOutput: "497df3d072612cb5",
recipeConfig: [
{
"op": "XTEA Encrypt",
"args": [
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Hex", "NO", 32
]
}
],
},
{
name: "XTEA Decrypt: ECB, sequential key",
input: "497df3d072612cb5",
expectedOutput: "4142434445464748",
recipeConfig: [
{
"op": "XTEA Decrypt",
"args": [
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Hex", "NO", 32
]
}
],
},
{
name: "XTEA Encrypt: ECB, sequential key, 'AAAAAAAA'",
input: "4141414141414141",
expectedOutput: "e78f2d13744341d8",
recipeConfig: [
{
"op": "XTEA Encrypt",
"args": [
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Hex", "NO", 32
]
}
],
},
{
name: "XTEA Encrypt: ECB, sequential key, plaintext 5a5b6e27",
input: "5a5b6e278948d77f",
expectedOutput: "4141414141414141",
recipeConfig: [
{
"op": "XTEA Encrypt",
"args": [
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Hex", "NO", 32
]
}
],
},
{
name: "XTEA Encrypt: ECB, all-zero key, 'ABCDEFGH'",
input: "4142434445464748",
expectedOutput: "a0390589f8b8efa5",
recipeConfig: [
{
"op": "XTEA Encrypt",
"args": [
{"option": "Hex", "string": "00000000000000000000000000000000"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Hex", "NO", 32
]
}
],
},
{
name: "XTEA Encrypt: ECB, all-zero key, 'AAAAAAAA'",
input: "4141414141414141",
expectedOutput: "ed23375a821a8c2d",
recipeConfig: [
{
"op": "XTEA Encrypt",
"args": [
{"option": "Hex", "string": "00000000000000000000000000000000"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Hex", "NO", 32
]
}
],
},
{
name: "XTEA Encrypt: ECB, all-zero key, all-zero plaintext",
input: "0000000000000000",
expectedOutput: "dee9d4d8f7131ed9",
recipeConfig: [
{
"op": "XTEA Encrypt",
"args": [
{"option": "Hex", "string": "00000000000000000000000000000000"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Hex", "NO", 32
]
}
],
},
{
name: "XTEA Encrypt: ECB, all-zero key, sequential plaintext",
input: "0102030405060708",
expectedOutput: "065c1b8975c6a816",
recipeConfig: [
{
"op": "XTEA Encrypt",
"args": [
{"option": "Hex", "string": "00000000000000000000000000000000"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Hex", "NO", 32
]
}
],
},
{
name: "XTEA Encrypt: ECB, pattern key, all-zero plaintext",
input: "0000000000000000",
expectedOutput: "1ff9a0261ac64264",
recipeConfig: [
{
"op": "XTEA Encrypt",
"args": [
{"option": "Hex", "string": "0123456712345678234567893456789a"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Hex", "NO", 32
]
}
],
},
{
name: "XTEA Encrypt: ECB, pattern key, sequential plaintext",
input: "0102030405060708",
expectedOutput: "8c67155b2ef91ead",
recipeConfig: [
{
"op": "XTEA Encrypt",
"args": [
{"option": "Hex", "string": "0123456712345678234567893456789a"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Hex", "NO", 32
]
}
],
},
{
name: "XTEA Decrypt: ECB, pattern key, sequential ciphertext",
input: "8c67155b2ef91ead",
expectedOutput: "0102030405060708",
recipeConfig: [
{
"op": "XTEA Decrypt",
"args": [
{"option": "Hex", "string": "0123456712345678234567893456789a"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Hex", "NO", 32
]
}
],
},
// ==================== XTEA CBC TEST ====================
{
name: "XTEA Encrypt then Decrypt: round-trip CBC with PKCS5",
input: "Hello XTEA cipher!",
expectedOutput: "Hello XTEA cipher!",
recipeConfig: [
{
"op": "XTEA Encrypt",
"args": [
{"option": "Hex", "string": "0123456789abcdef0123456789abcdef"},
{"option": "Hex", "string": "fedcba9876543210"},
"CBC", "Raw", "Hex", "PKCS5", 32
]
},
{
"op": "XTEA Decrypt",
"args": [
{"option": "Hex", "string": "0123456789abcdef0123456789abcdef"},
{"option": "Hex", "string": "fedcba9876543210"},
"CBC", "Hex", "Raw", "PKCS5", 32
]
}
],
},
// ==================== XTEA OFB TEST ====================
{
name: "XTEA Encrypt then Decrypt: round-trip OFB",
input: "Stream mode test",
expectedOutput: "Stream mode test",
recipeConfig: [
{
"op": "XTEA Encrypt",
"args": [
{"option": "Hex", "string": "deadbeefdeadbeefdeadbeefdeadbeef"},
{"option": "Hex", "string": "0102030405060708"},
"OFB", "Raw", "Hex", "NO", 32
]
},
{
"op": "XTEA Decrypt",
"args": [
{"option": "Hex", "string": "deadbeefdeadbeefdeadbeefdeadbeef"},
{"option": "Hex", "string": "0102030405060708"},
"OFB", "Hex", "Raw", "NO", 32
]
}
],
},
// ==================== XTEA CTR TEST ====================
{
name: "XTEA Encrypt then Decrypt: round-trip CTR",
input: "CTR mode with XTEA",
expectedOutput: "CTR mode with XTEA",
recipeConfig: [
{
"op": "XTEA Encrypt",
"args": [
{"option": "Hex", "string": "deadbeefdeadbeefdeadbeefdeadbeef"},
{"option": "Hex", "string": "0000000000000001"},
"CTR", "Raw", "Hex", "NO", 32
]
},
{
"op": "XTEA Decrypt",
"args": [
{"option": "Hex", "string": "deadbeefdeadbeefdeadbeefdeadbeef"},
{"option": "Hex", "string": "0000000000000001"},
"CTR", "Hex", "Raw", "NO", 32
]
}
],
},
// ==================== XTEA CFB TEST ====================
{
name: "XTEA Encrypt then Decrypt: round-trip CFB",
input: "CFB mode with XTEA cipher",
expectedOutput: "CFB mode with XTEA cipher",
recipeConfig: [
{
"op": "XTEA Encrypt",
"args": [
{"option": "Hex", "string": "0123456789abcdef0123456789abcdef"},
{"option": "Hex", "string": "aabbccddeeff0011"},
"CFB", "Raw", "Hex", "NO", 32
]
},
{
"op": "XTEA Decrypt",
"args": [
{"option": "Hex", "string": "0123456789abcdef0123456789abcdef"},
{"option": "Hex", "string": "aabbccddeeff0011"},
"CFB", "Hex", "Raw", "NO", 32
]
}
],
},
// ==================== XTEA NON-DEFAULT ROUNDS TEST ====================
{
name: "XTEA Encrypt then Decrypt: round-trip ECB with 16 rounds",
input: "4142434445464748",
expectedOutput: "4142434445464748",
recipeConfig: [
{
"op": "XTEA Encrypt",
"args": [
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Hex", "NO", 16
]
},
{
"op": "XTEA Decrypt",
"args": [
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Hex", "NO", 16
]
}
],
},
{
name: "XTEA Encrypt: ECB, 16 rounds differs from 32 rounds",
input: "4142434445464748",
expectedOutput: "497df3d072612cb5",
recipeConfig: [
{
"op": "XTEA Encrypt",
"args": [
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Hex", "NO", 32
]
}
],
},
// ==================== EDGE CASES ====================
{
name: "TEA Encrypt: empty input returns empty",
input: "",
expectedOutput: "",
recipeConfig: [
{
"op": "TEA Encrypt",
"args": [
{"option": "Hex", "string": "00000000000000000000000000000000"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Hex", "NO"
]
}
],
},
{
name: "XTEA Encrypt: empty input returns empty",
input: "",
expectedOutput: "",
recipeConfig: [
{
"op": "XTEA Encrypt",
"args": [
{"option": "Hex", "string": "00000000000000000000000000000000"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Hex", "NO", 32
]
}
],
},
// ==================== MULTI-BLOCK ECB TESTS ====================
{
name: "TEA Encrypt then Decrypt: multi-block ECB with PKCS5",
input: "This is a longer message that spans multiple TEA blocks!",
expectedOutput: "This is a longer message that spans multiple TEA blocks!",
recipeConfig: [
{
"op": "TEA Encrypt",
"args": [
{"option": "Hex", "string": "0123456789abcdef0123456789abcdef"},
{"option": "Hex", "string": ""},
"ECB", "Raw", "Hex", "PKCS5"
]
},
{
"op": "TEA Decrypt",
"args": [
{"option": "Hex", "string": "0123456789abcdef0123456789abcdef"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Raw", "PKCS5"
]
}
],
},
{
name: "XTEA Encrypt then Decrypt: multi-block ECB with PKCS5",
input: "This is a longer message that spans multiple XTEA blocks!",
expectedOutput: "This is a longer message that spans multiple XTEA blocks!",
recipeConfig: [
{
"op": "XTEA Encrypt",
"args": [
{"option": "Hex", "string": "0123456789abcdef0123456789abcdef"},
{"option": "Hex", "string": ""},
"ECB", "Raw", "Hex", "PKCS5", 32
]
},
{
"op": "XTEA Decrypt",
"args": [
{"option": "Hex", "string": "0123456789abcdef0123456789abcdef"},
{"option": "Hex", "string": ""},
"ECB", "Hex", "Raw", "PKCS5", 32
]
}
],
},
]);

View File

@ -0,0 +1,486 @@
/**
* Twofish cipher tests.
*
* Test vectors from the official Twofish paper:
* https://www.schneier.com/academic/twofish/
*
* Note: PKCS5 padding adds an extra block when input is exactly block-aligned.
* Round-trip tests verify correct encryption/decryption behavior.
*
* @author Medjedtxm
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
// ============================================================
// OFFICIAL TEST VECTORS from Bruce Schneier's Twofish paper:
// https://www.schneier.com/academic/twofish/
// https://www.schneier.com/wp-content/uploads/2015/12/ecb_ival.txt
// ============================================================
{
name: "Twofish Official Vector: 128-bit zero key, zero plaintext",
input: "00000000000000000000000000000000",
expectedOutput: "9f589f5cf6122c32b6bfec2f2ae8c35a",
recipeConfig: [
{
op: "Twofish Encrypt",
args: [
{ string: "00000000000000000000000000000000", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Hex", "NO"
]
}
]
},
{
name: "Twofish Official Vector: 192-bit zero key, zero plaintext",
input: "00000000000000000000000000000000",
expectedOutput: "efa71f788965bd4453f860178fc19101",
recipeConfig: [
{
op: "Twofish Encrypt",
args: [
{ string: "000000000000000000000000000000000000000000000000", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Hex", "NO"
]
}
]
},
{
name: "Twofish Official Vector: 256-bit zero key, zero plaintext",
input: "00000000000000000000000000000000",
expectedOutput: "57ff739d4dc92c1bd7fc01700cc8216f",
recipeConfig: [
{
op: "Twofish Encrypt",
args: [
{ string: "0000000000000000000000000000000000000000000000000000000000000000", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Hex", "NO"
]
}
]
},
// Decrypt verification of official vectors
{
name: "Twofish Official Vector Decrypt: 128-bit zero key",
input: "9f589f5cf6122c32b6bfec2f2ae8c35a",
expectedOutput: "00000000000000000000000000000000",
recipeConfig: [
{
op: "Twofish Decrypt",
args: [
{ string: "00000000000000000000000000000000", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Hex", "NO"
]
}
]
},
// ============================================================
// Round-trip tests for ECB mode with various key sizes
// ============================================================
{
name: "Twofish Round-trip: ECB 128-bit key",
input: "Hello, World!!!",
expectedOutput: "Hello, World!!!",
recipeConfig: [
{
op: "Twofish Encrypt",
args: [
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Raw", "Hex", "PKCS5"
]
},
{
op: "Twofish Decrypt",
args: [
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Raw", "PKCS5"
]
}
]
},
{
name: "Twofish Round-trip: ECB 192-bit key",
input: "Testing Twofish with 192-bit key",
expectedOutput: "Testing Twofish with 192-bit key",
recipeConfig: [
{
op: "Twofish Encrypt",
args: [
{ string: "000102030405060708090a0b0c0d0e0f1011121314151617", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Raw", "Hex", "PKCS5"
]
},
{
op: "Twofish Decrypt",
args: [
{ string: "000102030405060708090a0b0c0d0e0f1011121314151617", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Raw", "PKCS5"
]
}
]
},
{
name: "Twofish Round-trip: ECB 256-bit key",
input: "Testing Twofish with 256-bit key encryption",
expectedOutput: "Testing Twofish with 256-bit key encryption",
recipeConfig: [
{
op: "Twofish Encrypt",
args: [
{ string: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Raw", "Hex", "PKCS5"
]
},
{
op: "Twofish Decrypt",
args: [
{ string: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Raw", "PKCS5"
]
}
]
},
// Round-trip tests for CBC mode
{
name: "Twofish Round-trip: CBC 128-bit key",
input: "The quick brown fox jumps over the lazy dog",
expectedOutput: "The quick brown fox jumps over the lazy dog",
recipeConfig: [
{
op: "Twofish Encrypt",
args: [
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
{ string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
"CBC", "Raw", "Hex", "PKCS5"
]
},
{
op: "Twofish Decrypt",
args: [
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
{ string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
"CBC", "Hex", "Raw", "PKCS5"
]
}
]
},
{
name: "Twofish Round-trip: CBC 192-bit key",
input: "Testing Twofish with 192-bit key in CBC mode",
expectedOutput: "Testing Twofish with 192-bit key in CBC mode",
recipeConfig: [
{
op: "Twofish Encrypt",
args: [
{ string: "000102030405060708090a0b0c0d0e0f1011121314151617", option: "Hex" },
{ string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
"CBC", "Raw", "Hex", "PKCS5"
]
},
{
op: "Twofish Decrypt",
args: [
{ string: "000102030405060708090a0b0c0d0e0f1011121314151617", option: "Hex" },
{ string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
"CBC", "Hex", "Raw", "PKCS5"
]
}
]
},
{
name: "Twofish Round-trip: CBC 256-bit key",
input: "Testing Twofish with 256-bit key in CBC mode",
expectedOutput: "Testing Twofish with 256-bit key in CBC mode",
recipeConfig: [
{
op: "Twofish Encrypt",
args: [
{ string: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", option: "Hex" },
{ string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
"CBC", "Raw", "Hex", "PKCS5"
]
},
{
op: "Twofish Decrypt",
args: [
{ string: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", option: "Hex" },
{ string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
"CBC", "Hex", "Raw", "PKCS5"
]
}
]
},
// Round-trip tests for CFB mode
{
name: "Twofish Round-trip: CFB 128-bit key",
input: "Testing Twofish CFB mode encryption",
expectedOutput: "Testing Twofish CFB mode encryption",
recipeConfig: [
{
op: "Twofish Encrypt",
args: [
{ string: "deadbeefcafebabe0123456789abcdef", option: "Hex" },
{ string: "0102030405060708090a0b0c0d0e0f10", option: "Hex" },
"CFB", "Raw", "Hex", "PKCS5"
]
},
{
op: "Twofish Decrypt",
args: [
{ string: "deadbeefcafebabe0123456789abcdef", option: "Hex" },
{ string: "0102030405060708090a0b0c0d0e0f10", option: "Hex" },
"CFB", "Hex", "Raw", "PKCS5"
]
}
]
},
// Round-trip tests for OFB mode
{
name: "Twofish Round-trip: OFB 128-bit key",
input: "Testing Twofish OFB mode encryption",
expectedOutput: "Testing Twofish OFB mode encryption",
recipeConfig: [
{
op: "Twofish Encrypt",
args: [
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
{ string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
"OFB", "Raw", "Hex", "PKCS5"
]
},
{
op: "Twofish Decrypt",
args: [
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
{ string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
"OFB", "Hex", "Raw", "PKCS5"
]
}
]
},
// Round-trip tests for CTR mode
{
name: "Twofish Round-trip: CTR 128-bit key",
input: "Testing Twofish CTR mode encryption",
expectedOutput: "Testing Twofish CTR mode encryption",
recipeConfig: [
{
op: "Twofish Encrypt",
args: [
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
{ string: "00000000000000000000000000000001", option: "Hex" },
"CTR", "Raw", "Hex", "PKCS5"
]
},
{
op: "Twofish Decrypt",
args: [
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
{ string: "00000000000000000000000000000001", option: "Hex" },
"CTR", "Hex", "Raw", "PKCS5"
]
}
]
},
// UTF8 key tests
{
name: "Twofish Round-trip: UTF8 key (16 bytes)",
input: "Secret message!",
expectedOutput: "Secret message!",
recipeConfig: [
{
op: "Twofish Encrypt",
args: [
{ string: "MySecretPassword", option: "UTF8" },
{ string: "InitVectorHere!!", option: "UTF8" },
"CBC", "Raw", "Hex", "PKCS5"
]
},
{
op: "Twofish Decrypt",
args: [
{ string: "MySecretPassword", option: "UTF8" },
{ string: "InitVectorHere!!", option: "UTF8" },
"CBC", "Hex", "Raw", "PKCS5"
]
}
]
},
// Various input length tests
{
name: "Twofish Round-trip: 1 byte input",
input: "A",
expectedOutput: "A",
recipeConfig: [
{
op: "Twofish Encrypt",
args: [
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Raw", "Hex", "PKCS5"
]
},
{
op: "Twofish Decrypt",
args: [
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Raw", "PKCS5"
]
}
]
},
{
name: "Twofish Round-trip: 15 byte input",
input: "123456789012345",
expectedOutput: "123456789012345",
recipeConfig: [
{
op: "Twofish Encrypt",
args: [
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Raw", "Hex", "PKCS5"
]
},
{
op: "Twofish Decrypt",
args: [
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Raw", "PKCS5"
]
}
]
},
{
name: "Twofish Round-trip: 16 byte input (exact block)",
input: "1234567890123456",
expectedOutput: "1234567890123456",
recipeConfig: [
{
op: "Twofish Encrypt",
args: [
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Raw", "Hex", "PKCS5"
]
},
{
op: "Twofish Decrypt",
args: [
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Raw", "PKCS5"
]
}
]
},
{
name: "Twofish Round-trip: 17 byte input",
input: "12345678901234567",
expectedOutput: "12345678901234567",
recipeConfig: [
{
op: "Twofish Encrypt",
args: [
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Raw", "Hex", "PKCS5"
]
},
{
op: "Twofish Decrypt",
args: [
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Raw", "PKCS5"
]
}
]
},
{
name: "Twofish Round-trip: 32 byte input (two blocks)",
input: "12345678901234567890123456789012",
expectedOutput: "12345678901234567890123456789012",
recipeConfig: [
{
op: "Twofish Encrypt",
args: [
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Raw", "Hex", "PKCS5"
]
},
{
op: "Twofish Decrypt",
args: [
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Hex", "Raw", "PKCS5"
]
}
]
},
// Binary data test
{
name: "Twofish Round-trip: Binary data",
input: "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
expectedOutput: "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
recipeConfig: [
{
op: "Twofish Encrypt",
args: [
{ string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
"CBC", "Raw", "Hex", "PKCS5"
]
},
{
op: "Twofish Decrypt",
args: [
{ string: "ffeeddccbbaa99887766554433221100", option: "Hex" },
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
"CBC", "Hex", "Raw", "PKCS5"
]
}
]
},
// Consistency test - same input should always produce same output
{
name: "Twofish Encrypt: 128-bit key consistency test",
input: "TestData12345678",
expectedOutput: "8aed2d3a85dc3e0b663ba1fe1fdaf056771d591428af301d69fa1e227d083527",
recipeConfig: [
{
op: "Twofish Encrypt",
args: [
{ string: "00000000000000000000000000000000", option: "Hex" },
{ string: "", option: "Hex" },
"ECB", "Raw", "Hex", "PKCS5"
]
}
]
}
]);