mirror of
https://github.com/gchq/CyberChef
synced 2025-12-05 23:53:27 +00:00
Compare commits
241 Commits
bug/disabl
...
411f78d27a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
411f78d27a | ||
|
|
7ed7fca3ad | ||
|
|
5d3353189b | ||
|
|
f92238bf04 | ||
|
|
2b1ceef6a3 | ||
|
|
f4e73eef54 | ||
|
|
d751117219 | ||
|
|
a55075fdb6 | ||
|
|
288cd8f063 | ||
|
|
a7443778b8 | ||
|
|
e9b182d33b | ||
|
|
0c01c6a7c3 | ||
|
|
06f1982acf | ||
|
|
761173bce7 | ||
|
|
bfec582aee | ||
|
|
3a55b34214 | ||
|
|
95d5fd1789 | ||
|
|
159b80e853 | ||
|
|
f24bd92e34 | ||
|
|
e4f4d9c1c5 | ||
|
|
7ecf8dfdaa | ||
|
|
1bc3105002 | ||
|
|
66d445c5ef | ||
|
|
b2045e5bd8 | ||
|
|
64a4bfeadf | ||
|
|
46762a2af7 | ||
|
|
bd9e0142bc | ||
|
|
da922a45cf | ||
|
|
9538320928 | ||
|
|
b156fc9929 | ||
|
|
dda5814c30 | ||
|
|
7ca472279c | ||
|
|
670721f1f6 | ||
|
|
3c5eea5dfb | ||
|
|
497e2a9d45 | ||
|
|
e4a59c6990 | ||
|
|
85a3a18570 | ||
|
|
a150137c4b | ||
|
|
c6ece4292b | ||
|
|
c475a24854 | ||
|
|
1089c6bfb8 | ||
|
|
4085a4c219 | ||
|
|
a2665ba213 | ||
|
|
0a94c4a7c9 | ||
|
|
64355c9dde | ||
|
|
bd8906f46b | ||
|
|
26d8fa51b0 | ||
|
|
ad91099d5e | ||
|
|
b9ed1fde62 | ||
|
|
a0ade26505 | ||
|
|
575eade84d | ||
|
|
2cf3642493 | ||
|
|
7c8be12d52 | ||
|
|
e849569b10 | ||
|
|
fa559fdbed | ||
|
|
74d631c71e | ||
|
|
305a02c8a2 | ||
|
|
5a3b7bc4c0 | ||
|
|
c83e1ac4fb | ||
|
|
857576dbe4 | ||
|
|
e00a636fc0 | ||
|
|
6f4cbd8688 | ||
|
|
de5b03f854 | ||
|
|
457d28fc55 | ||
|
|
e0bdde89c4 | ||
|
|
68db8e93b7 | ||
|
|
9069d8e3ec | ||
|
|
e146636250 | ||
|
|
c0af2a9eb5 | ||
|
|
ae5648ede1 | ||
|
|
197d6735d2 | ||
|
|
75b52bef6d | ||
|
|
848660f8e1 | ||
|
|
0e7b1f7c78 | ||
|
|
bbb211d819 | ||
|
|
9ca0152aac | ||
|
|
4b72484ca4 | ||
|
|
e469f00fc7 | ||
|
|
75e3f35932 | ||
|
|
9a8804ab94 | ||
|
|
f5b5227e53 | ||
|
|
14472d3b40 | ||
|
|
9f30dd0e7a | ||
|
|
49d69a293b | ||
|
|
23de98f892 | ||
|
|
8852712f0d | ||
|
|
b62def3d3e | ||
|
|
464c92e7bf | ||
|
|
95044ab767 | ||
|
|
a809321b63 | ||
|
|
b6f0f9b200 | ||
|
|
a42c7de112 | ||
|
|
b85036b78f | ||
|
|
3b75e13287 | ||
|
|
98ef5d0110 | ||
|
|
2c21d72a6a | ||
|
|
42efc0187c | ||
|
|
d5f007deea | ||
|
|
566b423065 | ||
|
|
1b4760c447 | ||
|
|
3025391821 | ||
|
|
4e62aa6e1d | ||
|
|
fcecd029c7 | ||
|
|
f4988328be | ||
|
|
7710c5ef49 | ||
|
|
3057a20791 | ||
|
|
b2981d3cc7 | ||
|
|
2c32a64bfe | ||
|
|
d3357d2acd | ||
|
|
91125f00e7 | ||
|
|
4c6b4cd4e7 | ||
|
|
c4574ff042 | ||
|
|
7babef6f93 | ||
|
|
2b2435210b | ||
|
|
4a428e802e | ||
|
|
5b15e75479 | ||
|
|
a40aed2b47 | ||
|
|
5cef2b13a3 | ||
|
|
c2936a6f2c | ||
|
|
06b7f0129f | ||
|
|
e44e6fed35 | ||
|
|
a74e2e585e | ||
|
|
d602897221 | ||
|
|
1b8c229df2 | ||
|
|
aa7bbc1a62 | ||
|
|
6ccbc892c7 | ||
|
|
7b3980a5e2 | ||
|
|
7906f9d560 | ||
|
|
2ae923b73e | ||
|
|
15bbed093c | ||
|
|
23faeadea2 | ||
|
|
50c0d4bcd6 | ||
|
|
7f97afd3e0 | ||
|
|
c3994aa8e3 | ||
|
|
8166f981ae | ||
|
|
1cfbc2babb | ||
|
|
eb912547ac | ||
|
|
bcf62ec73d | ||
|
|
004ef7f5dc | ||
|
|
9ab990ff59 | ||
|
|
fb8e1be9f0 | ||
|
|
324560aeae | ||
|
|
95c6406d05 | ||
|
|
51b9fe644b | ||
|
|
fed10f3ee6 | ||
|
|
7cc3e5804b | ||
|
|
dcf0bbb02b | ||
|
|
f8b613b4e7 | ||
|
|
e48fc4c8d8 | ||
|
|
1b53b8d23f | ||
|
|
355566736a | ||
|
|
b99a76f9a6 | ||
|
|
912bbe54aa | ||
|
|
26a16b6945 | ||
|
|
feaf3dd119 | ||
|
|
3187ff6322 | ||
|
|
13f94a23f8 | ||
|
|
592e660deb | ||
|
|
3cdbdf4223 | ||
|
|
8cd875d06a | ||
|
|
bf36fe8143 | ||
|
|
41c5403700 | ||
|
|
5a7cb9e047 | ||
|
|
a41068e633 | ||
|
|
bce04609a5 | ||
|
|
d4da81fa91 | ||
|
|
d3e31890ae | ||
|
|
9f2527d736 | ||
|
|
caa373c1be | ||
|
|
f14c423c64 | ||
|
|
6f63de81b1 | ||
|
|
75991321de | ||
|
|
b560d74b8e | ||
|
|
90133e3f90 | ||
|
|
672cb5dea4 | ||
|
|
7eb9e08ad2 | ||
|
|
2007b26d57 | ||
|
|
e804555278 | ||
|
|
6b75ba8903 | ||
|
|
54e559c5a6 | ||
|
|
02f45e545d | ||
|
|
bab0a7ffed | ||
|
|
b92c1e7da0 | ||
|
|
0c6c45b152 | ||
|
|
802c576c60 | ||
|
|
e484d426fe | ||
|
|
4c6dcf182d | ||
|
|
4bb1e335ea | ||
|
|
ae9054dc37 | ||
|
|
f61bdf06c6 | ||
|
|
0f16fa0ce1 | ||
|
|
84ce8e6f30 | ||
|
|
9eff9e5018 | ||
|
|
857d3b6d17 | ||
|
|
54cfb17145 | ||
|
|
99ba6b487c | ||
|
|
a1647b02cb | ||
|
|
b15322467b | ||
| 9229fe9ac7 | |||
| 488c458720 | |||
|
|
784b2631a8 | ||
|
|
3eb1af0278 | ||
|
|
7e5eb01a5e | ||
|
|
1fce8e5112 | ||
|
|
738e6feda0 | ||
|
|
95f6c4c5d5 | ||
|
|
7877a0d7d0 | ||
| a80b1568ac | |||
| a616e46b50 | |||
| 752ce789c2 | |||
| 660069865a | |||
| 9169254fff | |||
| e12b00485e | |||
| 51a07a27db | |||
|
|
c8c9e572a6 | ||
| 7fb4824cd6 | |||
| 5e763b86dc | |||
| b090ce0428 | |||
|
|
3dddb516c9 | ||
|
|
fb3c36af85 | ||
|
|
edd22372d8 | ||
|
|
66d3b6e9ed | ||
| 036f80d734 | |||
|
|
3ca4c2fd45 | ||
|
|
cc21fe18ca | ||
|
|
4255d8d543 | ||
|
|
7353315baa | ||
|
|
721061d054 | ||
|
|
d2da11c79a | ||
|
|
c0e84dcd50 | ||
|
|
15b426ebb6 | ||
|
|
bf1e708a4c | ||
|
|
3e8c5d945c | ||
|
|
23763363ba | ||
|
|
518b336431 | ||
|
|
b125f82784 | ||
|
|
30349dbcb9 | ||
|
|
02f6537973 | ||
|
|
502f126986 | ||
|
|
7c7d1823ca | ||
|
|
ce6d38860d |
17
.cspell.json
Normal file
17
.cspell.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"version": "0.2",
|
||||
"language": "en,en-gb",
|
||||
"words": [],
|
||||
"dictionaries": [
|
||||
"npm",
|
||||
"softwareTerms",
|
||||
"node",
|
||||
"html",
|
||||
"css",
|
||||
"bash",
|
||||
"en-gb",
|
||||
"misc"
|
||||
],
|
||||
"ignorePaths": ["package.json", "package-lock.json", "node_modules"]
|
||||
}
|
||||
|
||||
21
.github/workflows/releases.yml
vendored
21
.github/workflows/releases.yml
vendored
@@ -25,6 +25,7 @@ jobs:
|
||||
|
||||
- name: Install
|
||||
run: |
|
||||
export DETECT_CHROMEDRIVER_VERSION=true
|
||||
npm ci
|
||||
npm run setheapsize
|
||||
|
||||
@@ -61,12 +62,22 @@ jobs:
|
||||
tags: ${{ steps.image-metadata.outputs.tags }}
|
||||
labels: ${{ steps.image-metadata.outputs.labels }}
|
||||
containerfiles: ./Dockerfile
|
||||
platforms: linux/amd64
|
||||
platforms: linux/amd64,linux/arm64
|
||||
oci: true
|
||||
# enable build layer caching between platforms
|
||||
layers: true
|
||||
# Webpack seems to use a lot of open files, increase the max open file limit to accomodate.
|
||||
extra-args: |
|
||||
--ulimit nofile=10000
|
||||
|
||||
- name: Publish to GHCR
|
||||
uses: redhat-actions/push-to-registry@v2
|
||||
with:
|
||||
image: ${{ steps.build-image.outputs.image }}
|
||||
tags: ${{ steps.build-image.outputs.tags }}
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ env.REGISTRY_USER }}
|
||||
password: ${{ env.REGISTRY_PASSWORD }}
|
||||
|
||||
- name: Upload Release Assets
|
||||
id: upload-release-assets
|
||||
@@ -83,11 +94,3 @@ jobs:
|
||||
uses: JS-DevTools/npm-publish@v1
|
||||
with:
|
||||
token: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
- name: Publish to GHCR
|
||||
uses: redhat-actions/push-to-registry@v2
|
||||
with:
|
||||
tags: ${{ steps.build-image.outputs.tags }}
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ env.REGISTRY_USER }}
|
||||
password: ${{ env.REGISTRY_PASSWORD }}
|
||||
|
||||
34
Dockerfile
34
Dockerfile
@@ -1,9 +1,35 @@
|
||||
FROM node:18-alpine AS build
|
||||
#####################################
|
||||
# Build the app to a static website #
|
||||
#####################################
|
||||
# Modifier --platform=$BUILDPLATFORM limits the platform to "BUILDPLATFORM" during buildx multi-platform builds
|
||||
# This is because npm "chromedriver" package is not compatiable with all platforms
|
||||
# For more info see: https://docs.docker.com/build/building/multi-platform/#cross-compilation
|
||||
FROM --platform=$BUILDPLATFORM node:18-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json .
|
||||
COPY package-lock.json .
|
||||
|
||||
# Install dependencies
|
||||
# --ignore-scripts prevents postinstall script (which runs grunt) as it depends on files other than package.json
|
||||
RUN npm ci --ignore-scripts
|
||||
|
||||
# Copy files needed for postinstall and build
|
||||
COPY . .
|
||||
RUN npm ci
|
||||
|
||||
# npm postinstall runs grunt, which depends on files other than package.json
|
||||
RUN npm run postinstall
|
||||
|
||||
# Build the app
|
||||
RUN npm run build
|
||||
|
||||
FROM nginx:1.25-alpine3.18 AS cyberchef
|
||||
#########################################
|
||||
# Package static build files into nginx #
|
||||
#########################################
|
||||
# We are using Github Actions: redhat-actions/buildah-build@v2 which needs manual selection of arch in base image
|
||||
# Remove TARGETARCH if docker buildx is supported in the CI release as --platform=$TARGETPLATFORM will be automatically set
|
||||
ARG TARGETPLATFORM
|
||||
FROM --platform=${TARGETPLATFORM} nginx:stable-alpine AS cyberchef
|
||||
|
||||
COPY --from=build ./build/prod /usr/share/nginx/html/
|
||||
COPY --from=builder /app/build/prod /usr/share/nginx/html/
|
||||
|
||||
9611
package-lock.json
generated
9611
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@@ -61,6 +61,7 @@
|
||||
"compression-webpack-plugin": "^11.1.0",
|
||||
"copy-webpack-plugin": "^12.0.2",
|
||||
"core-js": "^3.37.1",
|
||||
"cspell": "^8.17.3",
|
||||
"css-loader": "7.1.2",
|
||||
"eslint": "^9.4.0",
|
||||
"eslint-plugin-jsdoc": "^48.2.9",
|
||||
@@ -122,6 +123,7 @@
|
||||
"d3": "7.9.0",
|
||||
"d3-hexbin": "^0.2.2",
|
||||
"diff": "^5.2.0",
|
||||
"dompurify": "^3.2.5",
|
||||
"es6-promisify": "^7.0.0",
|
||||
"escodegen": "^2.1.0",
|
||||
"esprima": "^4.0.1",
|
||||
@@ -130,14 +132,16 @@
|
||||
"file-saver": "^2.0.5",
|
||||
"flat": "^6.0.1",
|
||||
"geodesy": "1.1.3",
|
||||
"hash-wasm": "^4.12.0",
|
||||
"highlight.js": "^11.9.0",
|
||||
"ieee754": "^1.2.1",
|
||||
"jimp": "^0.22.12",
|
||||
"jq-web": "^0.5.1",
|
||||
"jquery": "3.7.1",
|
||||
"js-crc": "^0.2.0",
|
||||
"js-sha3": "^0.9.3",
|
||||
"jsesc": "^3.0.2",
|
||||
"json5": "^2.2.3",
|
||||
"jsonata": "^2.0.3",
|
||||
"jsonpath-plus": "^9.0.0",
|
||||
"jsonwebtoken": "8.5.1",
|
||||
"jsqr": "^1.4.0",
|
||||
@@ -160,7 +164,7 @@
|
||||
"notepack.io": "^3.0.1",
|
||||
"ntlm": "^0.1.3",
|
||||
"nwmatcher": "^1.4.4",
|
||||
"otp": "0.1.3",
|
||||
"otpauth": "9.3.6",
|
||||
"path": "^0.12.7",
|
||||
"popper.js": "^1.16.1",
|
||||
"process": "^0.11.10",
|
||||
@@ -178,6 +182,7 @@
|
||||
"ua-parser-js": "^1.0.38",
|
||||
"unorm": "^1.6.0",
|
||||
"utf8": "^3.0.0",
|
||||
"uuid": "^11.1.0",
|
||||
"vkbeautify": "^0.99.3",
|
||||
"xpath": "0.0.34",
|
||||
"xregexp": "^5.1.1",
|
||||
@@ -193,6 +198,7 @@
|
||||
"testui": "npx grunt testui",
|
||||
"testuidev": "npx nightwatch --env=dev",
|
||||
"lint": "npx grunt lint",
|
||||
"lint:grammar": "cspell ./src",
|
||||
"postinstall": "npx grunt exec:fixCryptoApiImports && npx grunt exec:fixSnackbarMarkup && npx grunt exec:fixJimpModule",
|
||||
"newop": "node --experimental-modules --experimental-json-modules src/core/config/scripts/newOperation.mjs",
|
||||
"minor": "node --experimental-modules --experimental-json-modules src/core/config/scripts/newMinorVersion.mjs",
|
||||
|
||||
@@ -72,9 +72,14 @@
|
||||
"Avro to JSON",
|
||||
"CBOR Encode",
|
||||
"CBOR Decode",
|
||||
"YAML to JSON",
|
||||
"JSON to YAML",
|
||||
"Caret/M-decode",
|
||||
"Rison Encode",
|
||||
"Rison Decode"
|
||||
"Rison Decode",
|
||||
"To Modhex",
|
||||
"From Modhex",
|
||||
"MIME Decoding"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -190,7 +195,9 @@
|
||||
"Parse SSH Host Key",
|
||||
"Parse CSR",
|
||||
"Public Key from Certificate",
|
||||
"Public Key from Private Key"
|
||||
"Public Key from Private Key",
|
||||
"SM2 Encrypt",
|
||||
"SM2 Decrypt"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -234,7 +241,9 @@
|
||||
"Parse User Agent",
|
||||
"Parse IP range",
|
||||
"Parse IPv6 address",
|
||||
"IPv6 Transition Addresses",
|
||||
"Parse IPv4 header",
|
||||
"Strip IPv4 header",
|
||||
"Parse TCP",
|
||||
"Strip TCP header",
|
||||
"Parse TLS record",
|
||||
@@ -272,7 +281,8 @@
|
||||
"Unicode Text Format",
|
||||
"Remove Diacritics",
|
||||
"Unescape Unicode Characters",
|
||||
"Convert to NATO alphabet"
|
||||
"Convert to NATO alphabet",
|
||||
"Convert Leet Speak"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -284,6 +294,7 @@
|
||||
"To Upper case",
|
||||
"To Lower case",
|
||||
"Swap case",
|
||||
"Alternating Caps",
|
||||
"To Case Insensitive Regex",
|
||||
"From Case Insensitive Regex",
|
||||
"Add line numbers",
|
||||
@@ -324,7 +335,9 @@
|
||||
"Unescape string",
|
||||
"Pseudo-Random Number Generator",
|
||||
"Sleep",
|
||||
"File Tree"
|
||||
"File Tree",
|
||||
"Take nth bytes",
|
||||
"Drop nth bytes"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -357,6 +370,7 @@
|
||||
"Regular expression",
|
||||
"XPath expression",
|
||||
"JPath expression",
|
||||
"Jsonata Query",
|
||||
"CSS selector",
|
||||
"Extract EXIF",
|
||||
"Extract ID3",
|
||||
@@ -392,6 +406,7 @@
|
||||
"name": "Hashing",
|
||||
"ops": [
|
||||
"Analyse hash",
|
||||
"Generate all checksums",
|
||||
"Generate all hashes",
|
||||
"MD2",
|
||||
"MD4",
|
||||
@@ -410,6 +425,7 @@
|
||||
"Snefru",
|
||||
"BLAKE2b",
|
||||
"BLAKE2s",
|
||||
"BLAKE3",
|
||||
"GOST Hash",
|
||||
"Streebog",
|
||||
"SSDEEP",
|
||||
@@ -433,10 +449,9 @@
|
||||
"Fletcher-64 Checksum",
|
||||
"Adler-32 Checksum",
|
||||
"Luhn Checksum",
|
||||
"CRC-8 Checksum",
|
||||
"CRC-16 Checksum",
|
||||
"CRC-32 Checksum",
|
||||
"TCP/IP Checksum"
|
||||
"CRC Checksum",
|
||||
"TCP/IP Checksum",
|
||||
"XOR Checksum"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -457,8 +472,10 @@
|
||||
"CSS Minify",
|
||||
"XPath expression",
|
||||
"JPath expression",
|
||||
"Jq",
|
||||
"CSS selector",
|
||||
"PHP Deserialize",
|
||||
"PHP Serialize",
|
||||
"Microsoft Script Decoder",
|
||||
"Strip HTML tags",
|
||||
"Diff",
|
||||
@@ -533,6 +550,7 @@
|
||||
"Pseudo-Random Number Generator",
|
||||
"Generate De Bruijn Sequence",
|
||||
"Generate UUID",
|
||||
"Analyse UUID",
|
||||
"Generate TOTP",
|
||||
"Generate HOTP",
|
||||
"Generate QR Code",
|
||||
|
||||
23
src/core/lib/Base32.mjs
Normal file
23
src/core/lib/Base32.mjs
Normal file
@@ -0,0 +1,23 @@
|
||||
// import Utils from "../Utils.mjs";
|
||||
|
||||
/**
|
||||
* Base32 resources.
|
||||
*
|
||||
* @author Peter C-S [petercs@purelymail.com]
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base32 alphabets.
|
||||
*/
|
||||
export const ALPHABET_OPTIONS = [
|
||||
{
|
||||
name: "Standard", // https://www.rfc-editor.org/rfc/rfc4648#section-6
|
||||
value: "A-Z2-7=",
|
||||
},
|
||||
{
|
||||
name: "Hex Extended", // https://www.rfc-editor.org/rfc/rfc4648#section-7
|
||||
value: "0-9A-V=",
|
||||
},
|
||||
];
|
||||
|
||||
@@ -62,3 +62,9 @@ export const URL_REGEX = new RegExp(protocol + hostname + "(?:" + port + ")?(?:"
|
||||
* Domain name regular expression
|
||||
*/
|
||||
export const DOMAIN_REGEX = /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/ig;
|
||||
|
||||
|
||||
/**
|
||||
* DMARC Domain name regular expression
|
||||
*/
|
||||
export const DMARC_DOMAIN_REGEX = /\b((?=[a-z0-9_-]{1,63}\.)(xn--)?[a-z0-9_]+(-[a-z0-9_]+)*\.)+[a-z]{2,63}\b/ig;
|
||||
|
||||
165
src/core/lib/Modhex.mjs
Normal file
165
src/core/lib/Modhex.mjs
Normal file
@@ -0,0 +1,165 @@
|
||||
/**
|
||||
* @author linuxgemini [ilteris@asenkron.com.tr]
|
||||
* @copyright Crown Copyright 2024
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Utils from "../Utils.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import { fromHex, toHex } from "./Hex.mjs";
|
||||
|
||||
/**
|
||||
* Modhex alphabet.
|
||||
*/
|
||||
const MODHEX_ALPHABET = "cbdefghijklnrtuv";
|
||||
|
||||
|
||||
/**
|
||||
* Modhex alphabet map.
|
||||
*/
|
||||
const MODHEX_ALPHABET_MAP = MODHEX_ALPHABET.split("");
|
||||
|
||||
|
||||
/**
|
||||
* Hex alphabet to substitute Modhex.
|
||||
*/
|
||||
const HEX_ALPHABET = "0123456789abcdef";
|
||||
|
||||
|
||||
/**
|
||||
* Hex alphabet map to substitute Modhex.
|
||||
*/
|
||||
const HEX_ALPHABET_MAP = HEX_ALPHABET.split("");
|
||||
|
||||
|
||||
/**
|
||||
* Convert a byte array into a modhex string.
|
||||
*
|
||||
* @param {byteArray|Uint8Array|ArrayBuffer} data
|
||||
* @param {string} [delim=" "]
|
||||
* @param {number} [padding=2]
|
||||
* @returns {string}
|
||||
*
|
||||
* @example
|
||||
* // returns "cl bf bu"
|
||||
* toModhex([10,20,30]);
|
||||
*
|
||||
* // returns "cl:bf:bu"
|
||||
* toModhex([10,20,30], ":");
|
||||
*/
|
||||
export function toModhex(data, delim=" ", padding=2, extraDelim="", lineSize=0) {
|
||||
if (!data) return "";
|
||||
if (data instanceof ArrayBuffer) data = new Uint8Array(data);
|
||||
|
||||
const regularHexString = toHex(data, "", padding, "", 0);
|
||||
|
||||
let modhexString = "";
|
||||
for (const letter of regularHexString.split("")) {
|
||||
modhexString += MODHEX_ALPHABET_MAP[HEX_ALPHABET_MAP.indexOf(letter)];
|
||||
}
|
||||
|
||||
let output = "";
|
||||
const groupingRegexp = new RegExp(`.{1,${padding}}`, "g");
|
||||
const groupedModhex = modhexString.match(groupingRegexp);
|
||||
|
||||
for (let i = 0; i < groupedModhex.length; i++) {
|
||||
const group = groupedModhex[i];
|
||||
output += group + delim;
|
||||
|
||||
if (extraDelim) {
|
||||
output += extraDelim;
|
||||
}
|
||||
// Add LF after each lineSize amount of bytes but not at the end
|
||||
if ((i !== groupedModhex.length - 1) && ((i + 1) % lineSize === 0)) {
|
||||
output += "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the extraDelim at the end (if there is one)
|
||||
// and remove the delim at the end, but if it's prepended there's nothing to remove
|
||||
const rTruncLen = extraDelim.length + delim.length;
|
||||
if (rTruncLen) {
|
||||
// If rTruncLen === 0 then output.slice(0,0) will be returned, which is nothing
|
||||
return output.slice(0, -rTruncLen);
|
||||
} else {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a byte array into a modhex string as efficiently as possible with no options.
|
||||
*
|
||||
* @param {byteArray|Uint8Array|ArrayBuffer} data
|
||||
* @returns {string}
|
||||
*
|
||||
* @example
|
||||
* // returns "clbfbu"
|
||||
* toModhexFast([10,20,30]);
|
||||
*/
|
||||
export function toModhexFast(data) {
|
||||
if (!data) return "";
|
||||
if (data instanceof ArrayBuffer) data = new Uint8Array(data);
|
||||
|
||||
const output = [];
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
output.push(MODHEX_ALPHABET_MAP[(data[i] >> 4) & 0xf]);
|
||||
output.push(MODHEX_ALPHABET_MAP[data[i] & 0xf]);
|
||||
}
|
||||
return output.join("");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a modhex string into a byte array.
|
||||
*
|
||||
* @param {string} data
|
||||
* @param {string} [delim]
|
||||
* @param {number} [byteLen=2]
|
||||
* @returns {byteArray}
|
||||
*
|
||||
* @example
|
||||
* // returns [10,20,30]
|
||||
* fromModhex("cl bf bu");
|
||||
*
|
||||
* // returns [10,20,30]
|
||||
* fromModhex("cl:bf:bu", "Colon");
|
||||
*/
|
||||
export function fromModhex(data, delim="Auto", byteLen=2) {
|
||||
if (byteLen < 1 || Math.round(byteLen) !== byteLen)
|
||||
throw new OperationError("Byte length must be a positive integer");
|
||||
|
||||
// The `.replace(/\s/g, "")` an interesting workaround: Hex "multiline" tests aren't actually
|
||||
// multiline. Tests for Modhex fixes that, thus exposing the issue.
|
||||
data = data.toLowerCase().replace(/\s/g, "");
|
||||
|
||||
if (delim !== "None") {
|
||||
const delimRegex = delim === "Auto" ? /[^cbdefghijklnrtuv]/gi : Utils.regexRep(delim);
|
||||
data = data.split(delimRegex);
|
||||
} else {
|
||||
data = [data];
|
||||
}
|
||||
|
||||
let regularHexString = "";
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
for (const letter of data[i].split("")) {
|
||||
regularHexString += HEX_ALPHABET_MAP[MODHEX_ALPHABET_MAP.indexOf(letter)];
|
||||
}
|
||||
}
|
||||
|
||||
const output = fromHex(regularHexString, "None", byteLen);
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* To Modhex delimiters.
|
||||
*/
|
||||
export const TO_MODHEX_DELIM_OPTIONS = ["Space", "Percent", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF", "None"];
|
||||
|
||||
|
||||
/**
|
||||
* From Modhex delimiters.
|
||||
*/
|
||||
export const FROM_MODHEX_DELIM_OPTIONS = ["Auto"].concat(TO_MODHEX_DELIM_OPTIONS);
|
||||
258
src/core/lib/SM2.mjs
Normal file
258
src/core/lib/SM2.mjs
Normal file
@@ -0,0 +1,258 @@
|
||||
/**
|
||||
* Utilities and operations utilized for SM2 encryption and decryption
|
||||
* @author flakjacket95 [dflack95@gmail.com]
|
||||
* @copyright Crown Copyright 2024
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import { fromHex } from "../lib/Hex.mjs";
|
||||
import Utils from "../Utils.mjs";
|
||||
import Sm3 from "crypto-api/src/hasher/sm3.mjs";
|
||||
import {toHex} from "crypto-api/src/encoder/hex.mjs";
|
||||
import r from "jsrsasign";
|
||||
|
||||
/**
|
||||
* SM2 Class for encryption and decryption operations
|
||||
*/
|
||||
export class SM2 {
|
||||
/**
|
||||
* Constructor for SM2 class; sets up with the curve and the output format as specified in user args
|
||||
*
|
||||
* @param {*} curve
|
||||
* @param {*} format
|
||||
*/
|
||||
constructor(curve, format) {
|
||||
this.ecParams = null;
|
||||
this.rng = new r.SecureRandom();
|
||||
/*
|
||||
For any additional curve definitions utilized by SM2, add another block like the below for that curve, then add the curve name to the Curve selection dropdown
|
||||
*/
|
||||
r.crypto.ECParameterDB.regist(
|
||||
"sm2p256v1", // name / p = 2**256 - 2**224 - 2**96 + 2**64 - 1
|
||||
256,
|
||||
"FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF", // p
|
||||
"FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC", // a
|
||||
"28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93", // b
|
||||
"FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123", // n
|
||||
"1", // h
|
||||
"32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7", // gx
|
||||
"BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0", // gy
|
||||
[]
|
||||
); // alias
|
||||
this.ecParams = r.crypto.ECParameterDB.getByName(curve);
|
||||
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the public key coordinates for the SM2 class
|
||||
*
|
||||
* @param {string} publicKeyX
|
||||
* @param {string} publicKeyY
|
||||
*/
|
||||
setPublicKey(publicKeyX, publicKeyY) {
|
||||
/*
|
||||
* TODO: This needs some additional length validation; and checking for errors in the decoding process
|
||||
* TODO: Can probably support other public key encoding methods here as well in the future
|
||||
*/
|
||||
this.publicKey = this.ecParams.curve.decodePointHex("04" + publicKeyX + publicKeyY);
|
||||
|
||||
if (this.publicKey.isInfinity()) {
|
||||
throw new OperationError("Invalid Public Key");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the private key value for the SM2 class
|
||||
*
|
||||
* @param {string} privateKey
|
||||
*/
|
||||
setPrivateKey(privateKeyHex) {
|
||||
this.privateKey = new r.BigInteger(privateKeyHex, 16);
|
||||
}
|
||||
|
||||
/**
|
||||
* Main encryption function; takes user input, processes encryption and returns the result in hex (with the components arranged as configured by the user args)
|
||||
*
|
||||
* @param {*} input
|
||||
* @returns {string}
|
||||
*/
|
||||
encrypt(input) {
|
||||
const G = this.ecParams.G;
|
||||
|
||||
/*
|
||||
* Compute a new, random public key along the same elliptic curve to form the starting point for our encryption process (record the resulting X and Y as hex to provide as part of the operation output)
|
||||
* k: Randomly generated BigInteger
|
||||
* c1: Result of dotting our curve generator point `G` with the value of `k`
|
||||
*/
|
||||
const k = this.generatePublicKey();
|
||||
const c1 = G.multiply(k);
|
||||
const [hexC1X, hexC1Y] = this.getPointAsHex(c1);
|
||||
|
||||
/*
|
||||
* Compute p2 (secret) using the public key, and the chosen k value above
|
||||
*/
|
||||
const p2 = this.publicKey.multiply(k);
|
||||
|
||||
/*
|
||||
* Compute the C3 SM3 hash before we transform the array
|
||||
*/
|
||||
const c3 = this.c3(p2, input);
|
||||
|
||||
/*
|
||||
* Genreate a proper length encryption key, XOR iteratively, and convert newly encrypted data to hex
|
||||
*/
|
||||
const key = this.kdf(p2, input.byteLength);
|
||||
for (let i = 0; i < input.byteLength; i++) {
|
||||
input[i] ^= Utils.ord(key[i]);
|
||||
}
|
||||
const c2 = Buffer.from(input).toString("hex");
|
||||
|
||||
/*
|
||||
* Check user input specs; order the output components as selected
|
||||
*/
|
||||
if (this.format === "C1C3C2") {
|
||||
return hexC1X + hexC1Y + c3 + c2;
|
||||
} else {
|
||||
return hexC1X + hexC1Y + c2 + c3;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Function to decrypt an SM2 encrypted message
|
||||
*
|
||||
* @param {*} input
|
||||
*/
|
||||
decrypt(input) {
|
||||
const c1X = input.slice(0, 64);
|
||||
const c1Y = input.slice(64, 128);
|
||||
|
||||
let c3 = "";
|
||||
let c2 = "";
|
||||
|
||||
if (this.format === "C1C3C2") {
|
||||
c3 = input.slice(128, 192);
|
||||
c2 = input.slice(192);
|
||||
} else {
|
||||
c2 = input.slice(128, -64);
|
||||
c3 = input.slice(-64);
|
||||
}
|
||||
c2 = Uint8Array.from(fromHex(c2));
|
||||
const c1 = this.ecParams.curve.decodePointHex("04" + c1X + c1Y);
|
||||
|
||||
/*
|
||||
* Compute the p2 (secret) value by taking the C1 point provided in the encrypted package, and multiplying by the private k value
|
||||
*/
|
||||
const p2 = c1.multiply(this.privateKey);
|
||||
|
||||
/*
|
||||
* Similar to encryption; compute sufficient length key material and XOR the input data to recover the original message
|
||||
*/
|
||||
const key = this.kdf(p2, c2.byteLength);
|
||||
|
||||
for (let i = 0; i < c2.byteLength; i++) {
|
||||
c2[i] ^= Utils.ord(key[i]);
|
||||
}
|
||||
|
||||
const check = this.c3(p2, c2);
|
||||
if (check === c3) {
|
||||
return c2.buffer;
|
||||
} else {
|
||||
throw new OperationError("Decryption Error -- Computed Hashes Do Not Match");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates a large random number
|
||||
*
|
||||
* @param {*} limit
|
||||
* @returns
|
||||
*/
|
||||
getBigRandom(limit) {
|
||||
return new r.BigInteger(limit.bitLength(), this.rng)
|
||||
.mod(limit.subtract(r.BigInteger.ONE))
|
||||
.add(r.BigInteger.ONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for generating a large random K number; utilized for generating our initial C1 point
|
||||
* TODO: Do we need to do any sort of validation on the resulting k values?
|
||||
*
|
||||
* @returns {BigInteger}
|
||||
*/
|
||||
generatePublicKey() {
|
||||
const n = this.ecParams.n;
|
||||
const k = this.getBigRandom(n);
|
||||
return k;
|
||||
}
|
||||
|
||||
/**
|
||||
* SM2 Key Derivation Function (KDF); Takes P2 point, and generates a key material stream large enough to encrypt all of the input data
|
||||
*
|
||||
* @param {*} p2
|
||||
* @param {*} len
|
||||
* @returns {string}
|
||||
*/
|
||||
kdf(p2, len) {
|
||||
const [hX, hY] = this.getPointAsHex(p2);
|
||||
|
||||
const total = Math.ceil(len / 32) + 1;
|
||||
let cnt = 1;
|
||||
|
||||
let keyMaterial = "";
|
||||
|
||||
while (cnt < total) {
|
||||
const num = Utils.intToByteArray(cnt, 4, "big");
|
||||
const overall = fromHex(hX).concat(fromHex(hY)).concat(num);
|
||||
keyMaterial += this.sm3(overall);
|
||||
cnt++;
|
||||
}
|
||||
return keyMaterial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the C3 component of our final encrypted payload; which is the SM3 hash of the P2 point and the original, unencrypted input data
|
||||
*
|
||||
* @param {*} p2
|
||||
* @param {*} input
|
||||
* @returns {string}
|
||||
*/
|
||||
c3(p2, input) {
|
||||
const [hX, hY] = this.getPointAsHex(p2);
|
||||
|
||||
const overall = fromHex(hX).concat(Array.from(input)).concat(fromHex(hY));
|
||||
|
||||
return toHex(this.sm3(overall));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* SM3 setup helper function; takes input data as an array, processes the hash and returns the result
|
||||
*
|
||||
* @param {*} data
|
||||
* @returns {string}
|
||||
*/
|
||||
sm3(data) {
|
||||
const hashData = Utils.arrayBufferToStr(Uint8Array.from(data).buffer, false);
|
||||
const hasher = new Sm3();
|
||||
hasher.update(hashData);
|
||||
return hasher.finalize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function, returns an elliptic curve points X and Y values as hex;
|
||||
*
|
||||
* @param {EcPointFp} point
|
||||
* @returns {[]}
|
||||
*/
|
||||
getPointAsHex(point) {
|
||||
const biX = point.getX().toBigInteger();
|
||||
const biY = point.getY().toBigInteger();
|
||||
|
||||
const charlen = this.ecParams.keycharlen;
|
||||
const hX = ("0000000000" + biX.toString(16)).slice(- charlen);
|
||||
const hY = ("0000000000" + biY.toString(16)).slice(- charlen);
|
||||
return [hX, hY];
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ class AESDecrypt extends Operation {
|
||||
run(input, args) {
|
||||
const key = Utils.convertToByteString(args[0].string, args[0].option),
|
||||
iv = Utils.convertToByteString(args[1].string, args[1].option),
|
||||
mode = args[2].substring(0, 3),
|
||||
mode = args[2].split("/")[0],
|
||||
noPadding = args[2].endsWith("NoPadding"),
|
||||
inputType = args[3],
|
||||
outputType = args[4],
|
||||
|
||||
@@ -66,6 +66,14 @@ class AESEncrypt extends Operation {
|
||||
{
|
||||
name: "ECB",
|
||||
off: [5]
|
||||
},
|
||||
{
|
||||
name: "CBC/NoPadding",
|
||||
off: [5]
|
||||
},
|
||||
{
|
||||
name: "ECB/NoPadding",
|
||||
off: [5]
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -98,7 +106,8 @@ class AESEncrypt extends Operation {
|
||||
run(input, args) {
|
||||
const key = Utils.convertToByteString(args[0].string, args[0].option),
|
||||
iv = Utils.convertToByteString(args[1].string, args[1].option),
|
||||
mode = args[2],
|
||||
mode = args[2].split("/")[0],
|
||||
noPadding = args[2].endsWith("NoPadding"),
|
||||
inputType = args[3],
|
||||
outputType = args[4],
|
||||
aad = Utils.convertToByteString(args[5].string, args[5].option);
|
||||
@@ -114,11 +123,20 @@ The following algorithms will be used based on the size of the key:
|
||||
|
||||
input = Utils.convertToByteString(input, inputType);
|
||||
|
||||
// Handle NoPadding modes
|
||||
if (noPadding && input.length % 16 !== 0) {
|
||||
throw new OperationError("Input length must be a multiple of 16 bytes for NoPadding modes.");
|
||||
}
|
||||
const cipher = forge.cipher.createCipher("AES-" + mode, key);
|
||||
cipher.start({
|
||||
iv: iv,
|
||||
additionalData: mode === "GCM" ? aad : undefined
|
||||
});
|
||||
if (noPadding) {
|
||||
cipher.mode.pad = function(output, options) {
|
||||
return true;
|
||||
};
|
||||
}
|
||||
cipher.update(forge.util.createBuffer(input));
|
||||
cipher.finish();
|
||||
|
||||
|
||||
@@ -22,7 +22,13 @@ class AddLineNumbers extends Operation {
|
||||
this.description = "Adds line numbers to the output.";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
this.args = [
|
||||
{
|
||||
"name": "Offset",
|
||||
"type": "number",
|
||||
"value": 0
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,10 +39,11 @@ class AddLineNumbers extends Operation {
|
||||
run(input, args) {
|
||||
const lines = input.split("\n"),
|
||||
width = lines.length.toString().length;
|
||||
const offset = args[0] ? parseInt(args[0], 10) : 0;
|
||||
let output = "";
|
||||
|
||||
for (let n = 0; n < lines.length; n++) {
|
||||
output += (n+1).toString().padStart(width, " ") + " " + lines[n] + "\n";
|
||||
output += (n+1+offset).toString().padStart(width, " ") + " " + lines[n] + "\n";
|
||||
}
|
||||
return output.slice(0, output.length-1);
|
||||
}
|
||||
|
||||
53
src/core/operations/AlternatingCaps.mjs
Normal file
53
src/core/operations/AlternatingCaps.mjs
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* @author sw5678
|
||||
* @copyright Crown Copyright 2023
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
|
||||
/**
|
||||
* Alternating caps operation
|
||||
*/
|
||||
class AlternatingCaps extends Operation {
|
||||
|
||||
/**
|
||||
* AlternatingCaps constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Alternating Caps";
|
||||
this.module = "Default";
|
||||
this.description = "Alternating caps, also known as studly caps, sticky caps, or spongecase is a form of text notation in which the capitalization of letters varies by some pattern, or arbitrarily. An example of this would be spelling 'alternative caps' as 'aLtErNaTiNg CaPs'.";
|
||||
this.infoURL = "https://en.wikipedia.org/wiki/Alternating_caps";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args= [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
let output = "";
|
||||
let previousCaps = true;
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
// Check if the element is a letter
|
||||
if (!RegExp(/^\p{L}/, "u").test(input[i])) {
|
||||
output += input[i];
|
||||
} else if (previousCaps) {
|
||||
output += input[i].toLowerCase();
|
||||
previousCaps = false;
|
||||
} else {
|
||||
output += input[i].toUpperCase();
|
||||
previousCaps = true;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
export default AlternatingCaps;
|
||||
48
src/core/operations/AnalyseUUID.mjs
Normal file
48
src/core/operations/AnalyseUUID.mjs
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2023
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import * as uuid from "uuid";
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
|
||||
/**
|
||||
* Analyse UUID operation
|
||||
*/
|
||||
class AnalyseUUID extends Operation {
|
||||
|
||||
/**
|
||||
* AnalyseUUID constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Analyse UUID";
|
||||
this.module = "Crypto";
|
||||
this.description = "Tries to determine information about a given UUID and suggests which version may have been used to generate it";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Universally_unique_identifier";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
try {
|
||||
const uuidVersion = uuid.version(input);
|
||||
return "UUID version: " + uuidVersion;
|
||||
} catch (error) {
|
||||
throw new OperationError("Invalid UUID");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default AnalyseUUID;
|
||||
58
src/core/operations/BLAKE3.mjs
Normal file
58
src/core/operations/BLAKE3.mjs
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* @author xumptex [xumptex@outlook.fr]
|
||||
* @copyright Crown Copyright 2025
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import { blake3 } from "hash-wasm";
|
||||
/**
|
||||
* BLAKE3 operation
|
||||
*/
|
||||
class BLAKE3 extends Operation {
|
||||
|
||||
/**
|
||||
* BLAKE3 constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "BLAKE3";
|
||||
this.module = "Hashing";
|
||||
this.description = "Hashes the input using BLAKE3 (UTF-8 encoded), with an optional key (also UTF-8), and outputs the result in hexadecimal format.";
|
||||
this.infoURL = "https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
"name": "Size (bytes)",
|
||||
"type": "number"
|
||||
}, {
|
||||
"name": "Key",
|
||||
"type": "string",
|
||||
"value": ""
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const key = args[1];
|
||||
const size = args[0];
|
||||
// Check if the user want a key hash or not
|
||||
if (key === "") {
|
||||
return blake3(input, size*8);
|
||||
} if (key.length !== 32) {
|
||||
throw new OperationError("The key must be exactly 32 bytes long");
|
||||
}
|
||||
return blake3(input, size*8, key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default BLAKE3;
|
||||
@@ -76,8 +76,8 @@ class BlowfishDecrypt extends Operation {
|
||||
Blowfish's key length needs to be between 4 and 56 bytes (32-448 bits).`);
|
||||
}
|
||||
|
||||
if (iv.length !== 8) {
|
||||
throw new OperationError(`Invalid IV length: ${iv.length} bytes. Expected 8 bytes`);
|
||||
if (mode !== "ECB" && iv.length !== 8) {
|
||||
throw new OperationError(`Invalid IV length: ${iv.length} bytes. Expected 8 bytes.`);
|
||||
}
|
||||
|
||||
input = Utils.convertToByteString(input, inputType);
|
||||
|
||||
@@ -72,12 +72,12 @@ class BlowfishEncrypt extends Operation {
|
||||
|
||||
if (key.length < 4 || key.length > 56) {
|
||||
throw new OperationError(`Invalid key length: ${key.length} bytes
|
||||
|
||||
|
||||
Blowfish's key length needs to be between 4 and 56 bytes (32-448 bits).`);
|
||||
}
|
||||
|
||||
if (iv.length !== 8) {
|
||||
throw new OperationError(`Invalid IV length: ${iv.length} bytes. Expected 8 bytes`);
|
||||
if (mode !== "ECB" && iv.length !== 8) {
|
||||
throw new OperationError(`Invalid IV length: ${iv.length} bytes. Expected 8 bytes.`);
|
||||
}
|
||||
|
||||
input = Utils.convertToByteString(input, inputType);
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
/**
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2016
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import JSCRC from "js-crc";
|
||||
|
||||
/**
|
||||
* CRC-16 Checksum operation
|
||||
*/
|
||||
class CRC16Checksum extends Operation {
|
||||
|
||||
/**
|
||||
* CRC16Checksum constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "CRC-16 Checksum";
|
||||
this.module = "Crypto";
|
||||
this.description = "A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data.<br><br>The CRC was invented by W. Wesley Peterson in 1961.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Cyclic_redundancy_check";
|
||||
this.inputType = "ArrayBuffer";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
return JSCRC.crc16(input);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default CRC16Checksum;
|
||||
@@ -1,41 +0,0 @@
|
||||
/**
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2016
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import JSCRC from "js-crc";
|
||||
|
||||
/**
|
||||
* CRC-32 Checksum operation
|
||||
*/
|
||||
class CRC32Checksum extends Operation {
|
||||
|
||||
/**
|
||||
* CRC32Checksum constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "CRC-32 Checksum";
|
||||
this.module = "Crypto";
|
||||
this.description = "A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data.<br><br>The CRC was invented by W. Wesley Peterson in 1961; the 32-bit CRC function of Ethernet and many other standards is the work of several researchers and was published in 1975.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Cyclic_redundancy_check";
|
||||
this.inputType = "ArrayBuffer";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
return JSCRC.crc32(input);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default CRC32Checksum;
|
||||
@@ -1,157 +0,0 @@
|
||||
/**
|
||||
* @author mshwed [m@ttshwed.com]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
|
||||
import { toHexFast } from "../lib/Hex.mjs";
|
||||
|
||||
/**
|
||||
* CRC-8 Checksum operation
|
||||
*/
|
||||
class CRC8Checksum extends Operation {
|
||||
|
||||
/**
|
||||
* CRC8Checksum constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "CRC-8 Checksum";
|
||||
this.module = "Crypto";
|
||||
this.description = "A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data.<br><br>The CRC was invented by W. Wesley Peterson in 1961.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Cyclic_redundancy_check";
|
||||
this.inputType = "ArrayBuffer";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
"name": "Algorithm",
|
||||
"type": "option",
|
||||
"value": [
|
||||
"CRC-8",
|
||||
"CRC-8/CDMA2000",
|
||||
"CRC-8/DARC",
|
||||
"CRC-8/DVB-S2",
|
||||
"CRC-8/EBU",
|
||||
"CRC-8/I-CODE",
|
||||
"CRC-8/ITU",
|
||||
"CRC-8/MAXIM",
|
||||
"CRC-8/ROHC",
|
||||
"CRC-8/WCDMA"
|
||||
]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the pre-computed lookup table for byte division
|
||||
*
|
||||
* @param polynomial
|
||||
*/
|
||||
calculateCRC8LookupTable(polynomial) {
|
||||
const crc8Table = new Uint8Array(256);
|
||||
|
||||
let currentByte;
|
||||
for (let i = 0; i < 256; i++) {
|
||||
currentByte = i;
|
||||
for (let bit = 0; bit < 8; bit++) {
|
||||
if ((currentByte & 0x80) !== 0) {
|
||||
currentByte <<= 1;
|
||||
currentByte ^= polynomial;
|
||||
} else {
|
||||
currentByte <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
crc8Table[i] = currentByte;
|
||||
}
|
||||
|
||||
return crc8Table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the CRC-8 Checksum from an input
|
||||
*
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {number} polynomial
|
||||
* @param {number} initializationValue
|
||||
* @param {boolean} inputReflection
|
||||
* @param {boolean} outputReflection
|
||||
* @param {number} xorOut
|
||||
*/
|
||||
calculateCRC8(input, polynomial, initializationValue, inputReflection, outputReflection, xorOut) {
|
||||
const crcSize = 8;
|
||||
const crcTable = this.calculateCRC8LookupTable(polynomial);
|
||||
|
||||
let crc = initializationValue !== 0 ? initializationValue : 0;
|
||||
let currentByte, position;
|
||||
|
||||
input = new Uint8Array(input);
|
||||
for (const inputByte of input) {
|
||||
currentByte = inputReflection ? this.reverseBits(inputByte, crcSize) : inputByte;
|
||||
|
||||
position = (currentByte ^ crc) & 255;
|
||||
crc = crcTable[position];
|
||||
}
|
||||
|
||||
crc = outputReflection ? this.reverseBits(crc, crcSize) : crc;
|
||||
|
||||
if (xorOut !== 0) crc = crc ^ xorOut;
|
||||
|
||||
return toHexFast(new Uint8Array([crc]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the bits for a given input byte.
|
||||
*
|
||||
* @param {number} input
|
||||
*/
|
||||
reverseBits(input, hashSize) {
|
||||
let reversedByte = 0;
|
||||
for (let i = hashSize - 1; i >= 0; i--) {
|
||||
reversedByte |= ((input & 1) << i);
|
||||
input >>= 1;
|
||||
}
|
||||
|
||||
return reversedByte;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const algorithm = args[0];
|
||||
|
||||
switch (algorithm) {
|
||||
case "CRC-8":
|
||||
return this.calculateCRC8(input, 0x7, 0x0, false, false, 0x0);
|
||||
case "CRC-8/CDMA2000":
|
||||
return this.calculateCRC8(input, 0x9B, 0xFF, false, false, 0x0);
|
||||
case "CRC-8/DARC":
|
||||
return this.calculateCRC8(input, 0x39, 0x0, true, true, 0x0);
|
||||
case "CRC-8/DVB-S2":
|
||||
return this.calculateCRC8(input, 0xD5, 0x0, false, false, 0x0);
|
||||
case "CRC-8/EBU":
|
||||
return this.calculateCRC8(input, 0x1D, 0xFF, true, true, 0x0);
|
||||
case "CRC-8/I-CODE":
|
||||
return this.calculateCRC8(input, 0x1D, 0xFD, false, false, 0x0);
|
||||
case "CRC-8/ITU":
|
||||
return this.calculateCRC8(input, 0x7, 0x0, false, false, 0x55);
|
||||
case "CRC-8/MAXIM":
|
||||
return this.calculateCRC8(input, 0x31, 0x0, true, true, 0x0);
|
||||
case "CRC-8/ROHC":
|
||||
return this.calculateCRC8(input, 0x7, 0xFF, true, true, 0x0);
|
||||
case "CRC-8/WCDMA":
|
||||
return this.calculateCRC8(input, 0x9B, 0x0, true, true, 0x0);
|
||||
default:
|
||||
throw new OperationError("Unknown checksum algorithm");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default CRC8Checksum;
|
||||
1110
src/core/operations/CRCChecksum.mjs
Normal file
1110
src/core/operations/CRCChecksum.mjs
Normal file
File diff suppressed because it is too large
Load Diff
116
src/core/operations/ConvertLeetSpeak.mjs
Normal file
116
src/core/operations/ConvertLeetSpeak.mjs
Normal file
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* @author bartblaze []
|
||||
* @copyright Crown Copyright 2025
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
|
||||
/**
|
||||
* Convert Leet Speak operation
|
||||
*/
|
||||
class ConvertLeetSpeak extends Operation {
|
||||
/**
|
||||
* ConvertLeetSpeak constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Convert Leet Speak";
|
||||
this.module = "Default";
|
||||
this.description = "Converts to and from Leet Speak.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Leet";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
name: "Direction",
|
||||
type: "option",
|
||||
value: ["To Leet Speak", "From Leet Speak"],
|
||||
defaultIndex: 0
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const direction = args[0];
|
||||
|
||||
if (direction === "To Leet Speak") {
|
||||
return input.replace(/[a-z]/gi, char => {
|
||||
const leetChar = toLeetMap[char.toLowerCase()] || char;
|
||||
return char === char.toUpperCase() ? leetChar.toUpperCase() : leetChar;
|
||||
});
|
||||
} else if (direction === "From Leet Speak") {
|
||||
return input.replace(/[48cd3f6h1jklmn0pqr57uvwxyz]/gi, char => {
|
||||
const normalChar = fromLeetMap[char] || char;
|
||||
return normalChar;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const toLeetMap = {
|
||||
"a": "4",
|
||||
"b": "b",
|
||||
"c": "c",
|
||||
"d": "d",
|
||||
"e": "3",
|
||||
"f": "f",
|
||||
"g": "g",
|
||||
"h": "h",
|
||||
"i": "1",
|
||||
"j": "j",
|
||||
"k": "k",
|
||||
"l": "l",
|
||||
"m": "m",
|
||||
"n": "n",
|
||||
"o": "0",
|
||||
"p": "p",
|
||||
"q": "q",
|
||||
"r": "r",
|
||||
"s": "5",
|
||||
"t": "7",
|
||||
"u": "u",
|
||||
"v": "v",
|
||||
"w": "w",
|
||||
"x": "x",
|
||||
"y": "y",
|
||||
"z": "z"
|
||||
};
|
||||
|
||||
const fromLeetMap = {
|
||||
"4": "a",
|
||||
"b": "b",
|
||||
"c": "c",
|
||||
"d": "d",
|
||||
"3": "e",
|
||||
"f": "f",
|
||||
"g": "g",
|
||||
"h": "h",
|
||||
"1": "i",
|
||||
"j": "j",
|
||||
"k": "k",
|
||||
"l": "l",
|
||||
"m": "m",
|
||||
"n": "n",
|
||||
"0": "o",
|
||||
"p": "p",
|
||||
"q": "q",
|
||||
"r": "r",
|
||||
"5": "s",
|
||||
"7": "t",
|
||||
"u": "u",
|
||||
"v": "v",
|
||||
"w": "w",
|
||||
"x": "x",
|
||||
"y": "y",
|
||||
"z": "z"
|
||||
};
|
||||
|
||||
export default ConvertLeetSpeak;
|
||||
|
||||
@@ -22,7 +22,7 @@ class DESDecrypt extends Operation {
|
||||
|
||||
this.name = "DES Decrypt";
|
||||
this.module = "Ciphers";
|
||||
this.description = "DES is a previously dominant algorithm for encryption, and was published as an official U.S. Federal Information Processing Standard (FIPS). It is now considered to be insecure due to its small key size.<br><br><b>Key:</b> DES uses a key length of 8 bytes (64 bits).<br>Triple DES uses a key length of 24 bytes (192 bits).<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used as a default.";
|
||||
this.description = "DES is a previously dominant algorithm for encryption, and was published as an official U.S. Federal Information Processing Standard (FIPS). It is now considered to be insecure due to its small key size.<br><br><b>Key:</b> DES uses a key length of 8 bytes (64 bits).<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used as a default.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Data_Encryption_Standard";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
@@ -72,8 +72,7 @@ class DESDecrypt extends Operation {
|
||||
if (key.length !== 8) {
|
||||
throw new OperationError(`Invalid key length: ${key.length} bytes
|
||||
|
||||
DES uses a key length of 8 bytes (64 bits).
|
||||
Triple DES uses a key length of 24 bytes (192 bits).`);
|
||||
DES uses a key length of 8 bytes (64 bits).`);
|
||||
}
|
||||
if (iv.length !== 8 && mode !== "ECB") {
|
||||
throw new OperationError(`Invalid IV length: ${iv.length} bytes
|
||||
|
||||
@@ -22,7 +22,7 @@ class DESEncrypt extends Operation {
|
||||
|
||||
this.name = "DES Encrypt";
|
||||
this.module = "Ciphers";
|
||||
this.description = "DES is a previously dominant algorithm for encryption, and was published as an official U.S. Federal Information Processing Standard (FIPS). It is now considered to be insecure due to its small key size.<br><br><b>Key:</b> DES uses a key length of 8 bytes (64 bits).<br>Triple DES uses a key length of 24 bytes (192 bits).<br><br>You can generate a password-based key using one of the KDF operations.<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used.";
|
||||
this.description = "DES is a previously dominant algorithm for encryption, and was published as an official U.S. Federal Information Processing Standard (FIPS). It is now considered to be insecure due to its small key size.<br><br><b>Key:</b> DES uses a key length of 8 bytes (64 bits).<br><br>You can generate a password-based key using one of the KDF operations.<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Data_Encryption_Standard";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
@@ -70,8 +70,7 @@ class DESEncrypt extends Operation {
|
||||
if (key.length !== 8) {
|
||||
throw new OperationError(`Invalid key length: ${key.length} bytes
|
||||
|
||||
DES uses a key length of 8 bytes (64 bits).
|
||||
Triple DES uses a key length of 24 bytes (192 bits).`);
|
||||
DES uses a key length of 8 bytes (64 bits).`);
|
||||
}
|
||||
if (iv.length !== 8 && mode !== "ECB") {
|
||||
throw new OperationError(`Invalid IV length: ${iv.length} bytes
|
||||
|
||||
79
src/core/operations/DropNthBytes.mjs
Normal file
79
src/core/operations/DropNthBytes.mjs
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* @author Oshawk [oshawk@protonmail.com]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
|
||||
/**
|
||||
* Drop nth bytes operation
|
||||
*/
|
||||
class DropNthBytes extends Operation {
|
||||
|
||||
/**
|
||||
* DropNthBytes constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Drop nth bytes";
|
||||
this.module = "Default";
|
||||
this.description = "Drops every nth byte starting with a given byte.";
|
||||
this.infoURL = "";
|
||||
this.inputType = "byteArray";
|
||||
this.outputType = "byteArray";
|
||||
this.args = [
|
||||
{
|
||||
name: "Drop every",
|
||||
type: "number",
|
||||
value: 4
|
||||
},
|
||||
{
|
||||
name: "Starting at",
|
||||
type: "number",
|
||||
value: 0
|
||||
},
|
||||
{
|
||||
name: "Apply to each line",
|
||||
type: "boolean",
|
||||
value: false
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {byteArray} input
|
||||
* @param {Object[]} args
|
||||
* @returns {byteArray}
|
||||
*/
|
||||
run(input, args) {
|
||||
const n = args[0];
|
||||
const start = args[1];
|
||||
const eachLine = args[2];
|
||||
|
||||
if (parseInt(n, 10) !== n || n <= 0) {
|
||||
throw new OperationError("'Drop every' must be a positive integer.");
|
||||
}
|
||||
if (parseInt(start, 10) !== start || start < 0) {
|
||||
throw new OperationError("'Starting at' must be a positive or zero integer.");
|
||||
}
|
||||
|
||||
let offset = 0;
|
||||
const output = [];
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
if (eachLine && input[i] === 0x0a) {
|
||||
output.push(0x0a);
|
||||
offset = i + 1;
|
||||
} else if (i - offset < start || (i - (start + offset)) % n !== 0) {
|
||||
output.push(input[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default DropNthBytes;
|
||||
@@ -9,6 +9,7 @@ import OperationError from "../errors/OperationError.mjs";
|
||||
import { fromBase64 } from "../lib/Base64.mjs";
|
||||
import { toHexFast } from "../lib/Hex.mjs";
|
||||
import r from "jsrsasign";
|
||||
import Utils from "../Utils.mjs";
|
||||
|
||||
/**
|
||||
* ECDSA Verify operation
|
||||
@@ -59,6 +60,11 @@ class ECDSAVerify extends Operation {
|
||||
name: "Message",
|
||||
type: "text",
|
||||
value: ""
|
||||
},
|
||||
{
|
||||
name: "Message format",
|
||||
type: "option",
|
||||
value: ["Raw", "Hex", "Base64"]
|
||||
}
|
||||
];
|
||||
}
|
||||
@@ -70,7 +76,7 @@ class ECDSAVerify extends Operation {
|
||||
*/
|
||||
run(input, args) {
|
||||
let inputFormat = args[0];
|
||||
const [, mdAlgo, keyPem, msg] = args;
|
||||
const [, mdAlgo, keyPem, msg, msgFormat] = args;
|
||||
|
||||
if (keyPem.replace("-----BEGIN PUBLIC KEY-----", "").length === 0) {
|
||||
throw new OperationError("Please enter a public key.");
|
||||
@@ -145,7 +151,8 @@ class ECDSAVerify extends Operation {
|
||||
throw new OperationError("Provided key is not a public key.");
|
||||
}
|
||||
sig.init(key);
|
||||
sig.updateString(msg);
|
||||
const messageStr = Utils.convertToByteString(msg, msgFormat);
|
||||
sig.updateString(messageStr);
|
||||
const result = sig.verify(signatureASN1Hex);
|
||||
return result ? "Verified OK" : "Verification Failure";
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import { search, DOMAIN_REGEX } from "../lib/Extract.mjs";
|
||||
import { search, DOMAIN_REGEX, DMARC_DOMAIN_REGEX } from "../lib/Extract.mjs";
|
||||
import { caseInsensitiveSort } from "../lib/Sort.mjs";
|
||||
|
||||
/**
|
||||
@@ -39,6 +39,11 @@ class ExtractDomains extends Operation {
|
||||
name: "Unique",
|
||||
type: "boolean",
|
||||
value: false
|
||||
},
|
||||
{
|
||||
name: "Underscore (DMARC, DKIM, etc)",
|
||||
type: "boolean",
|
||||
value: false
|
||||
}
|
||||
];
|
||||
}
|
||||
@@ -49,11 +54,11 @@ class ExtractDomains extends Operation {
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const [displayTotal, sort, unique] = args;
|
||||
const [displayTotal, sort, unique, dmarc] = args;
|
||||
|
||||
const results = search(
|
||||
input,
|
||||
DOMAIN_REGEX,
|
||||
dmarc ? DMARC_DOMAIN_REGEX : DOMAIN_REGEX,
|
||||
null,
|
||||
sort ? caseInsensitiveSort : null,
|
||||
unique
|
||||
|
||||
@@ -51,7 +51,7 @@ class ExtractEmailAddresses extends Operation {
|
||||
run(input, args) {
|
||||
const [displayTotal, sort, unique] = args,
|
||||
// email regex from: https://www.regextester.com/98066
|
||||
regex = /(?:[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9](?:[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9-]*[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9])?\.)+[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9](?:[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9-]*[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}\])/ig;
|
||||
regex = /(?:[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9](?:[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9-]*[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9])?\.)+[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9](?:[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9-]*[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\])/ig;
|
||||
|
||||
const results = search(
|
||||
input,
|
||||
|
||||
@@ -21,7 +21,7 @@ class ExtractIPAddresses extends Operation {
|
||||
|
||||
this.name = "Extract IP addresses";
|
||||
this.module = "Regex";
|
||||
this.description = "Extracts all IPv4 and IPv6 addresses.<br><br>Warning: Given a string <code>710.65.0.456</code>, this will match <code>10.65.0.45</code> so always check the original input!";
|
||||
this.description = "Extracts all IPv4 and IPv6 addresses.<br><br>Warning: Given a string <code>1.2.3.4.5.6.7.8</code>, this will match <code>1.2.3.4 and 5.6.7.8</code> so always check the original input!";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
@@ -65,7 +65,21 @@ class ExtractIPAddresses extends Operation {
|
||||
*/
|
||||
run(input, args) {
|
||||
const [includeIpv4, includeIpv6, removeLocal, displayTotal, sort, unique] = args,
|
||||
ipv4 = "(?:(?:\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d|\\d)(?:\\/\\d{1,2})?",
|
||||
|
||||
// IPv4 decimal groups can have values 0 to 255. To construct a regex the following sub-regex is reused:
|
||||
ipv4DecimalByte = "(?:25[0-5]|2[0-4]\\d|1?[0-9]\\d|\\d)",
|
||||
ipv4OctalByte = "(?:0[1-3]?[0-7]{1,2})",
|
||||
|
||||
// Look behind and ahead will be used to exclude matches with additional decimal digits left and right of IP address
|
||||
lookBehind = "(?<!\\d)",
|
||||
lookAhead = "(?!\\d)",
|
||||
|
||||
// Each variant requires exactly 4 groups with literal . between.
|
||||
ipv4Decimal = "(?:" + lookBehind + ipv4DecimalByte + "\\.){3}" + "(?:" + ipv4DecimalByte + lookAhead + ")",
|
||||
ipv4Octal = "(?:" + lookBehind + ipv4OctalByte + "\\.){3}" + "(?:" + ipv4OctalByte + lookAhead + ")",
|
||||
|
||||
// Then we allow IPv4 addresses to be expressed either entirely in decimal or entirely in Octal
|
||||
ipv4 = "(?:" + ipv4Decimal + "|" + ipv4Octal + ")",
|
||||
ipv6 = "((?=.*::)(?!.*::.+::)(::)?([\\dA-F]{1,4}:(:|\\b)|){5}|([\\dA-F]{1,4}:){6})(([\\dA-F]{1,4}((?!\\3)::|:\\b|(?![\\dA-F])))|(?!\\2\\3)){2}";
|
||||
let ips = "";
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import Utils from "../Utils.mjs";
|
||||
import {ALPHABET_OPTIONS} from "../lib/Base32.mjs";
|
||||
|
||||
|
||||
/**
|
||||
* From Base32 operation
|
||||
@@ -27,8 +29,8 @@ class FromBase32 extends Operation {
|
||||
this.args = [
|
||||
{
|
||||
name: "Alphabet",
|
||||
type: "binaryString",
|
||||
value: "A-Z2-7="
|
||||
type: "editableOption",
|
||||
value: ALPHABET_OPTIONS
|
||||
},
|
||||
{
|
||||
name: "Remove non-alphabet chars",
|
||||
@@ -41,6 +43,11 @@ class FromBase32 extends Operation {
|
||||
pattern: "^(?:[A-Z2-7]{8})+(?:[A-Z2-7]{2}={6}|[A-Z2-7]{4}={4}|[A-Z2-7]{5}={3}|[A-Z2-7]{7}={1})?$",
|
||||
flags: "",
|
||||
args: ["A-Z2-7=", false]
|
||||
},
|
||||
{
|
||||
pattern: "^(?:[0-9A-V]{8})+(?:[0-9A-V]{2}={6}|[0-9A-V]{4}={4}|[0-9A-V]{5}={3}|[0-9A-V]{7}={1})?$",
|
||||
flags: "",
|
||||
args: ["0-9A-V=", false]
|
||||
}
|
||||
];
|
||||
}
|
||||
@@ -96,3 +103,4 @@ class FromBase32 extends Operation {
|
||||
}
|
||||
|
||||
export default FromBase32;
|
||||
|
||||
|
||||
84
src/core/operations/FromModhex.mjs
Normal file
84
src/core/operations/FromModhex.mjs
Normal file
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* @author linuxgemini [ilteris@asenkron.com.tr]
|
||||
* @copyright Crown Copyright 2024
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import { FROM_MODHEX_DELIM_OPTIONS, fromModhex } from "../lib/Modhex.mjs";
|
||||
|
||||
/**
|
||||
* From Modhex operation
|
||||
*/
|
||||
class FromModhex extends Operation {
|
||||
|
||||
/**
|
||||
* FromModhex constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "From Modhex";
|
||||
this.module = "Default";
|
||||
this.description = "Converts a modhex byte string back into its raw value.";
|
||||
this.infoURL = "https://en.wikipedia.org/wiki/YubiKey#ModHex";
|
||||
this.inputType = "string";
|
||||
this.outputType = "byteArray";
|
||||
this.args = [
|
||||
{
|
||||
name: "Delimiter",
|
||||
type: "option",
|
||||
value: FROM_MODHEX_DELIM_OPTIONS
|
||||
}
|
||||
];
|
||||
this.checks = [
|
||||
{
|
||||
pattern: "^(?:[cbdefghijklnrtuv]{2})+$",
|
||||
flags: "i",
|
||||
args: ["None"]
|
||||
},
|
||||
{
|
||||
pattern: "^[cbdefghijklnrtuv]{2}(?: [cbdefghijklnrtuv]{2})*$",
|
||||
flags: "i",
|
||||
args: ["Space"]
|
||||
},
|
||||
{
|
||||
pattern: "^[cbdefghijklnrtuv]{2}(?:,[cbdefghijklnrtuv]{2})*$",
|
||||
flags: "i",
|
||||
args: ["Comma"]
|
||||
},
|
||||
{
|
||||
pattern: "^[cbdefghijklnrtuv]{2}(?:;[cbdefghijklnrtuv]{2})*$",
|
||||
flags: "i",
|
||||
args: ["Semi-colon"]
|
||||
},
|
||||
{
|
||||
pattern: "^[cbdefghijklnrtuv]{2}(?::[cbdefghijklnrtuv]{2})*$",
|
||||
flags: "i",
|
||||
args: ["Colon"]
|
||||
},
|
||||
{
|
||||
pattern: "^[cbdefghijklnrtuv]{2}(?:\\n[cbdefghijklnrtuv]{2})*$",
|
||||
flags: "i",
|
||||
args: ["Line feed"]
|
||||
},
|
||||
{
|
||||
pattern: "^[cbdefghijklnrtuv]{2}(?:\\r\\n[cbdefghijklnrtuv]{2})*$",
|
||||
flags: "i",
|
||||
args: ["CRLF"]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {byteArray}
|
||||
*/
|
||||
run(input, args) {
|
||||
const delim = args[0] || "Auto";
|
||||
return fromModhex(input, delim, 2);
|
||||
}
|
||||
}
|
||||
|
||||
export default FromModhex;
|
||||
254
src/core/operations/GenerateAllChecksums.mjs
Normal file
254
src/core/operations/GenerateAllChecksums.mjs
Normal file
@@ -0,0 +1,254 @@
|
||||
/**
|
||||
* @author r4mos [2k95ljkhg@mozmail.com]
|
||||
* @copyright Crown Copyright 2025
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import Adler32Checksum from "./Adler32Checksum.mjs";
|
||||
import CRCChecksum from "./CRCChecksum.mjs";
|
||||
import Fletcher8Checksum from "./Fletcher8Checksum.mjs";
|
||||
import Fletcher16Checksum from "./Fletcher16Checksum.mjs";
|
||||
import Fletcher32Checksum from "./Fletcher32Checksum.mjs";
|
||||
import Fletcher64Checksum from "./Fletcher64Checksum.mjs";
|
||||
|
||||
/**
|
||||
* Generate all checksums operation
|
||||
*/
|
||||
class GenerateAllChecksums extends Operation {
|
||||
|
||||
/**
|
||||
* GenerateAllChecksums constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Generate all checksums";
|
||||
this.module = "Crypto";
|
||||
this.description = "Generates all available checksums for the input.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Checksum";
|
||||
this.inputType = "ArrayBuffer";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
name: "Length (bits)",
|
||||
type: "option",
|
||||
value: [
|
||||
"All", "3", "4", "5", "6", "7", "8", "10", "11", "12", "13", "14", "15", "16", "17", "21", "24", "30", "31", "32", "40", "64", "82"
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Include names",
|
||||
type: "boolean",
|
||||
value: true
|
||||
},
|
||||
];
|
||||
|
||||
const adler32 = new Adler32Checksum;
|
||||
const crc = new CRCChecksum;
|
||||
const fletcher8 = new Fletcher8Checksum;
|
||||
const fletcher16 = new Fletcher16Checksum;
|
||||
const fletcher32 = new Fletcher32Checksum;
|
||||
const fletcher64 = new Fletcher64Checksum;
|
||||
this.checksums = [
|
||||
{name: "CRC-3/GSM", algo: crc, params: ["CRC-3/GSM"]},
|
||||
{name: "CRC-3/ROHC", algo: crc, params: ["CRC-3/ROHC"]},
|
||||
{name: "CRC-4/G-704", algo: crc, params: ["CRC-4/G-704"]},
|
||||
{name: "CRC-4/INTERLAKEN", algo: crc, params: ["CRC-4/INTERLAKEN"]},
|
||||
{name: "CRC-4/ITU", algo: crc, params: ["CRC-4/ITU"]},
|
||||
{name: "CRC-5/EPC", algo: crc, params: ["CRC-5/EPC"]},
|
||||
{name: "CRC-5/EPC-C1G2", algo: crc, params: ["CRC-5/EPC-C1G2"]},
|
||||
{name: "CRC-5/G-704", algo: crc, params: ["CRC-5/G-704"]},
|
||||
{name: "CRC-5/ITU", algo: crc, params: ["CRC-5/ITU"]},
|
||||
{name: "CRC-5/USB", algo: crc, params: ["CRC-5/USB"]},
|
||||
{name: "CRC-6/CDMA2000-A", algo: crc, params: ["CRC-6/CDMA2000-A"]},
|
||||
{name: "CRC-6/CDMA2000-B", algo: crc, params: ["CRC-6/CDMA2000-B"]},
|
||||
{name: "CRC-6/DARC", algo: crc, params: ["CRC-6/DARC"]},
|
||||
{name: "CRC-6/G-704", algo: crc, params: ["CRC-6/G-704"]},
|
||||
{name: "CRC-6/GSM", algo: crc, params: ["CRC-6/GSM"]},
|
||||
{name: "CRC-6/ITU", algo: crc, params: ["CRC-6/ITU"]},
|
||||
{name: "CRC-7/MMC", algo: crc, params: ["CRC-7/MMC"]},
|
||||
{name: "CRC-7/ROHC", algo: crc, params: ["CRC-7/ROHC"]},
|
||||
{name: "CRC-7/UMTS", algo: crc, params: ["CRC-7/UMTS"]},
|
||||
{name: "CRC-8", algo: crc, params: ["CRC-8"]},
|
||||
{name: "CRC-8/8H2F", algo: crc, params: ["CRC-8/8H2F"]},
|
||||
{name: "CRC-8/AES", algo: crc, params: ["CRC-8/AES"]},
|
||||
{name: "CRC-8/AUTOSAR", algo: crc, params: ["CRC-8/AUTOSAR"]},
|
||||
{name: "CRC-8/BLUETOOTH", algo: crc, params: ["CRC-8/BLUETOOTH"]},
|
||||
{name: "CRC-8/CDMA2000", algo: crc, params: ["CRC-8/CDMA2000"]},
|
||||
{name: "CRC-8/DARC", algo: crc, params: ["CRC-8/DARC"]},
|
||||
{name: "CRC-8/DVB-S2", algo: crc, params: ["CRC-8/DVB-S2"]},
|
||||
{name: "CRC-8/EBU", algo: crc, params: ["CRC-8/EBU"]},
|
||||
{name: "CRC-8/GSM-A", algo: crc, params: ["CRC-8/GSM-A"]},
|
||||
{name: "CRC-8/GSM-B", algo: crc, params: ["CRC-8/GSM-B"]},
|
||||
{name: "CRC-8/HITAG", algo: crc, params: ["CRC-8/HITAG"]},
|
||||
{name: "CRC-8/I-432-1", algo: crc, params: ["CRC-8/I-432-1"]},
|
||||
{name: "CRC-8/I-CODE", algo: crc, params: ["CRC-8/I-CODE"]},
|
||||
{name: "CRC-8/ITU", algo: crc, params: ["CRC-8/ITU"]},
|
||||
{name: "CRC-8/LTE", algo: crc, params: ["CRC-8/LTE"]},
|
||||
{name: "CRC-8/MAXIM", algo: crc, params: ["CRC-8/MAXIM"]},
|
||||
{name: "CRC-8/MAXIM-DOW", algo: crc, params: ["CRC-8/MAXIM-DOW"]},
|
||||
{name: "CRC-8/MIFARE-MAD", algo: crc, params: ["CRC-8/MIFARE-MAD"]},
|
||||
{name: "CRC-8/NRSC-5", algo: crc, params: ["CRC-8/NRSC-5"]},
|
||||
{name: "CRC-8/OPENSAFETY", algo: crc, params: ["CRC-8/OPENSAFETY"]},
|
||||
{name: "CRC-8/ROHC", algo: crc, params: ["CRC-8/ROHC"]},
|
||||
{name: "CRC-8/SAE-J1850", algo: crc, params: ["CRC-8/SAE-J1850"]},
|
||||
{name: "CRC-8/SAE-J1850-ZERO", algo: crc, params: ["CRC-8/SAE-J1850-ZERO"]},
|
||||
{name: "CRC-8/SMBUS", algo: crc, params: ["CRC-8/SMBUS"]},
|
||||
{name: "CRC-8/TECH-3250", algo: crc, params: ["CRC-8/TECH-3250"]},
|
||||
{name: "CRC-8/WCDMA", algo: crc, params: ["CRC-8/WCDMA"]},
|
||||
{name: "Fletcher-8", algo: fletcher8, params: []},
|
||||
{name: "CRC-10/ATM", algo: crc, params: ["CRC-10/ATM"]},
|
||||
{name: "CRC-10/CDMA2000", algo: crc, params: ["CRC-10/CDMA2000"]},
|
||||
{name: "CRC-10/GSM", algo: crc, params: ["CRC-10/GSM"]},
|
||||
{name: "CRC-10/I-610", algo: crc, params: ["CRC-10/I-610"]},
|
||||
{name: "CRC-11/FLEXRAY", algo: crc, params: ["CRC-11/FLEXRAY"]},
|
||||
{name: "CRC-11/UMTS", algo: crc, params: ["CRC-11/UMTS"]},
|
||||
{name: "CRC-12/3GPP", algo: crc, params: ["CRC-12/3GPP"]},
|
||||
{name: "CRC-12/CDMA2000", algo: crc, params: ["CRC-12/CDMA2000"]},
|
||||
{name: "CRC-12/DECT", algo: crc, params: ["CRC-12/DECT"]},
|
||||
{name: "CRC-12/GSM", algo: crc, params: ["CRC-12/GSM"]},
|
||||
{name: "CRC-12/UMTS", algo: crc, params: ["CRC-12/UMTS"]},
|
||||
{name: "CRC-13/BBC", algo: crc, params: ["CRC-13/BBC"]},
|
||||
{name: "CRC-14/DARC", algo: crc, params: ["CRC-14/DARC"]},
|
||||
{name: "CRC-14/GSM", algo: crc, params: ["CRC-14/GSM"]},
|
||||
{name: "CRC-15/CAN", algo: crc, params: ["CRC-15/CAN"]},
|
||||
{name: "CRC-15/MPT1327", algo: crc, params: ["CRC-15/MPT1327"]},
|
||||
{name: "CRC-16", algo: crc, params: ["CRC-16"]},
|
||||
{name: "CRC-16/A", algo: crc, params: ["CRC-16/A"]},
|
||||
{name: "CRC-16/ACORN", algo: crc, params: ["CRC-16/ACORN"]},
|
||||
{name: "CRC-16/ARC", algo: crc, params: ["CRC-16/ARC"]},
|
||||
{name: "CRC-16/AUG-CCITT", algo: crc, params: ["CRC-16/AUG-CCITT"]},
|
||||
{name: "CRC-16/AUTOSAR", algo: crc, params: ["CRC-16/AUTOSAR"]},
|
||||
{name: "CRC-16/B", algo: crc, params: ["CRC-16/B"]},
|
||||
{name: "CRC-16/BLUETOOTH", algo: crc, params: ["CRC-16/BLUETOOTH"]},
|
||||
{name: "CRC-16/BUYPASS", algo: crc, params: ["CRC-16/BUYPASS"]},
|
||||
{name: "CRC-16/CCITT", algo: crc, params: ["CRC-16/CCITT"]},
|
||||
{name: "CRC-16/CCITT-FALSE", algo: crc, params: ["CRC-16/CCITT-FALSE"]},
|
||||
{name: "CRC-16/CCITT-TRUE", algo: crc, params: ["CRC-16/CCITT-TRUE"]},
|
||||
{name: "CRC-16/CCITT-ZERO", algo: crc, params: ["CRC-16/CCITT-ZERO"]},
|
||||
{name: "CRC-16/CDMA2000", algo: crc, params: ["CRC-16/CDMA2000"]},
|
||||
{name: "CRC-16/CMS", algo: crc, params: ["CRC-16/CMS"]},
|
||||
{name: "CRC-16/DARC", algo: crc, params: ["CRC-16/DARC"]},
|
||||
{name: "CRC-16/DDS-110", algo: crc, params: ["CRC-16/DDS-110"]},
|
||||
{name: "CRC-16/DECT-R", algo: crc, params: ["CRC-16/DECT-R"]},
|
||||
{name: "CRC-16/DECT-X", algo: crc, params: ["CRC-16/DECT-X"]},
|
||||
{name: "CRC-16/DNP", algo: crc, params: ["CRC-16/DNP"]},
|
||||
{name: "CRC-16/EN-13757", algo: crc, params: ["CRC-16/EN-13757"]},
|
||||
{name: "CRC-16/EPC", algo: crc, params: ["CRC-16/EPC"]},
|
||||
{name: "CRC-16/EPC-C1G2", algo: crc, params: ["CRC-16/EPC-C1G2"]},
|
||||
{name: "CRC-16/GENIBUS", algo: crc, params: ["CRC-16/GENIBUS"]},
|
||||
{name: "CRC-16/GSM", algo: crc, params: ["CRC-16/GSM"]},
|
||||
{name: "CRC-16/I-CODE", algo: crc, params: ["CRC-16/I-CODE"]},
|
||||
{name: "CRC-16/IBM", algo: crc, params: ["CRC-16/IBM"]},
|
||||
{name: "CRC-16/IBM-3740", algo: crc, params: ["CRC-16/IBM-3740"]},
|
||||
{name: "CRC-16/IBM-SDLC", algo: crc, params: ["CRC-16/IBM-SDLC"]},
|
||||
{name: "CRC-16/IEC-61158-2", algo: crc, params: ["CRC-16/IEC-61158-2"]},
|
||||
{name: "CRC-16/ISO-HDLC", algo: crc, params: ["CRC-16/ISO-HDLC"]},
|
||||
{name: "CRC-16/ISO-IEC-14443-3-A", algo: crc, params: ["CRC-16/ISO-IEC-14443-3-A"]},
|
||||
{name: "CRC-16/ISO-IEC-14443-3-B", algo: crc, params: ["CRC-16/ISO-IEC-14443-3-B"]},
|
||||
{name: "CRC-16/KERMIT", algo: crc, params: ["CRC-16/KERMIT"]},
|
||||
{name: "CRC-16/LHA", algo: crc, params: ["CRC-16/LHA"]},
|
||||
{name: "CRC-16/LJ1200", algo: crc, params: ["CRC-16/LJ1200"]},
|
||||
{name: "CRC-16/LTE", algo: crc, params: ["CRC-16/LTE"]},
|
||||
{name: "CRC-16/M17", algo: crc, params: ["CRC-16/M17"]},
|
||||
{name: "CRC-16/MAXIM", algo: crc, params: ["CRC-16/MAXIM"]},
|
||||
{name: "CRC-16/MAXIM-DOW", algo: crc, params: ["CRC-16/MAXIM-DOW"]},
|
||||
{name: "CRC-16/MCRF4XX", algo: crc, params: ["CRC-16/MCRF4XX"]},
|
||||
{name: "CRC-16/MODBUS", algo: crc, params: ["CRC-16/MODBUS"]},
|
||||
{name: "CRC-16/NRSC-5", algo: crc, params: ["CRC-16/NRSC-5"]},
|
||||
{name: "CRC-16/OPENSAFETY-A", algo: crc, params: ["CRC-16/OPENSAFETY-A"]},
|
||||
{name: "CRC-16/OPENSAFETY-B", algo: crc, params: ["CRC-16/OPENSAFETY-B"]},
|
||||
{name: "CRC-16/PROFIBUS", algo: crc, params: ["CRC-16/PROFIBUS"]},
|
||||
{name: "CRC-16/RIELLO", algo: crc, params: ["CRC-16/RIELLO"]},
|
||||
{name: "CRC-16/SPI-FUJITSU", algo: crc, params: ["CRC-16/SPI-FUJITSU"]},
|
||||
{name: "CRC-16/T10-DIF", algo: crc, params: ["CRC-16/T10-DIF"]},
|
||||
{name: "CRC-16/TELEDISK", algo: crc, params: ["CRC-16/TELEDISK"]},
|
||||
{name: "CRC-16/TMS37157", algo: crc, params: ["CRC-16/TMS37157"]},
|
||||
{name: "CRC-16/UMTS", algo: crc, params: ["CRC-16/UMTS"]},
|
||||
{name: "CRC-16/USB", algo: crc, params: ["CRC-16/USB"]},
|
||||
{name: "CRC-16/V-41-LSB", algo: crc, params: ["CRC-16/V-41-LSB"]},
|
||||
{name: "CRC-16/V-41-MSB", algo: crc, params: ["CRC-16/V-41-MSB"]},
|
||||
{name: "CRC-16/VERIFONE", algo: crc, params: ["CRC-16/VERIFONE"]},
|
||||
{name: "CRC-16/X-25", algo: crc, params: ["CRC-16/X-25"]},
|
||||
{name: "CRC-16/XMODEM", algo: crc, params: ["CRC-16/XMODEM"]},
|
||||
{name: "CRC-16/ZMODEM", algo: crc, params: ["CRC-16/ZMODEM"]},
|
||||
{name: "Fletcher-16", algo: fletcher16, params: []},
|
||||
{name: "CRC-17/CAN-FD", algo: crc, params: ["CRC-17/CAN-FD"]},
|
||||
{name: "CRC-21/CAN-FD", algo: crc, params: ["CRC-21/CAN-FD"]},
|
||||
{name: "CRC-24/BLE", algo: crc, params: ["CRC-24/BLE"]},
|
||||
{name: "CRC-24/FLEXRAY-A", algo: crc, params: ["CRC-24/FLEXRAY-A"]},
|
||||
{name: "CRC-24/FLEXRAY-B", algo: crc, params: ["CRC-24/FLEXRAY-B"]},
|
||||
{name: "CRC-24/INTERLAKEN", algo: crc, params: ["CRC-24/INTERLAKEN"]},
|
||||
{name: "CRC-24/LTE-A", algo: crc, params: ["CRC-24/LTE-A"]},
|
||||
{name: "CRC-24/LTE-B", algo: crc, params: ["CRC-24/LTE-B"]},
|
||||
{name: "CRC-24/OPENPGP", algo: crc, params: ["CRC-24/OPENPGP"]},
|
||||
{name: "CRC-24/OS-9", algo: crc, params: ["CRC-24/OS-9"]},
|
||||
{name: "CRC-30/CDMA", algo: crc, params: ["CRC-30/CDMA"]},
|
||||
{name: "CRC-31/PHILIPS", algo: crc, params: ["CRC-31/PHILIPS"]},
|
||||
{name: "Adler-32", algo: adler32, params: []},
|
||||
{name: "CRC-32", algo: crc, params: ["CRC-32"]},
|
||||
{name: "CRC-32/AAL5", algo: crc, params: ["CRC-32/AAL5"]},
|
||||
{name: "CRC-32/ADCCP", algo: crc, params: ["CRC-32/ADCCP"]},
|
||||
{name: "CRC-32/AIXM", algo: crc, params: ["CRC-32/AIXM"]},
|
||||
{name: "CRC-32/AUTOSAR", algo: crc, params: ["CRC-32/AUTOSAR"]},
|
||||
{name: "CRC-32/BASE91-C", algo: crc, params: ["CRC-32/BASE91-C"]},
|
||||
{name: "CRC-32/BASE91-D", algo: crc, params: ["CRC-32/BASE91-D"]},
|
||||
{name: "CRC-32/BZIP2", algo: crc, params: ["CRC-32/BZIP2"]},
|
||||
{name: "CRC-32/C", algo: crc, params: ["CRC-32/C"]},
|
||||
{name: "CRC-32/CASTAGNOLI", algo: crc, params: ["CRC-32/CASTAGNOLI"]},
|
||||
{name: "CRC-32/CD-ROM-EDC", algo: crc, params: ["CRC-32/CD-ROM-EDC"]},
|
||||
{name: "CRC-32/CKSUM", algo: crc, params: ["CRC-32/CKSUM"]},
|
||||
{name: "CRC-32/D", algo: crc, params: ["CRC-32/D"]},
|
||||
{name: "CRC-32/DECT-B", algo: crc, params: ["CRC-32/DECT-B"]},
|
||||
{name: "CRC-32/INTERLAKEN", algo: crc, params: ["CRC-32/INTERLAKEN"]},
|
||||
{name: "CRC-32/ISCSI", algo: crc, params: ["CRC-32/ISCSI"]},
|
||||
{name: "CRC-32/ISO-HDLC", algo: crc, params: ["CRC-32/ISO-HDLC"]},
|
||||
{name: "CRC-32/JAMCRC", algo: crc, params: ["CRC-32/JAMCRC"]},
|
||||
{name: "CRC-32/MEF", algo: crc, params: ["CRC-32/MEF"]},
|
||||
{name: "CRC-32/MPEG-2", algo: crc, params: ["CRC-32/MPEG-2"]},
|
||||
{name: "CRC-32/NVME", algo: crc, params: ["CRC-32/NVME"]},
|
||||
{name: "CRC-32/PKZIP", algo: crc, params: ["CRC-32/PKZIP"]},
|
||||
{name: "CRC-32/POSIX", algo: crc, params: ["CRC-32/POSIX"]},
|
||||
{name: "CRC-32/Q", algo: crc, params: ["CRC-32/Q"]},
|
||||
{name: "CRC-32/SATA", algo: crc, params: ["CRC-32/SATA"]},
|
||||
{name: "CRC-32/V-42", algo: crc, params: ["CRC-32/V-42"]},
|
||||
{name: "CRC-32/XFER", algo: crc, params: ["CRC-32/XFER"]},
|
||||
{name: "CRC-32/XZ", algo: crc, params: ["CRC-32/XZ"]},
|
||||
{name: "Fletcher-32", algo: fletcher32, params: []},
|
||||
{name: "CRC-40/GSM", algo: crc, params: ["CRC-40/GSM"]},
|
||||
{name: "CRC-64/ECMA-182", algo: crc, params: ["CRC-64/ECMA-182"]},
|
||||
{name: "CRC-64/GO-ECMA", algo: crc, params: ["CRC-64/GO-ECMA"]},
|
||||
{name: "CRC-64/GO-ISO", algo: crc, params: ["CRC-64/GO-ISO"]},
|
||||
{name: "CRC-64/MS", algo: crc, params: ["CRC-64/MS"]},
|
||||
{name: "CRC-64/NVME", algo: crc, params: ["CRC-64/NVME"]},
|
||||
{name: "CRC-64/REDIS", algo: crc, params: ["CRC-64/REDIS"]},
|
||||
{name: "CRC-64/WE", algo: crc, params: ["CRC-64/WE"]},
|
||||
{name: "CRC-64/XZ", algo: crc, params: ["CRC-64/XZ"]},
|
||||
{name: "Fletcher-64", algo: fletcher64, params: []},
|
||||
{name: "CRC-82/DARC", algo: crc, params: ["CRC-82/DARC"]}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const [length, includeNames] = args;
|
||||
let output = "";
|
||||
this.checksums.forEach(checksum => {
|
||||
const checksumLength = checksum.name.match(new RegExp("-(\\d{1,2})(\\/|$)"))[1];
|
||||
if (length === "All" || length === checksumLength) {
|
||||
const value = checksum.algo.run(new Uint8Array(input), checksum.params || []);
|
||||
output += includeNames ?
|
||||
`${checksum.name}:${" ".repeat(25-checksum.name.length)}${value}\n`:
|
||||
`${value}\n`;
|
||||
}
|
||||
});
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
export default GenerateAllChecksums;
|
||||
@@ -22,14 +22,6 @@ import HAS160 from "./HAS160.mjs";
|
||||
import Whirlpool from "./Whirlpool.mjs";
|
||||
import SSDEEP from "./SSDEEP.mjs";
|
||||
import CTPH from "./CTPH.mjs";
|
||||
import Fletcher8Checksum from "./Fletcher8Checksum.mjs";
|
||||
import Fletcher16Checksum from "./Fletcher16Checksum.mjs";
|
||||
import Fletcher32Checksum from "./Fletcher32Checksum.mjs";
|
||||
import Fletcher64Checksum from "./Fletcher64Checksum.mjs";
|
||||
import Adler32Checksum from "./Adler32Checksum.mjs";
|
||||
import CRC8Checksum from "./CRC8Checksum.mjs";
|
||||
import CRC16Checksum from "./CRC16Checksum.mjs";
|
||||
import CRC32Checksum from "./CRC32Checksum.mjs";
|
||||
import BLAKE2b from "./BLAKE2b.mjs";
|
||||
import BLAKE2s from "./BLAKE2s.mjs";
|
||||
import Streebog from "./Streebog.mjs";
|
||||
@@ -114,16 +106,6 @@ class GenerateAllHashes extends Operation {
|
||||
{name: "SSDEEP", algo: (new SSDEEP()), inputType: "str"},
|
||||
{name: "CTPH", algo: (new CTPH()), inputType: "str"}
|
||||
];
|
||||
this.checksums = [
|
||||
{name: "Fletcher-8", algo: (new Fletcher8Checksum), inputType: "byteArray", params: []},
|
||||
{name: "Fletcher-16", algo: (new Fletcher16Checksum), inputType: "byteArray", params: []},
|
||||
{name: "Fletcher-32", algo: (new Fletcher32Checksum), inputType: "byteArray", params: []},
|
||||
{name: "Fletcher-64", algo: (new Fletcher64Checksum), inputType: "byteArray", params: []},
|
||||
{name: "Adler-32", algo: (new Adler32Checksum), inputType: "byteArray", params: []},
|
||||
{name: "CRC-8", algo: (new CRC8Checksum), inputType: "arrayBuffer", params: ["CRC-8"]},
|
||||
{name: "CRC-16", algo: (new CRC16Checksum), inputType: "arrayBuffer", params: []},
|
||||
{name: "CRC-32", algo: (new CRC32Checksum), inputType: "arrayBuffer", params: []}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,14 +126,6 @@ class GenerateAllHashes extends Operation {
|
||||
output += this.formatDigest(digest, length, includeNames, hash.name);
|
||||
});
|
||||
|
||||
if (length === "All") {
|
||||
output += "\nChecksums:\n";
|
||||
this.checksums.forEach(checksum => {
|
||||
digest = this.executeAlgo(checksum.algo, checksum.inputType, checksum.params || []);
|
||||
output += this.formatDigest(digest, length, includeNames, checksum.name);
|
||||
});
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,16 +5,14 @@
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import otp from "otp";
|
||||
import ToBase32 from "./ToBase32.mjs";
|
||||
import * as OTPAuth from "otpauth";
|
||||
|
||||
/**
|
||||
* Generate HOTP operation
|
||||
*/
|
||||
class GenerateHOTP extends Operation {
|
||||
|
||||
/**
|
||||
* GenerateHOTP constructor
|
||||
*
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
@@ -31,11 +29,6 @@ class GenerateHOTP extends Operation {
|
||||
"type": "string",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"name": "Key size",
|
||||
"type": "number",
|
||||
"value": 32
|
||||
},
|
||||
{
|
||||
"name": "Code length",
|
||||
"type": "number",
|
||||
@@ -50,21 +43,26 @@ class GenerateHOTP extends Operation {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*
|
||||
*/
|
||||
run(input, args) {
|
||||
const otpObj = otp({
|
||||
name: args[0],
|
||||
keySize: args[1],
|
||||
codeLength: args[2],
|
||||
secret: (new ToBase32).run(input, []).split("=")[0],
|
||||
});
|
||||
const counter = args[3];
|
||||
return `URI: ${otpObj.hotpURL}\n\nPassword: ${otpObj.hotp(counter)}`;
|
||||
}
|
||||
const secretStr = new TextDecoder("utf-8").decode(input).trim();
|
||||
const secret = secretStr ? secretStr.toUpperCase().replace(/\s+/g, "") : "";
|
||||
|
||||
const hotp = new OTPAuth.HOTP({
|
||||
issuer: "",
|
||||
label: args[0],
|
||||
algorithm: "SHA1",
|
||||
digits: args[1],
|
||||
counter: args[2],
|
||||
secret: OTPAuth.Secret.fromBase32(secret)
|
||||
});
|
||||
|
||||
const uri = hotp.toString();
|
||||
const code = hotp.generate();
|
||||
|
||||
return `URI: ${uri}\n\nPassword: ${code}`;
|
||||
}
|
||||
}
|
||||
|
||||
export default GenerateHOTP;
|
||||
|
||||
@@ -5,20 +5,17 @@
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import otp from "otp";
|
||||
import ToBase32 from "./ToBase32.mjs";
|
||||
import * as OTPAuth from "otpauth";
|
||||
|
||||
/**
|
||||
* Generate TOTP operation
|
||||
*/
|
||||
class GenerateTOTP extends Operation {
|
||||
|
||||
/**
|
||||
* GenerateTOTP constructor
|
||||
*
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Generate TOTP";
|
||||
this.module = "Default";
|
||||
this.description = "The Time-based One-Time Password algorithm (TOTP) is an algorithm that computes a one-time password from a shared secret key and the current time. It has been adopted as Internet Engineering Task Force standard RFC 6238, is the cornerstone of Initiative For Open Authentication (OAUTH), and is used in a number of two-factor authentication systems. A TOTP is an HOTP where the counter is the current time.<br><br>Enter the secret as the input or leave it blank for a random secret to be generated. T0 and T1 are in seconds.";
|
||||
@@ -31,11 +28,6 @@ class GenerateTOTP extends Operation {
|
||||
"type": "string",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"name": "Key size",
|
||||
"type": "number",
|
||||
"value": 32
|
||||
},
|
||||
{
|
||||
"name": "Code length",
|
||||
"type": "number",
|
||||
@@ -55,22 +47,27 @@ class GenerateTOTP extends Operation {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*
|
||||
*/
|
||||
run(input, args) {
|
||||
const otpObj = otp({
|
||||
name: args[0],
|
||||
keySize: args[1],
|
||||
codeLength: args[2],
|
||||
secret: (new ToBase32).run(input, []).split("=")[0],
|
||||
epoch: args[3],
|
||||
timeSlice: args[4]
|
||||
});
|
||||
return `URI: ${otpObj.totpURL}\n\nPassword: ${otpObj.totp()}`;
|
||||
}
|
||||
const secretStr = new TextDecoder("utf-8").decode(input).trim();
|
||||
const secret = secretStr ? secretStr.toUpperCase().replace(/\s+/g, "") : "";
|
||||
|
||||
const totp = new OTPAuth.TOTP({
|
||||
issuer: "",
|
||||
label: args[0],
|
||||
algorithm: "SHA1",
|
||||
digits: args[1],
|
||||
period: args[3],
|
||||
epoch: args[2] * 1000, // Convert seconds to milliseconds
|
||||
secret: OTPAuth.Secret.fromBase32(secret)
|
||||
});
|
||||
|
||||
const uri = totp.toString();
|
||||
const code = totp.generate();
|
||||
|
||||
return `URI: ${uri}\n\nPassword: ${code}`;
|
||||
}
|
||||
}
|
||||
|
||||
export default GenerateTOTP;
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import crypto from "crypto";
|
||||
|
||||
import * as uuid from "uuid";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
/**
|
||||
* Generate UUID operation
|
||||
*/
|
||||
@@ -20,11 +20,38 @@ class GenerateUUID extends Operation {
|
||||
|
||||
this.name = "Generate UUID";
|
||||
this.module = "Crypto";
|
||||
this.description = "Generates an RFC 4122 version 4 compliant Universally Unique Identifier (UUID), also known as a Globally Unique Identifier (GUID).<br><br>A version 4 UUID relies on random numbers, in this case generated using <code>window.crypto</code> if available and falling back to <code>Math.random</code> if not.";
|
||||
this.description =
|
||||
"Generates an RFC 9562 (formerly RFC 4122) compliant Universally Unique Identifier (UUID), " +
|
||||
"also known as a Globally Unique Identifier (GUID).<br>" +
|
||||
"<br>" +
|
||||
"We currently support generating the following UUID versions:<br>" +
|
||||
"<ul>" +
|
||||
"<li><strong>v1</strong>: Timestamp-based</li>" +
|
||||
"<li><strong>v3</strong>: Namespace w/ MD5</li>" +
|
||||
"<li><strong>v4</strong>: Random (default)</li>" +
|
||||
"<li><strong>v5</strong>: Namespace w/ SHA-1</li>" +
|
||||
"<li><strong>v6</strong>: Timestamp, reordered</li>" +
|
||||
"<li><strong>v7</strong>: Unix Epoch time-based</li>" +
|
||||
"</ul>" +
|
||||
"UUIDs are generated using the <a href='https://npmjs.org/uuid/'><code>uuid</code><a> package.<br>";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Universally_unique_identifier";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
this.args = [
|
||||
{
|
||||
name: "Version",
|
||||
hint: "UUID version",
|
||||
type: "option",
|
||||
value: ["v1", "v3", "v4", "v5", "v6", "v7"],
|
||||
defaultIndex: 2,
|
||||
},
|
||||
{
|
||||
name: "Namespace",
|
||||
hint: "UUID namespace (UUID; valid for v3 and v5)",
|
||||
type: "string",
|
||||
value: "1b671a64-40d5-491e-99b0-da01ff1f3341"
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,16 +60,17 @@ class GenerateUUID extends Operation {
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const buf = new Uint32Array(4).map(() => {
|
||||
return crypto.randomBytes(4).readUInt32BE(0, true);
|
||||
});
|
||||
let i = 0;
|
||||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
||||
const r = (buf[i >> 3] >> ((i % 8) * 4)) & 0xf,
|
||||
v = c === "x" ? r : (r & 0x3 | 0x8);
|
||||
i++;
|
||||
return v.toString(16);
|
||||
});
|
||||
const [version, namespace] = args;
|
||||
const hasDesiredVersion = typeof uuid[version] === "function";
|
||||
if (!hasDesiredVersion) throw new OperationError("Invalid UUID version");
|
||||
|
||||
const requiresNamespace = ["v3", "v5"].includes(version);
|
||||
if (!requiresNamespace) return uuid[version]();
|
||||
|
||||
const hasValidNamespace = typeof namespace === "string" && uuid.validate(namespace);
|
||||
if (!hasValidNamespace) throw new OperationError("Invalid UUID namespace");
|
||||
|
||||
return uuid[version](input, namespace);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
209
src/core/operations/IPv6TransitionAddresses.mjs
Normal file
209
src/core/operations/IPv6TransitionAddresses.mjs
Normal file
@@ -0,0 +1,209 @@
|
||||
/**
|
||||
* @author jb30795 [jb30795@proton.me]
|
||||
* @copyright Crown Copyright 2024
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
|
||||
/**
|
||||
* IPv6 Transition Addresses operation
|
||||
*/
|
||||
class IPv6TransitionAddresses extends Operation {
|
||||
|
||||
/**
|
||||
* IPv6TransitionAddresses constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "IPv6 Transition Addresses";
|
||||
this.module = "Default";
|
||||
this.description = "Converts IPv4 addresses to their IPv6 Transition addresses. IPv6 Transition addresses can also be converted back into their original IPv4 address. MAC addresses can also be converted into the EUI-64 format, this can them be appended to your IPv6 /64 range to obtain a full /128 address.<br><br>Transition technologies enable translation between IPv4 and IPv6 addresses or tunneling to allow traffic to pass through the incompatible network, allowing the two standards to coexist.<br><br>Only /24 ranges and currently handled. Remove headers to easily copy out results.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/IPv6_transition_mechanism";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
"name": "Ignore ranges",
|
||||
"type": "boolean",
|
||||
"value": true
|
||||
},
|
||||
{
|
||||
"name": "Remove headers",
|
||||
"type": "boolean",
|
||||
"value": false
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const XOR = {"0": "2", "1": "3", "2": "0", "3": "1", "4": "6", "5": "7", "6": "4", "7": "5", "8": "a", "9": "b", "a": "8", "b": "9", "c": "e", "d": "f", "e": "c", "f": "d"};
|
||||
|
||||
/**
|
||||
* Function to convert to hex
|
||||
*/
|
||||
function hexify(octet) {
|
||||
return Number(octet).toString(16).padStart(2, "0");
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to convert Hex to Int
|
||||
*/
|
||||
function intify(hex) {
|
||||
return parseInt(hex, 16);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function converts IPv4 to IPv6 Transtion address
|
||||
*/
|
||||
function ipTransition(input, range) {
|
||||
let output = "";
|
||||
const HEXIP = input.split(".");
|
||||
|
||||
/**
|
||||
* 6to4
|
||||
*/
|
||||
if (!args[1]) {
|
||||
output += "6to4: ";
|
||||
}
|
||||
output += "2002:" + hexify(HEXIP[0]) + hexify(HEXIP[1]) + ":" + hexify(HEXIP[2]);
|
||||
if (range) {
|
||||
output += "00::/40\n";
|
||||
} else {
|
||||
output += hexify(HEXIP[3]) + "::/48\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Mapped
|
||||
*/
|
||||
if (!args[1]) {
|
||||
output += "IPv4 Mapped: ";
|
||||
}
|
||||
output += "::ffff:" + hexify(HEXIP[0]) + hexify(HEXIP[1]) + ":" + hexify(HEXIP[2]);
|
||||
if (range) {
|
||||
output += "00/120\n";
|
||||
} else {
|
||||
output += hexify(HEXIP[3]) + "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Translated
|
||||
*/
|
||||
if (!args[1]) {
|
||||
output += "IPv4 Translated: ";
|
||||
}
|
||||
output += "::ffff:0:" + hexify(HEXIP[0]) + hexify(HEXIP[1]) + ":" + hexify(HEXIP[2]);
|
||||
if (range) {
|
||||
output += "00/120\n";
|
||||
} else {
|
||||
output += hexify(HEXIP[3]) + "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Nat64
|
||||
*/
|
||||
if (!args[1]) {
|
||||
output += "Nat 64: ";
|
||||
}
|
||||
output += "64:ff9b::" + hexify(HEXIP[0]) + hexify(HEXIP[1]) + ":" + hexify(HEXIP[2]);
|
||||
if (range) {
|
||||
output += "00/120\n";
|
||||
} else {
|
||||
output += hexify(HEXIP[3]) + "\n";
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert MAC to EUI-64
|
||||
*/
|
||||
function macTransition(input) {
|
||||
let output = "";
|
||||
const MACPARTS = input.split(":");
|
||||
if (!args[1]) {
|
||||
output += "EUI-64 Interface ID: ";
|
||||
}
|
||||
const MAC = MACPARTS[0] + MACPARTS[1] + ":" + MACPARTS[2] + "ff:fe" + MACPARTS[3] + ":" + MACPARTS[4] + MACPARTS[5];
|
||||
output += MAC.slice(0, 1) + XOR[MAC.slice(1, 2)] + MAC.slice(2);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert IPv6 address to its original IPv4 or MAC address
|
||||
*/
|
||||
function unTransition(input) {
|
||||
let output = "";
|
||||
let hextets = "";
|
||||
|
||||
/**
|
||||
* 6to4
|
||||
*/
|
||||
if (input.startsWith("2002:")) {
|
||||
if (!args[1]) {
|
||||
output += "IPv4: ";
|
||||
}
|
||||
output += String(intify(input.slice(5, 7))) + "." + String(intify(input.slice(7, 9)))+ "." + String(intify(input.slice(10, 12)))+ "." + String(intify(input.slice(12, 14))) + "\n";
|
||||
} else if (input.startsWith("::ffff:") || input.startsWith("0000:0000:0000:0000:0000:ffff:") || input.startsWith("::ffff:0000:") || input.startsWith("0000:0000:0000:0000:ffff:0000:") || input.startsWith("64:ff9b::") || input.startsWith("0064:ff9b:0000:0000:0000:0000:")) {
|
||||
/**
|
||||
* Mapped/Translated/Nat64
|
||||
*/
|
||||
hextets = /:([0-9a-z]{1,4}):[0-9a-z]{1,4}$/.exec(input)[1].padStart(4, "0") + /:([0-9a-z]{1,4})$/.exec(input)[1].padStart(4, "0");
|
||||
if (!args[1]) {
|
||||
output += "IPv4: ";
|
||||
}
|
||||
output += intify(hextets.slice(-8, -7) + hextets.slice(-7, -6)) + "." +intify(hextets.slice(-6, -5) + hextets.slice(-5, -4)) + "." +intify(hextets.slice(-4, -3) + hextets.slice(-3, -2)) + "." +intify(hextets.slice(-2, -1) + hextets.slice(-1,)) + "\n";
|
||||
} else if (input.slice(-12, -7).toUpperCase() === "FF:FE") {
|
||||
/**
|
||||
* EUI-64
|
||||
*/
|
||||
if (!args[1]) {
|
||||
output += "Mac Address: ";
|
||||
}
|
||||
const MAC = (input.slice(-19, -17) + ":" + input.slice(-17, -15) + ":" + input.slice(-14, -12) + ":" + input.slice(-7, -5) + ":" + input.slice(-4, -2) + ":" + input.slice(-2,)).toUpperCase();
|
||||
output += MAC.slice(0, 1) + XOR[MAC.slice(1, 2)] + MAC.slice(2) + "\n";
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Main
|
||||
*/
|
||||
let output = "";
|
||||
let inputs = input.split("\n");
|
||||
// Remove blank rows
|
||||
inputs = inputs.filter(Boolean);
|
||||
|
||||
for (let i = 0; i < inputs.length; i++) {
|
||||
// if ignore ranges is checked and input is a range, skip
|
||||
if ((args[0] && !inputs[i].includes("/")) || (!args[0])) {
|
||||
if (/^[0-9]{1,3}(?:\.[0-9]{1,3}){3}$/.test(inputs[i])) {
|
||||
output += ipTransition(inputs[i], false);
|
||||
} else if (/\/24$/.test(inputs[i])) {
|
||||
output += ipTransition(inputs[i], true);
|
||||
} else if (/^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$/.test(inputs[i])) {
|
||||
output += macTransition(inputs[i]);
|
||||
} else if (/^((?:[0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:(?:(?::[0-9a-fA-F]{1,4}){1,6})|:(?:(?::[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(?::[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(?:ffff(?::0{1,4}){0,1}:){0,1}(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])|(?:[0-9a-fA-F]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/.test(inputs[i])) {
|
||||
output += unTransition(inputs[i]);
|
||||
} else {
|
||||
output = "Enter compressed or expanded IPv6 address, IPv4 address or MAC Address.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default IPv6TransitionAddresses;
|
||||
46
src/core/operations/JSONtoYAML.mjs
Normal file
46
src/core/operations/JSONtoYAML.mjs
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* @author ccarpo [ccarpo@gmx.net]
|
||||
* @copyright Crown Copyright 2021
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import YAML from "yaml";
|
||||
|
||||
/**
|
||||
* JSON to YAML operation
|
||||
*/
|
||||
class JSONtoYAML extends Operation {
|
||||
|
||||
/**
|
||||
* JSONtoYAML constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "JSON to YAML";
|
||||
this.module = "Default";
|
||||
this.description = "Format a JSON object into YAML";
|
||||
this.infoURL = "https://en.wikipedia.org/wiki/YAML";
|
||||
this.inputType = "JSON";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {JSON} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
try {
|
||||
return YAML.stringify(input);
|
||||
} catch (err) {
|
||||
throw new OperationError("Test");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default JSONtoYAML;
|
||||
57
src/core/operations/Jq.mjs
Normal file
57
src/core/operations/Jq.mjs
Normal file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* @author zhzy0077 [zhzy0077@hotmail.com]
|
||||
* @copyright Crown Copyright 2023
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import jq from "jq-web";
|
||||
|
||||
/**
|
||||
* jq operation
|
||||
*/
|
||||
class Jq extends Operation {
|
||||
|
||||
/**
|
||||
* Jq constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Jq";
|
||||
this.module = "Jq";
|
||||
this.description = "jq is a lightweight and flexible command-line JSON processor.";
|
||||
this.infoURL = "https://github.com/jqlang/jq";
|
||||
this.inputType = "JSON";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
name: "Query",
|
||||
type: "string",
|
||||
value: ""
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {JSON} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const [query] = args;
|
||||
let result;
|
||||
|
||||
try {
|
||||
result = jq.json(input, query);
|
||||
} catch (err) {
|
||||
throw new OperationError(`Invalid jq expression: ${err.message}`);
|
||||
}
|
||||
|
||||
return JSON.stringify(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Jq;
|
||||
65
src/core/operations/Jsonata.mjs
Normal file
65
src/core/operations/Jsonata.mjs
Normal file
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* @author Jon K (jon@ajarsoftware.com)
|
||||
* @copyright Crown Copyright 2016
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import jsonata from "jsonata";
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
|
||||
/**
|
||||
* Jsonata Query operation
|
||||
*/
|
||||
class JsonataQuery extends Operation {
|
||||
/**
|
||||
* JsonataQuery constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Jsonata Query";
|
||||
this.module = "Code";
|
||||
this.description =
|
||||
"Query and transform JSON data with a jsonata query.";
|
||||
this.infoURL = "https://docs.jsonata.org/overview.html";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
name: "Query",
|
||||
type: "text",
|
||||
value: "string",
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
async run(input, args) {
|
||||
const [query] = args;
|
||||
let result, jsonObj;
|
||||
|
||||
try {
|
||||
jsonObj = JSON.parse(input);
|
||||
} catch (err) {
|
||||
throw new OperationError(`Invalid input JSON: ${err.message}`);
|
||||
}
|
||||
|
||||
try {
|
||||
const expression = jsonata(query);
|
||||
result = await expression.evaluate(jsonObj);
|
||||
} catch (err) {
|
||||
throw new OperationError(
|
||||
`Invalid Jsonata Expression: ${err.message}`
|
||||
);
|
||||
}
|
||||
|
||||
return JSON.stringify(result === undefined ? "" : result);
|
||||
}
|
||||
}
|
||||
|
||||
export default JsonataQuery;
|
||||
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* @author n1073645 [n1073645@gmail.com]
|
||||
* @author k3ach [k3ach@proton.me]
|
||||
* @copyright Crown Copyright 2020
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
@@ -20,39 +21,46 @@ class LuhnChecksum extends Operation {
|
||||
|
||||
this.name = "Luhn Checksum";
|
||||
this.module = "Default";
|
||||
this.description = "The Luhn algorithm, also known as the modulus 10 or mod 10 algorithm, is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers and Canadian Social Insurance Numbers.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Luhn_algorithm";
|
||||
this.description = "The Luhn mod N algorithm using the english alphabet. The Luhn mod N algorithm is an extension to the Luhn algorithm (also known as mod 10 algorithm) that allows it to work with sequences of values in any even-numbered base. This can be useful when a check digit is required to validate an identification string composed of letters, a combination of letters and digits or any arbitrary set of N characters where N is divisible by 2.";
|
||||
this.infoURL = "https://en.wikipedia.org/wiki/Luhn_mod_N_algorithm";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
this.args = [
|
||||
{
|
||||
"name": "Radix",
|
||||
"type": "number",
|
||||
"value": 10
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the Luhn Checksum from the input.
|
||||
* Generates the Luhn checksum from the input.
|
||||
*
|
||||
* @param {string} inputStr
|
||||
* @returns {number}
|
||||
*/
|
||||
checksum(inputStr) {
|
||||
checksum(inputStr, radix = 10) {
|
||||
let even = false;
|
||||
return inputStr.split("").reverse().reduce((acc, elem) => {
|
||||
// Convert element to integer.
|
||||
let temp = parseInt(elem, 10);
|
||||
// Convert element to an integer based on the provided radix.
|
||||
let temp = parseInt(elem, radix);
|
||||
|
||||
// If element is not an integer.
|
||||
if (isNaN(temp))
|
||||
throw new OperationError("Character: " + elem + " is not a digit.");
|
||||
// If element is not a valid number in the given radix.
|
||||
if (isNaN(temp)) {
|
||||
throw new Error("Character: " + elem + " is not valid in radix " + radix + ".");
|
||||
}
|
||||
|
||||
// If element is in an even position
|
||||
if (even) {
|
||||
// Double the element and add the quotient and remainder together.
|
||||
temp = 2 * elem;
|
||||
temp = Math.floor(temp/10) + (temp % 10);
|
||||
// Double the element and sum the quotient and remainder.
|
||||
temp = 2 * temp;
|
||||
temp = Math.floor(temp / radix) + (temp % radix);
|
||||
}
|
||||
|
||||
even = !even;
|
||||
return acc + temp;
|
||||
}, 0) % 10;
|
||||
}, 0) % radix; // Use radix as the modulus base
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,9 +71,20 @@ class LuhnChecksum extends Operation {
|
||||
run(input, args) {
|
||||
if (!input) return "";
|
||||
|
||||
const checkSum = this.checksum(input);
|
||||
let checkDigit = this.checksum(input + "0");
|
||||
checkDigit = checkDigit === 0 ? 0 : (10-checkDigit);
|
||||
const radix = args[0];
|
||||
|
||||
if (radix < 2 || radix > 36) {
|
||||
throw new OperationError("Error: Radix argument must be between 2 and 36");
|
||||
}
|
||||
|
||||
if (radix % 2 !== 0) {
|
||||
throw new OperationError("Error: Radix argument must be divisible by 2");
|
||||
}
|
||||
|
||||
const checkSum = this.checksum(input, radix).toString(radix);
|
||||
let checkDigit = this.checksum(input + "0", radix);
|
||||
checkDigit = checkDigit === 0 ? 0 : (radix - checkDigit);
|
||||
checkDigit = checkDigit.toString(radix);
|
||||
|
||||
return `Checksum: ${checkSum}
|
||||
Checkdigit: ${checkDigit}
|
||||
|
||||
171
src/core/operations/MIMEDecoding.mjs
Normal file
171
src/core/operations/MIMEDecoding.mjs
Normal file
@@ -0,0 +1,171 @@
|
||||
/**
|
||||
* @author mshwed [m@ttshwed.com]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import Utils from "../Utils.mjs";
|
||||
import { fromHex } from "../lib/Hex.mjs";
|
||||
import { fromBase64 } from "../lib/Base64.mjs";
|
||||
import cptable from "codepage";
|
||||
|
||||
/**
|
||||
* MIME Decoding operation
|
||||
*/
|
||||
class MIMEDecoding extends Operation {
|
||||
|
||||
/**
|
||||
* MIMEDecoding constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "MIME Decoding";
|
||||
this.module = "Default";
|
||||
this.description = "Enables the decoding of MIME message header extensions for non-ASCII text";
|
||||
this.infoURL = "https://tools.ietf.org/html/rfc2047";
|
||||
this.inputType = "byteArray";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {byteArray} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const mimeEncodedText = Utils.byteArrayToUtf8(input);
|
||||
const encodedHeaders = mimeEncodedText.replace(/\r\n/g, "\n");
|
||||
|
||||
const decodedHeader = this.decodeHeaders(encodedHeaders);
|
||||
|
||||
return decodedHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode MIME header strings
|
||||
*
|
||||
* @param headerString
|
||||
*/
|
||||
decodeHeaders(headerString) {
|
||||
// No encoded words detected
|
||||
let i = headerString.indexOf("=?");
|
||||
if (i === -1) return headerString;
|
||||
|
||||
let decodedHeaders = headerString.slice(0, i);
|
||||
let header = headerString.slice(i);
|
||||
|
||||
let isBetweenWords = false;
|
||||
let start, cur, charset, encoding, j, end, text;
|
||||
while (header.length > -1) {
|
||||
start = header.indexOf("=?");
|
||||
if (start === -1) break;
|
||||
cur = start + "=?".length;
|
||||
|
||||
i = header.slice(cur).indexOf("?");
|
||||
if (i === -1) break;
|
||||
|
||||
charset = header.slice(cur, cur + i);
|
||||
cur += i + "?".length;
|
||||
|
||||
if (header.length < cur + "Q??=".length) break;
|
||||
|
||||
encoding = header[cur];
|
||||
cur += 1;
|
||||
|
||||
if (header[cur] !== "?") break;
|
||||
|
||||
cur += 1;
|
||||
|
||||
j = header.slice(cur).indexOf("?=");
|
||||
if (j === -1) break;
|
||||
|
||||
text = header.slice(cur, cur + j);
|
||||
end = cur + j + "?=".length;
|
||||
|
||||
if (encoding.toLowerCase() === "b") {
|
||||
text = fromBase64(text);
|
||||
} else if (encoding.toLowerCase() === "q") {
|
||||
text = this.parseQEncodedWord(text);
|
||||
} else {
|
||||
isBetweenWords = false;
|
||||
decodedHeaders += header.slice(0, start + 2);
|
||||
header = header.slice(start + 2);
|
||||
}
|
||||
|
||||
if (start > 0 && (!isBetweenWords || header.slice(0, start).search(/\S/g) > -1)) {
|
||||
decodedHeaders += header.slice(0, start);
|
||||
}
|
||||
|
||||
decodedHeaders += this.convertFromCharset(charset, text);
|
||||
|
||||
header = header.slice(end);
|
||||
isBetweenWords = true;
|
||||
}
|
||||
|
||||
if (header.length > 0) {
|
||||
decodedHeaders += header;
|
||||
}
|
||||
|
||||
return decodedHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts decoded text for supported charsets.
|
||||
* Supports UTF-8, US-ASCII, ISO-8859-*
|
||||
*
|
||||
* @param encodedWord
|
||||
*/
|
||||
convertFromCharset(charset, encodedText) {
|
||||
charset = charset.toLowerCase();
|
||||
const parsedCharset = charset.split("-");
|
||||
|
||||
if (parsedCharset.length === 2 && parsedCharset[0] === "utf" && charset === "utf-8") {
|
||||
return cptable.utils.decode(65001, encodedText);
|
||||
} else if (parsedCharset.length === 2 && charset === "us-ascii") {
|
||||
return cptable.utils.decode(20127, encodedText);
|
||||
} else if (parsedCharset.length === 3 && parsedCharset[0] === "iso" && parsedCharset[1] === "8859") {
|
||||
const isoCharset = parseInt(parsedCharset[2], 10);
|
||||
if (isoCharset >= 1 && isoCharset <= 16) {
|
||||
return cptable.utils.decode(28590 + isoCharset, encodedText);
|
||||
}
|
||||
}
|
||||
|
||||
throw new OperationError("Unhandled Charset");
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a Q encoded word
|
||||
*
|
||||
* @param encodedWord
|
||||
*/
|
||||
parseQEncodedWord(encodedWord) {
|
||||
let decodedWord = "";
|
||||
for (let i = 0; i < encodedWord.length; i++) {
|
||||
if (encodedWord[i] === "_") {
|
||||
decodedWord += " ";
|
||||
// Parse hex encoding
|
||||
} else if (encodedWord[i] === "=") {
|
||||
if ((i + 2) >= encodedWord.length) throw new OperationError("Incorrectly Encoded Word");
|
||||
const decodedHex = Utils.byteArrayToChars(fromHex(encodedWord.substring(i + 1, i + 3)));
|
||||
decodedWord += decodedHex;
|
||||
i += 2;
|
||||
} else if (
|
||||
(encodedWord[i].charCodeAt(0) >= " ".charCodeAt(0) && encodedWord[i].charCodeAt(0) <= "~".charCodeAt(0)) ||
|
||||
encodedWord[i] === "\n" ||
|
||||
encodedWord[i] === "\r" ||
|
||||
encodedWord[i] === "\t") {
|
||||
decodedWord += encodedWord[i];
|
||||
} else {
|
||||
throw new OperationError("Incorrectly Encoded Word");
|
||||
}
|
||||
}
|
||||
|
||||
return decodedWord;
|
||||
}
|
||||
}
|
||||
|
||||
export default MIMEDecoding;
|
||||
126
src/core/operations/PHPSerialize.mjs
Normal file
126
src/core/operations/PHPSerialize.mjs
Normal file
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* @author brun0ne [brunonblok@gmail.com]
|
||||
* @copyright Crown Copyright 2023
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
|
||||
/**
|
||||
* PHP Serialize operation
|
||||
*/
|
||||
class PHPSerialize extends Operation {
|
||||
|
||||
/**
|
||||
* PHPSerialize constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "PHP Serialize";
|
||||
this.module = "Default";
|
||||
this.description = "Performs PHP serialization on JSON data.<br><br>This function does not support <code>object</code> tags.<br><br>Since PHP doesn't distinguish dicts and arrays, this operation is not always symmetric to <code>PHP Deserialize</code>.<br><br>Example:<br><code>[5,"abc",true]</code><br>becomes<br><code>a:3:{i:0;i:5;i:1;s:3:"abc";i:2;b:1;}<code>";
|
||||
this.infoURL = "https://www.phpinternalsbook.com/php5/classes_objects/serialization.html";
|
||||
this.inputType = "JSON";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {JSON} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
/**
|
||||
* Determines if a number is an integer
|
||||
* @param {number} value
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isInteger(value) {
|
||||
return typeof value === "number" && parseInt(value.toString(), 10) === value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize basic types
|
||||
* @param {string | number | boolean} content
|
||||
* @returns {string}
|
||||
*/
|
||||
function serializeBasicTypes(content) {
|
||||
const basicTypes = {
|
||||
"string": "s",
|
||||
"integer": "i",
|
||||
"float": "d",
|
||||
"boolean": "b"
|
||||
};
|
||||
/**
|
||||
* Booleans
|
||||
* cast to 0 or 1
|
||||
*/
|
||||
if (typeof content === "boolean") {
|
||||
return `${basicTypes.boolean}:${content ? 1 : 0}`;
|
||||
}
|
||||
/* Numbers */
|
||||
if (typeof content === "number") {
|
||||
if (isInteger(content)) {
|
||||
return `${basicTypes.integer}:${content.toString()}`;
|
||||
} else {
|
||||
return `${basicTypes.float}:${content.toString()}`;
|
||||
}
|
||||
}
|
||||
/* Strings */
|
||||
if (typeof content === "string")
|
||||
return `${basicTypes.string}:${content.length}:"${content}"`;
|
||||
|
||||
/** This should be unreachable */
|
||||
throw new OperationError(`Encountered a non-implemented type: ${typeof content}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively serialize
|
||||
* @param {*} object
|
||||
* @returns {string}
|
||||
*/
|
||||
function serialize(object) {
|
||||
/* Null */
|
||||
if (object == null) {
|
||||
return `N;`;
|
||||
}
|
||||
|
||||
if (typeof object !== "object") {
|
||||
/* Basic types */
|
||||
return `${serializeBasicTypes(object)};`;
|
||||
} else if (object instanceof Array) {
|
||||
/* Arrays */
|
||||
const serializedElements = [];
|
||||
|
||||
for (let i = 0; i < object.length; i++) {
|
||||
serializedElements.push(`${serialize(i)}${serialize(object[i])}`);
|
||||
}
|
||||
|
||||
return `a:${object.length}:{${serializedElements.join("")}}`;
|
||||
} else if (object instanceof Object) {
|
||||
/**
|
||||
* Objects
|
||||
* Note: the output cannot be guaranteed to be in the same order as the input
|
||||
*/
|
||||
const serializedElements = [];
|
||||
const keys = Object.keys(object);
|
||||
|
||||
for (const key of keys) {
|
||||
serializedElements.push(`${serialize(key)}${serialize(object[key])}`);
|
||||
}
|
||||
|
||||
return `a:${keys.length}:{${serializedElements.join("")}}`;
|
||||
}
|
||||
|
||||
/** This should be unreachable */
|
||||
throw new OperationError(`Encountered a non-implemented type: ${typeof object}`);
|
||||
}
|
||||
|
||||
return serialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
export default PHPSerialize;
|
||||
@@ -6,7 +6,8 @@
|
||||
|
||||
import r from "jsrsasign";
|
||||
import { fromBase64 } from "../lib/Base64.mjs";
|
||||
import { toHex } from "../lib/Hex.mjs";
|
||||
import { runHash } from "../lib/Hash.mjs";
|
||||
import { fromHex, toHex } from "../lib/Hex.mjs";
|
||||
import { formatByteStr, formatDnObj } from "../lib/PublicKey.mjs";
|
||||
import Operation from "../Operation.mjs";
|
||||
import Utils from "../Utils.mjs";
|
||||
@@ -81,7 +82,8 @@ class ParseX509Certificate extends Operation {
|
||||
}
|
||||
if (undefinedInputFormat) throw "Undefined input format";
|
||||
|
||||
const sn = cert.getSerialNumberHex(),
|
||||
const hex = Utils.strToArrayBuffer(Utils.byteArrayToChars(fromHex(cert.hex))),
|
||||
sn = cert.getSerialNumberHex(),
|
||||
issuer = cert.getIssuer(),
|
||||
subject = cert.getSubject(),
|
||||
pk = cert.getPublicKey(),
|
||||
@@ -191,6 +193,10 @@ Issuer
|
||||
${issuerStr}
|
||||
Subject
|
||||
${subjectStr}
|
||||
Fingerprints
|
||||
MD5: ${runHash("md5", hex)}
|
||||
SHA1: ${runHash("sha1", hex)}
|
||||
SHA256: ${runHash("sha256", hex)}
|
||||
Public Key
|
||||
${pkStr.slice(0, -1)}
|
||||
Certificate Signature
|
||||
|
||||
@@ -59,15 +59,16 @@ class ROT13 extends Operation {
|
||||
rot13Upperacse = args[1],
|
||||
rotNumbers = args[2];
|
||||
let amount = args[3],
|
||||
chr;
|
||||
amountNumbers = args[3];
|
||||
|
||||
if (amount) {
|
||||
if (amount < 0) {
|
||||
amount = 26 - (Math.abs(amount) % 26);
|
||||
amountNumbers = 10 - (Math.abs(amountNumbers) % 10);
|
||||
}
|
||||
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
chr = input[i];
|
||||
let chr = input[i];
|
||||
if (rot13Upperacse && chr >= 65 && chr <= 90) { // Upper case
|
||||
chr = (chr - 65 + amount) % 26;
|
||||
output[i] = chr + 65;
|
||||
@@ -75,7 +76,7 @@ class ROT13 extends Operation {
|
||||
chr = (chr - 97 + amount) % 26;
|
||||
output[i] = chr + 97;
|
||||
} else if (rotNumbers && chr >= 48 && chr <= 57) { // Numbers
|
||||
chr = (chr - 48 + amount) % 10;
|
||||
chr = (chr - 48 + amountNumbers) % 10;
|
||||
output[i] = chr + 48;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class RailFenceCipherDecode extends Operation {
|
||||
}
|
||||
}
|
||||
|
||||
return plaintext.join("").trim();
|
||||
return plaintext.join("");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class RailFenceCipherEncode extends Operation {
|
||||
rows[rowIdx] += plaintext[pos];
|
||||
}
|
||||
|
||||
return rows.join("").trim();
|
||||
return rows.join("");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
71
src/core/operations/SM2Decrypt.mjs
Normal file
71
src/core/operations/SM2Decrypt.mjs
Normal file
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* @author flakjacket95 [dflack95@gmail.com]
|
||||
* @copyright Crown Copyright 2024
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import Operation from "../Operation.mjs";
|
||||
|
||||
import { SM2 } from "../lib/SM2.mjs";
|
||||
|
||||
/**
|
||||
* SM2Decrypt operation
|
||||
*/
|
||||
class SM2Decrypt extends Operation {
|
||||
|
||||
/**
|
||||
* SM2Decrypt constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "SM2 Decrypt";
|
||||
this.module = "Crypto";
|
||||
this.description = "Decrypts a message utilizing the SM2 standard";
|
||||
this.infoURL = ""; // Usually a Wikipedia link. Remember to remove localisation (i.e. https://wikipedia.org/etc rather than https://en.wikipedia.org/etc)
|
||||
this.inputType = "string";
|
||||
this.outputType = "ArrayBuffer";
|
||||
this.args = [
|
||||
{
|
||||
name: "Private Key",
|
||||
type: "string",
|
||||
value: "DEADBEEF"
|
||||
},
|
||||
{
|
||||
"name": "Input Format",
|
||||
"type": "option",
|
||||
"value": ["C1C3C2", "C1C2C3"],
|
||||
"defaultIndex": 0
|
||||
},
|
||||
{
|
||||
name: "Curve",
|
||||
type: "option",
|
||||
"value": ["sm2p256v1"],
|
||||
"defaultIndex": 0
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {ArrayBuffer}
|
||||
*/
|
||||
run(input, args) {
|
||||
const [privateKey, inputFormat, curveName] = args;
|
||||
|
||||
if (privateKey.length !== 64) {
|
||||
throw new OperationError("Input private key must be in hex; and should be 32 bytes");
|
||||
}
|
||||
|
||||
const sm2 = new SM2(curveName, inputFormat);
|
||||
sm2.setPrivateKey(privateKey);
|
||||
|
||||
const result = sm2.decrypt(input);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default SM2Decrypt;
|
||||
77
src/core/operations/SM2Encrypt.mjs
Normal file
77
src/core/operations/SM2Encrypt.mjs
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* @author flakjacket95 [dflack95@gmail.com]
|
||||
* @copyright Crown Copyright 2024
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import Operation from "../Operation.mjs";
|
||||
|
||||
import { SM2 } from "../lib/SM2.mjs";
|
||||
|
||||
/**
|
||||
* SM2 Encrypt operation
|
||||
*/
|
||||
class SM2Encrypt extends Operation {
|
||||
|
||||
/**
|
||||
* SM2Encrypt constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "SM2 Encrypt";
|
||||
this.module = "Crypto";
|
||||
this.description = "Encrypts a message utilizing the SM2 standard";
|
||||
this.infoURL = ""; // Usually a Wikipedia link. Remember to remove localisation (i.e. https://wikipedia.org/etc rather than https://en.wikipedia.org/etc)
|
||||
this.inputType = "ArrayBuffer";
|
||||
this.outputType = "string";
|
||||
|
||||
this.args = [
|
||||
{
|
||||
name: "Public Key X",
|
||||
type: "string",
|
||||
value: "DEADBEEF"
|
||||
},
|
||||
{
|
||||
name: "Public Key Y",
|
||||
type: "string",
|
||||
value: "DEADBEEF"
|
||||
},
|
||||
{
|
||||
"name": "Output Format",
|
||||
"type": "option",
|
||||
"value": ["C1C3C2", "C1C2C3"],
|
||||
"defaultIndex": 0
|
||||
},
|
||||
{
|
||||
name: "Curve",
|
||||
type: "option",
|
||||
"value": ["sm2p256v1"],
|
||||
"defaultIndex": 0
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {byteArray}
|
||||
*/
|
||||
run(input, args) {
|
||||
const [publicKeyX, publicKeyY, outputFormat, curveName] = args;
|
||||
this.outputFormat = outputFormat;
|
||||
|
||||
if (publicKeyX.length !== 64 || publicKeyY.length !== 64) {
|
||||
throw new OperationError("Invalid Public Key - Ensure each component is 32 bytes in size and in hex");
|
||||
}
|
||||
|
||||
const sm2 = new SM2(curveName, outputFormat);
|
||||
sm2.setPublicKey(publicKeyX, publicKeyY);
|
||||
|
||||
const result = sm2.encrypt(new Uint8Array(input));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export default SM2Encrypt;
|
||||
57
src/core/operations/StripIPv4Header.mjs
Normal file
57
src/core/operations/StripIPv4Header.mjs
Normal file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* @author c65722 []
|
||||
* @copyright Crown Copyright 2024
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import Stream from "../lib/Stream.mjs";
|
||||
|
||||
/**
|
||||
* Strip IPv4 header operation
|
||||
*/
|
||||
class StripIPv4Header extends Operation {
|
||||
|
||||
/**
|
||||
* StripIPv4Header constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Strip IPv4 header";
|
||||
this.module = "Default";
|
||||
this.description = "Strips the IPv4 header from an IPv4 packet, outputting the payload.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/IPv4";
|
||||
this.inputType = "ArrayBuffer";
|
||||
this.outputType = "ArrayBuffer";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {ArrayBuffer}
|
||||
*/
|
||||
run(input, args) {
|
||||
const MIN_HEADER_LEN = 20;
|
||||
|
||||
const s = new Stream(new Uint8Array(input));
|
||||
if (s.length < MIN_HEADER_LEN) {
|
||||
throw new OperationError("Input length is less than minimum IPv4 header length");
|
||||
}
|
||||
|
||||
const ihl = s.readInt(1) & 0x0f;
|
||||
const dataOffsetBytes = ihl * 4;
|
||||
if (s.length < dataOffsetBytes) {
|
||||
throw new OperationError("Input length is less than IHL");
|
||||
}
|
||||
|
||||
s.moveTo(dataOffsetBytes);
|
||||
|
||||
return s.getBytes().buffer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default StripIPv4Header;
|
||||
79
src/core/operations/TakeNthBytes.mjs
Normal file
79
src/core/operations/TakeNthBytes.mjs
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* @author Oshawk [oshawk@protonmail.com]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
|
||||
/**
|
||||
* Take nth bytes operation
|
||||
*/
|
||||
class TakeNthBytes extends Operation {
|
||||
|
||||
/**
|
||||
* TakeNthBytes constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Take nth bytes";
|
||||
this.module = "Default";
|
||||
this.description = "Takes every nth byte starting with a given byte.";
|
||||
this.infoURL = "";
|
||||
this.inputType = "byteArray";
|
||||
this.outputType = "byteArray";
|
||||
this.args = [
|
||||
{
|
||||
name: "Take every",
|
||||
type: "number",
|
||||
value: 4
|
||||
},
|
||||
{
|
||||
name: "Starting at",
|
||||
type: "number",
|
||||
value: 0
|
||||
},
|
||||
{
|
||||
name: "Apply to each line",
|
||||
type: "boolean",
|
||||
value: false
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {byteArray} input
|
||||
* @param {Object[]} args
|
||||
* @returns {byteArray}
|
||||
*/
|
||||
run(input, args) {
|
||||
const n = args[0];
|
||||
const start = args[1];
|
||||
const eachLine = args[2];
|
||||
|
||||
if (parseInt(n, 10) !== n || n <= 0) {
|
||||
throw new OperationError("'Take every' must be a positive integer.");
|
||||
}
|
||||
if (parseInt(start, 10) !== start || start < 0) {
|
||||
throw new OperationError("'Starting at' must be a positive or zero integer.");
|
||||
}
|
||||
|
||||
let offset = 0;
|
||||
const output = [];
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
if (eachLine && input[i] === 0x0a) {
|
||||
output.push(0x0a);
|
||||
offset = i + 1;
|
||||
} else if (i - offset >= start && (i - (start + offset)) % n === 0) {
|
||||
output.push(input[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default TakeNthBytes;
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import Utils from "../Utils.mjs";
|
||||
import {ALPHABET_OPTIONS} from "../lib/Base32.mjs";
|
||||
|
||||
/**
|
||||
* To Base32 operation
|
||||
@@ -27,8 +28,8 @@ class ToBase32 extends Operation {
|
||||
this.args = [
|
||||
{
|
||||
name: "Alphabet",
|
||||
type: "binaryString",
|
||||
value: "A-Z2-7="
|
||||
type: "editableOption",
|
||||
value: ALPHABET_OPTIONS
|
||||
}
|
||||
];
|
||||
}
|
||||
@@ -83,3 +84,4 @@ class ToBase32 extends Operation {
|
||||
}
|
||||
|
||||
export default ToBase32;
|
||||
|
||||
|
||||
55
src/core/operations/ToModhex.mjs
Normal file
55
src/core/operations/ToModhex.mjs
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* @author linuxgemini [ilteris@asenkron.com.tr]
|
||||
* @copyright Crown Copyright 2024
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import { TO_MODHEX_DELIM_OPTIONS, toModhex } from "../lib/Modhex.mjs";
|
||||
import Utils from "../Utils.mjs";
|
||||
|
||||
/**
|
||||
* To Modhex operation
|
||||
*/
|
||||
class ToModhex extends Operation {
|
||||
|
||||
/**
|
||||
* ToModhex constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "To Modhex";
|
||||
this.module = "Default";
|
||||
this.description = "Converts the input string to modhex bytes separated by the specified delimiter.";
|
||||
this.infoURL = "https://en.wikipedia.org/wiki/YubiKey#ModHex";
|
||||
this.inputType = "ArrayBuffer";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
name: "Delimiter",
|
||||
type: "option",
|
||||
value: TO_MODHEX_DELIM_OPTIONS
|
||||
},
|
||||
{
|
||||
name: "Bytes per line",
|
||||
type: "number",
|
||||
value: 0
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const delim = Utils.charRep(args[0]);
|
||||
const lineSize = args[1];
|
||||
|
||||
return toModhex(new Uint8Array(input), delim, 2, "", lineSize);
|
||||
}
|
||||
}
|
||||
|
||||
export default ToModhex;
|
||||
@@ -22,7 +22,7 @@ class TripleDESDecrypt extends Operation {
|
||||
|
||||
this.name = "Triple DES Decrypt";
|
||||
this.module = "Ciphers";
|
||||
this.description = "Triple DES applies DES three times to each block to increase key size.<br><br><b>Key:</b> Triple DES uses a key length of 24 bytes (192 bits).<br>DES uses a key length of 8 bytes (64 bits).<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used as a default.";
|
||||
this.description = "Triple DES applies DES three times to each block to increase key size.<br><br><b>Key:</b> Triple DES uses a key length of 24 bytes (192 bits).<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used as a default.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Triple_DES";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
@@ -73,8 +73,7 @@ class TripleDESDecrypt extends Operation {
|
||||
if (key.length !== 24 && key.length !== 16) {
|
||||
throw new OperationError(`Invalid key length: ${key.length} bytes
|
||||
|
||||
Triple DES uses a key length of 24 bytes (192 bits).
|
||||
DES uses a key length of 8 bytes (64 bits).`);
|
||||
Triple DES uses a key length of 24 bytes (192 bits).`);
|
||||
}
|
||||
if (iv.length !== 8 && mode !== "ECB") {
|
||||
throw new OperationError(`Invalid IV length: ${iv.length} bytes
|
||||
|
||||
@@ -22,7 +22,7 @@ class TripleDESEncrypt extends Operation {
|
||||
|
||||
this.name = "Triple DES Encrypt";
|
||||
this.module = "Ciphers";
|
||||
this.description = "Triple DES applies DES three times to each block to increase key size.<br><br><b>Key:</b> Triple DES uses a key length of 24 bytes (192 bits).<br>DES uses a key length of 8 bytes (64 bits).<br><br>You can generate a password-based key using one of the KDF operations.<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used.";
|
||||
this.description = "Triple DES applies DES three times to each block to increase key size.<br><br><b>Key:</b> Triple DES uses a key length of 24 bytes (192 bits).<br><br>You can generate a password-based key using one of the KDF operations.<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Triple_DES";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
@@ -72,8 +72,7 @@ class TripleDESEncrypt extends Operation {
|
||||
if (key.length !== 24 && key.length !== 16) {
|
||||
throw new OperationError(`Invalid key length: ${key.length} bytes
|
||||
|
||||
Triple DES uses a key length of 24 bytes (192 bits).
|
||||
DES uses a key length of 8 bytes (64 bits).`);
|
||||
Triple DES uses a key length of 24 bytes (192 bits).`);
|
||||
}
|
||||
if (iv.length !== 8 && mode !== "ECB") {
|
||||
throw new OperationError(`Invalid IV length: ${iv.length} bytes
|
||||
|
||||
@@ -23,7 +23,13 @@ class URLDecode extends Operation {
|
||||
this.infoURL = "https://wikipedia.org/wiki/Percent-encoding";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
this.args = [
|
||||
{
|
||||
"name": "Treat \"+\" as space",
|
||||
"type": "boolean",
|
||||
"value": true
|
||||
},
|
||||
];
|
||||
this.checks = [
|
||||
{
|
||||
pattern: ".*(?:%[\\da-f]{2}.*){4}",
|
||||
@@ -39,7 +45,8 @@ class URLDecode extends Operation {
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const data = input.replace(/\+/g, "%20");
|
||||
const plusIsSpace = args[0];
|
||||
const data = plusIsSpace ? input.replace(/\+/g, "%20") : input;
|
||||
try {
|
||||
return decodeURIComponent(data);
|
||||
} catch (err) {
|
||||
|
||||
59
src/core/operations/XORChecksum.mjs
Normal file
59
src/core/operations/XORChecksum.mjs
Normal file
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* @author Thomas Weißschuh [thomas@t-8ch.de]
|
||||
* @copyright Crown Copyright 2023
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import Utils from "../Utils.mjs";
|
||||
import { toHex } from "../lib/Hex.mjs";
|
||||
|
||||
/**
|
||||
* XOR Checksum operation
|
||||
*/
|
||||
class XORChecksum extends Operation {
|
||||
|
||||
/**
|
||||
* XORChecksum constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "XOR Checksum";
|
||||
this.module = "Crypto";
|
||||
this.description = "XOR Checksum splits the input into blocks of a configurable size and performs the XOR operation on these blocks.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/XOR";
|
||||
this.inputType = "ArrayBuffer";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
name: "Blocksize",
|
||||
type: "number",
|
||||
value: 4
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const blocksize = args[0];
|
||||
input = new Uint8Array(input);
|
||||
|
||||
const res = Array(blocksize);
|
||||
res.fill(0);
|
||||
|
||||
for (const chunk of Utils.chunked(input, blocksize)) {
|
||||
for (let i = 0; i < blocksize; i++) {
|
||||
res[i] ^= chunk[i];
|
||||
}
|
||||
}
|
||||
|
||||
return toHex(res, "");
|
||||
}
|
||||
}
|
||||
|
||||
export default XORChecksum;
|
||||
45
src/core/operations/YAMLToJSON.mjs
Normal file
45
src/core/operations/YAMLToJSON.mjs
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @author ccarpo [ccarpo@gmx.net]
|
||||
* @copyright Crown Copyright 2021
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import jsYaml from "js-yaml";
|
||||
/**
|
||||
* YAML to JSON operation
|
||||
*/
|
||||
class YAMLToJSON extends Operation {
|
||||
|
||||
/**
|
||||
* YAMLToJSON constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "YAML to JSON";
|
||||
this.module = "Default";
|
||||
this.description = "Convert YAML to JSON";
|
||||
this.infoURL = "https://en.wikipedia.org/wiki/YAML";
|
||||
this.inputType = "string";
|
||||
this.outputType = "JSON";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {JSON}
|
||||
*/
|
||||
run(input, args) {
|
||||
try {
|
||||
return jsYaml.load(input);
|
||||
} catch (err) {
|
||||
throw new OperationError("Unable to parse YAML: " + err);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default YAMLToJSON;
|
||||
@@ -74,11 +74,11 @@ function transformArgs(opArgsList, newArgs) {
|
||||
return opArgs.map((arg) => {
|
||||
if (arg.type === "option") {
|
||||
// pick default option if not already chosen
|
||||
return typeof arg.value === "string" ? arg.value : arg.value[0];
|
||||
return typeof arg.value === "string" ? arg.value : arg.value[arg.defaultIndex ?? 0];
|
||||
}
|
||||
|
||||
if (arg.type === "editableOption") {
|
||||
return typeof arg.value === "string" ? arg.value : arg.value[0].value;
|
||||
return typeof arg.value === "string" ? arg.value : arg.value[arg.defaultIndex ?? 0].value;
|
||||
}
|
||||
|
||||
if (arg.type === "toggleString") {
|
||||
|
||||
3
src/web/App.mjs
Executable file → Normal file
3
src/web/App.mjs
Executable file → Normal file
@@ -60,6 +60,7 @@ class App {
|
||||
|
||||
this.initialiseSplitter();
|
||||
this.loadLocalStorage();
|
||||
this.manager.options.applyPreferredColorScheme();
|
||||
this.populateOperationsList();
|
||||
this.manager.setup();
|
||||
this.manager.output.saveBombe();
|
||||
@@ -536,6 +537,8 @@ class App {
|
||||
// Read in theme from URI params
|
||||
if (this.uriParams.theme) {
|
||||
this.manager.options.changeTheme(Utils.escapeHtml(this.uriParams.theme));
|
||||
} else {
|
||||
this.manager.options.applyPreferredColorScheme();
|
||||
}
|
||||
|
||||
window.dispatchEvent(this.manager.statechange);
|
||||
|
||||
@@ -125,6 +125,7 @@ class Manager {
|
||||
window.addEventListener("focus", this.window.windowFocus.bind(this.window));
|
||||
window.addEventListener("statechange", this.app.stateChange.bind(this.app));
|
||||
window.addEventListener("popstate", this.app.popState.bind(this.app));
|
||||
window.addEventListener("message", this.input.handlePostMessage.bind(this.input));
|
||||
|
||||
// Controls
|
||||
document.getElementById("bake").addEventListener("click", this.controls.bakeClick.bind(this.controls));
|
||||
|
||||
@@ -1,23 +1,26 @@
|
||||
[
|
||||
{
|
||||
"@context": "http://schema.org",
|
||||
"@type": "Organization",
|
||||
"url": "https://gchq.github.io/CyberChef/",
|
||||
"logo": "https://gchq.github.io/CyberChef/images/cyberchef-128x128.png",
|
||||
"sameAs": [
|
||||
"https://github.com/gchq/CyberChef",
|
||||
"https://www.npmjs.com/package/cyberchef"
|
||||
"@graph": [
|
||||
{
|
||||
"@type": "Organization",
|
||||
"url": "https://gchq.github.io/CyberChef/",
|
||||
"logo": "https://gchq.github.io/CyberChef/images/cyberchef-128x128.png",
|
||||
"sameAs": [
|
||||
"https://github.com/gchq/CyberChef",
|
||||
"https://www.npmjs.com/package/cyberchef"
|
||||
]
|
||||
},
|
||||
{
|
||||
"@type": "WebSite",
|
||||
"url": "https://gchq.github.io/CyberChef/",
|
||||
"name": "CyberChef",
|
||||
"potentialAction": {
|
||||
"@type": "SearchAction",
|
||||
"target": "https://gchq.github.io/CyberChef/?op={operation_search_term}",
|
||||
"query-input": "required name=operation_search_term"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"@context": "http://schema.org",
|
||||
"@type": "WebSite",
|
||||
"url": "https://gchq.github.io/CyberChef/",
|
||||
"name": "CyberChef",
|
||||
"potentialAction": {
|
||||
"@type": "SearchAction",
|
||||
"target": "https://gchq.github.io/CyberChef/?op={operation_search_term}",
|
||||
"query-input": "required name=operation_search_term"
|
||||
}
|
||||
}
|
||||
]
|
||||
]
|
||||
@@ -1654,6 +1654,23 @@ class InputWaiter {
|
||||
this.changeTab(inputNum, this.app.options.syncTabs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for incoming postMessages
|
||||
* If the events data has a `type` property set to `dataSubmit`
|
||||
* the value property is set to the current input
|
||||
* @param {event} e
|
||||
* @param {object} e.data
|
||||
* @param {string} e.data.type - the type of request, currently the only value is "dataSubmit"
|
||||
* @param {string} e.data.value - the value of the message
|
||||
*/
|
||||
handlePostMessage(e) {
|
||||
log.debug(e);
|
||||
if ("data" in e && "id" in e.data && "value" in e.data) {
|
||||
if (e.data.id === "setInput") {
|
||||
this.setInput(e.data.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default InputWaiter;
|
||||
|
||||
29
src/web/waiters/OptionsWaiter.mjs
Executable file → Normal file
29
src/web/waiters/OptionsWaiter.mjs
Executable file → Normal file
@@ -160,9 +160,36 @@ class OptionsWaiter {
|
||||
|
||||
// Update theme selection
|
||||
const themeSelect = document.getElementById("theme");
|
||||
themeSelect.selectedIndex = themeSelect.querySelector(`option[value="${theme}"`).index;
|
||||
let themeOption = themeSelect.querySelector(`option[value="${theme}"]`);
|
||||
|
||||
if (!themeOption) {
|
||||
const preferredColorScheme = this.getPreferredColorScheme();
|
||||
document.querySelector(":root").className = preferredColorScheme;
|
||||
themeOption = themeSelect.querySelector(`option[value="${preferredColorScheme}"]`);
|
||||
}
|
||||
|
||||
themeSelect.selectedIndex = themeOption.index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the user's preferred color scheme using the `prefers-color-scheme` media query.
|
||||
*/
|
||||
applyPreferredColorScheme() {
|
||||
const themeFromStorage = this.app?.options?.theme;
|
||||
let theme = themeFromStorage;
|
||||
if (!theme) {
|
||||
theme = this.getPreferredColorScheme();
|
||||
}
|
||||
this.changeTheme(theme);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user's preferred color scheme using the `prefers-color-scheme` media query.
|
||||
*/
|
||||
getPreferredColorScheme() {
|
||||
const prefersDarkScheme = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||
return prefersDarkScheme ? "dark" : "classic";
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the console logging level.
|
||||
|
||||
@@ -8,6 +8,7 @@ import HTMLOperation from "../HTMLOperation.mjs";
|
||||
import Sortable from "sortablejs";
|
||||
import Utils from "../../core/Utils.mjs";
|
||||
import {escapeControlChars} from "../utils/editorUtils.mjs";
|
||||
import DOMPurify from "dompurify";
|
||||
|
||||
|
||||
/**
|
||||
@@ -435,7 +436,9 @@ class RecipeWaiter {
|
||||
const item = document.createElement("li");
|
||||
|
||||
item.classList.add("operation");
|
||||
item.innerHTML = name;
|
||||
const clean = DOMPurify.sanitize(name);
|
||||
item.innerHTML = clean;
|
||||
|
||||
this.buildRecipeOperation(item);
|
||||
document.getElementById("rec-list").appendChild(item);
|
||||
|
||||
|
||||
@@ -64,9 +64,9 @@ module.exports = {
|
||||
testOp(browser, ["From Hex", "Bzip2 Decompress"], "425a68393141592653597b0884b7000003038000008200ce00200021a647a4218013709517c5dc914e14241ec2212dc0", "test_output", [[], [true]]);
|
||||
// testOp(browser, "CBOR Decode", "test input", "test output");
|
||||
// testOp(browser, "CBOR Encode", "test input", "test output");
|
||||
testOp(browser, "CRC-16 Checksum", "test input", "77c7");
|
||||
testOp(browser, "CRC-32 Checksum", "test input", "29822bc8");
|
||||
testOp(browser, "CRC-8 Checksum", "test input", "9d");
|
||||
testOp(browser, "CRC Checksum", "test input", "77c7", ["CRC-16"]);
|
||||
testOp(browser, "CRC Checksum", "test input", "29822bc8", ["CRC-32"]);
|
||||
testOp(browser, "CRC Checksum", "test input", "9d", ["CRC-8"]);
|
||||
// testOp(browser, "CSS Beautify", "test input", "test_output");
|
||||
// testOp(browser, "CSS Minify", "test input", "test_output");
|
||||
// testOp(browser, "CSS selector", "test input", "test_output");
|
||||
|
||||
@@ -119,7 +119,7 @@ TestRegister.addApiTests([
|
||||
assert.strictEqual(result[0].module, "Ciphers");
|
||||
assert.strictEqual(result[0].inputType, "string");
|
||||
assert.strictEqual(result[0].outputType, "string");
|
||||
assert.strictEqual(result[0].description, "Triple DES applies DES three times to each block to increase key size.<br><br><b>Key:</b> Triple DES uses a key length of 24 bytes (192 bits).<br>DES uses a key length of 8 bytes (64 bits).<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used as a default.");
|
||||
assert.strictEqual(result[0].description, "Triple DES applies DES three times to each block to increase key size.<br><br><b>Key:</b> Triple DES uses a key length of 24 bytes (192 bits).<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used as a default.");
|
||||
assert.strictEqual(result[0].args.length, 5);
|
||||
}),
|
||||
|
||||
|
||||
@@ -305,16 +305,6 @@ Full hash: $2a$10$ODeP1.6fMsb.ENk2ngPUCO7qTGVPyHA9TqDVcyupyed8FjsiF65L6`;
|
||||
assert.strictEqual(result.toString(), "2");
|
||||
}),
|
||||
|
||||
it("CRC16 Checksum", () => {
|
||||
const result = chef.CRC16Checksum("Rain on Your Parade");
|
||||
assert.strictEqual(result.toString(), "db1c");
|
||||
}),
|
||||
|
||||
it("CRC32 Checksum", () => {
|
||||
const result = chef.CRC32Checksum("Rain on Your Parade");
|
||||
assert.strictEqual(result.toString(), "e902f76c");
|
||||
}),
|
||||
|
||||
it("CSS Beautify", () => {
|
||||
const result = chef.CSSBeautify("header {color:black;padding:3rem;}");
|
||||
const expected = `header {
|
||||
@@ -575,12 +565,11 @@ Top Drawer`, {
|
||||
}),
|
||||
|
||||
it("Generate HOTP", () => {
|
||||
const result = chef.generateHOTP("Cut The Mustard", {
|
||||
name: "colonel",
|
||||
const result = chef.generateHOTP("JBSWY3DPEHPK3PXP", {
|
||||
});
|
||||
const expected = `URI: otpauth://hotp/colonel?secret=IN2XIICUNBSSATLVON2GC4TE
|
||||
const expected = `URI: otpauth://hotp/?secret=JBSWY3DPEHPK3PXP&algorithm=SHA1&digits=6&counter=0
|
||||
|
||||
Password: 034148`;
|
||||
Password: 282760`;
|
||||
assert.strictEqual(result.toString(), expected);
|
||||
}),
|
||||
|
||||
@@ -591,10 +580,25 @@ Password: 034148`;
|
||||
assert.strictEqual(result.toString().substr(0, 37), "-----BEGIN PGP PRIVATE KEY BLOCK-----");
|
||||
}),
|
||||
|
||||
it("Generate UUID", () => {
|
||||
const result = chef.generateUUID();
|
||||
assert.ok(result.toString());
|
||||
assert.strictEqual(result.toString().length, 36);
|
||||
...[1, 3, 4, 5, 6, 7].map(version => it(`Generate UUID v${version}`, () => {
|
||||
const result = chef.generateUUID("", { "version": `v${version}` }).toString();
|
||||
assert.ok(result);
|
||||
assert.strictEqual(result.length, 36);
|
||||
})),
|
||||
|
||||
...[1, 3, 4, 5, 6, 7].map(version => it(`Analyze UUID v${version}`, () => {
|
||||
const uuid = chef.generateUUID("", { "version": `v${version}` }).toString();
|
||||
const result = chef.analyseUUID(uuid).toString();
|
||||
const expected = `UUID version: ${version}`;
|
||||
assert.strictEqual(result, expected);
|
||||
})),
|
||||
|
||||
it("Generate UUID using defaults", () => {
|
||||
const uuid = chef.generateUUID();
|
||||
assert.ok(uuid);
|
||||
|
||||
const analysis = chef.analyseUUID(uuid).toString();
|
||||
assert.strictEqual(analysis, "UUID version: 4");
|
||||
}),
|
||||
|
||||
it("Gzip, Gunzip", () => {
|
||||
|
||||
@@ -11,15 +11,14 @@
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import {
|
||||
setLongTestFailure,
|
||||
logTestReport,
|
||||
} from "../lib/utils.mjs";
|
||||
import { setLongTestFailure, logTestReport } from "../lib/utils.mjs";
|
||||
|
||||
import TestRegister from "../lib/TestRegister.mjs";
|
||||
import "./tests/AESKeyWrap.mjs";
|
||||
import "./tests/AlternatingCaps.mjs";
|
||||
import "./tests/AvroToJSON.mjs";
|
||||
import "./tests/BaconCipher.mjs";
|
||||
import "./tests/Base32.mjs";
|
||||
import "./tests/Base45.mjs";
|
||||
import "./tests/Base58.mjs";
|
||||
import "./tests/Base62.mjs";
|
||||
@@ -30,6 +29,7 @@ import "./tests/BCD.mjs";
|
||||
import "./tests/BitwiseOp.mjs";
|
||||
import "./tests/BLAKE2b.mjs";
|
||||
import "./tests/BLAKE2s.mjs";
|
||||
import "./tests/BLAKE3.mjs";
|
||||
import "./tests/Bombe.mjs";
|
||||
import "./tests/BSON.mjs";
|
||||
import "./tests/ByteRepr.mjs";
|
||||
@@ -44,7 +44,6 @@ import "./tests/ChaCha.mjs";
|
||||
import "./tests/ChangeIPFormat.mjs";
|
||||
import "./tests/CharEnc.mjs";
|
||||
import "./tests/Charts.mjs";
|
||||
import "./tests/Checksum.mjs";
|
||||
import "./tests/Ciphers.mjs";
|
||||
import "./tests/CipherSaber2.mjs";
|
||||
import "./tests/CMAC.mjs";
|
||||
@@ -54,21 +53,26 @@ import "./tests/Comment.mjs";
|
||||
import "./tests/Compress.mjs";
|
||||
import "./tests/ConditionalJump.mjs";
|
||||
import "./tests/ConvertCoordinateFormat.mjs";
|
||||
import "./tests/ConvertLeetSpeak.mjs";
|
||||
import "./tests/ConvertToNATOAlphabet.mjs";
|
||||
import "./tests/CRCChecksum.mjs";
|
||||
import "./tests/Crypt.mjs";
|
||||
import "./tests/CSV.mjs";
|
||||
import "./tests/DateTime.mjs";
|
||||
import "./tests/DefangIP.mjs";
|
||||
import "./tests/DropNthBytes.mjs";
|
||||
import "./tests/ECDSA.mjs";
|
||||
import "./tests/ELFInfo.mjs";
|
||||
import "./tests/Enigma.mjs";
|
||||
import "./tests/ExtractEmailAddresses.mjs";
|
||||
import "./tests/ExtractHashes.mjs";
|
||||
import "./tests/ExtractIPAddresses.mjs";
|
||||
import "./tests/Float.mjs";
|
||||
import "./tests/FileTree.mjs";
|
||||
import "./tests/FletcherChecksum.mjs";
|
||||
import "./tests/Fork.mjs";
|
||||
import "./tests/FromDecimal.mjs";
|
||||
import "./tests/GenerateAllChecksums.mjs";
|
||||
import "./tests/GenerateAllHashes.mjs";
|
||||
import "./tests/GenerateDeBruijnSequence.mjs";
|
||||
import "./tests/GetAllCasings.mjs";
|
||||
@@ -86,6 +90,7 @@ import "./tests/IndexOfCoincidence.mjs";
|
||||
import "./tests/JA3Fingerprint.mjs";
|
||||
import "./tests/JA4.mjs";
|
||||
import "./tests/JA3SFingerprint.mjs";
|
||||
import "./tests/Jsonata.mjs";
|
||||
import "./tests/JSONBeautify.mjs";
|
||||
import "./tests/JSONMinify.mjs";
|
||||
import "./tests/JSONtoCSV.mjs";
|
||||
@@ -102,6 +107,8 @@ import "./tests/LZNT1Decompress.mjs";
|
||||
import "./tests/LZString.mjs";
|
||||
import "./tests/Magic.mjs";
|
||||
import "./tests/Media.mjs";
|
||||
import "./tests/MIMEDecoding.mjs";
|
||||
import "./tests/Modhex.mjs";
|
||||
import "./tests/MorseCode.mjs";
|
||||
import "./tests/MS.mjs";
|
||||
import "./tests/MultipleBombe.mjs";
|
||||
@@ -121,6 +128,7 @@ import "./tests/ParseUDP.mjs";
|
||||
import "./tests/PEMtoHex.mjs";
|
||||
import "./tests/PGP.mjs";
|
||||
import "./tests/PHP.mjs";
|
||||
import "./tests/PHPSerialize.mjs";
|
||||
import "./tests/PowerSet.mjs";
|
||||
import "./tests/Protobuf.mjs";
|
||||
import "./tests/PubKeyFromCert.mjs";
|
||||
@@ -140,20 +148,34 @@ import "./tests/SetIntersection.mjs";
|
||||
import "./tests/SetUnion.mjs";
|
||||
import "./tests/Shuffle.mjs";
|
||||
import "./tests/SIGABA.mjs";
|
||||
import "./tests/SM2.mjs";
|
||||
import "./tests/SM4.mjs";
|
||||
// import "./tests/SplitColourChannels.mjs"; // Cannot test operations that use the File type yet
|
||||
import "./tests/StrUtils.mjs";
|
||||
import "./tests/StripIPv4Header.mjs";
|
||||
import "./tests/StripTCPHeader.mjs";
|
||||
import "./tests/StripUDPHeader.mjs";
|
||||
import "./tests/Subsection.mjs";
|
||||
import "./tests/SwapCase.mjs";
|
||||
import "./tests/SymmetricDifference.mjs";
|
||||
import "./tests/TakeNthBytes.mjs";
|
||||
import "./tests/TextEncodingBruteForce.mjs";
|
||||
import "./tests/ToFromInsensitiveRegex.mjs";
|
||||
import "./tests/TranslateDateTimeFormat.mjs";
|
||||
import "./tests/Typex.mjs";
|
||||
import "./tests/UnescapeString.mjs";
|
||||
import "./tests/Unicode.mjs";
|
||||
import "./tests/URLEncodeDecode.mjs";
|
||||
import "./tests/RSA.mjs";
|
||||
import "./tests/CBOREncode.mjs";
|
||||
import "./tests/CBORDecode.mjs";
|
||||
import "./tests/JA3Fingerprint.mjs";
|
||||
import "./tests/JA3SFingerprint.mjs";
|
||||
import "./tests/HASSH.mjs";
|
||||
import "./tests/JSONtoYAML.mjs";
|
||||
|
||||
// Cannot test operations that use the File type yet
|
||||
// import "./tests/SplitColourChannels.mjs";
|
||||
import "./tests/YARA.mjs";
|
||||
import "./tests/ParseCSR.mjs";
|
||||
import "./tests/XXTEA.mjs";
|
||||
@@ -162,14 +184,14 @@ const testStatus = {
|
||||
allTestsPassing: true,
|
||||
counts: {
|
||||
total: 0,
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
setLongTestFailure();
|
||||
|
||||
const logOpsTestReport = logTestReport.bind(null, testStatus);
|
||||
|
||||
(async function() {
|
||||
(async function () {
|
||||
const results = await TestRegister.runTests();
|
||||
logOpsTestReport(results);
|
||||
})();
|
||||
|
||||
19
tests/operations/tests/AlternatingCaps.mjs
Normal file
19
tests/operations/tests/AlternatingCaps.mjs
Normal file
@@ -0,0 +1,19 @@
|
||||
/* @author sw5678
|
||||
* @copyright Crown Copyright 2024
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
"name": "AlternatingCaps: Basic Example",
|
||||
"input": "Hello, world!",
|
||||
"expectedOutput": "hElLo, WoRlD!",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "Alternating Caps",
|
||||
"args": []
|
||||
},
|
||||
],
|
||||
}
|
||||
]);
|
||||
55
tests/operations/tests/BLAKE3.mjs
Normal file
55
tests/operations/tests/BLAKE3.mjs
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* BLAKE3 tests.
|
||||
* @author xumptex [xumptex@outlook.fr]
|
||||
* @copyright Crown Copyright 2025
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "BLAKE3: 8 - Hello world",
|
||||
input: "Hello world",
|
||||
expectedOutput: "e7e6fb7d2869d109",
|
||||
recipeConfig: [
|
||||
{ "op": "BLAKE3",
|
||||
"args": [8, ""] }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "BLAKE3: 16 - Hello world 2",
|
||||
input: "Hello world 2",
|
||||
expectedOutput: "2a3df5fe5f0d3fcdd995fc203c7f7c52",
|
||||
recipeConfig: [
|
||||
{ "op": "BLAKE3",
|
||||
"args": [16, ""] }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "BLAKE3: 32 - Hello world",
|
||||
input: "Hello world",
|
||||
expectedOutput: "e7e6fb7d2869d109b62cdb1227208d4016cdaa0af6603d95223c6a698137d945",
|
||||
recipeConfig: [
|
||||
{ "op": "BLAKE3",
|
||||
"args": [32, ""] }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "BLAKE3: Key Test",
|
||||
input: "Hello world",
|
||||
expectedOutput: "59dd23ac9d025690",
|
||||
recipeConfig: [
|
||||
{ "op": "BLAKE3",
|
||||
"args": [8, "ThiskeyisexactlythirtytwoBytesLo"] }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "BLAKE3: Key Test 2",
|
||||
input: "Hello world",
|
||||
expectedOutput: "c8302c9634c1da42",
|
||||
recipeConfig: [
|
||||
{ "op": "BLAKE3",
|
||||
"args": [8, "ThiskeyisexactlythirtytwoByteslo"] }
|
||||
]
|
||||
}
|
||||
]);
|
||||
176
tests/operations/tests/Base32.mjs
Normal file
176
tests/operations/tests/Base32.mjs
Normal file
@@ -0,0 +1,176 @@
|
||||
/**
|
||||
* Base32 Tests
|
||||
*
|
||||
* @author Peter C-S [petercs@purelymail.com]
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
import {ALPHABET_OPTIONS} from "../../../src/core/lib/Base32.mjs";
|
||||
|
||||
// Example Standard Base32 Tests
|
||||
const STANDARD_INP = "HELLO BASE32";
|
||||
const STANDARD_OUT = "JBCUYTCPEBBECU2FGMZA====";
|
||||
|
||||
// Example Hex Extended Base32 Tests
|
||||
const EXTENDED_INP = "HELLO BASE32 EXTENDED";
|
||||
const EXTENDED_OUT = "912KOJ2F41142KQ56CP20HAOAH2KSH258G======";
|
||||
|
||||
// All Bytes
|
||||
const ALL_BYTES = [
|
||||
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
|
||||
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
|
||||
"\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f",
|
||||
"\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f",
|
||||
"\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f",
|
||||
"\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f",
|
||||
"\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f",
|
||||
"\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f",
|
||||
"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f",
|
||||
"\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f",
|
||||
"\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf",
|
||||
"\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf",
|
||||
"\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf",
|
||||
"\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf",
|
||||
"\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef",
|
||||
"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
|
||||
].join("");
|
||||
|
||||
const ALL_BYTES_EXTENDED_OUT = "000G40O40K30E209185GO38E1S8124GJ2GAHC5OO34D1M70T3OFI08924CI2A9H750KIKAPC5KN2UC1H68PJ8D9M6SS3IEHR7GUJSFQ085146H258P3KGIAA9D64QJIFA18L4KQKALB5EM2PB9DLONAUBTG62OJ3CHIMCPR8D5L6MR3DDPNN0SBIEDQ7ATJNF1SNKURSFLV7V041GA1O91C6GU48J2KBHI6OT3SGI699754LIQBPH6CQJEE9R7KVK2GQ58T4KMJAFA59LALQPBDELUOB3CLJMIQRDDTON6TBNF5TNQVS1GE2OF2CBHM7P34SLIUCPN7CVK6HQB9T9LEMQVCDJMMRRJETTNV0S7HE7P75SRJUHQFATFMERRNFU3OV5SVKUNRFFU7PVBTVPVFUVS======";
|
||||
const ALL_BYTES_STANDARD_OUT = "AAAQEAYEAUDAOCAJBIFQYDIOB4IBCEQTCQKRMFYYDENBWHA5DYPSAIJCEMSCKJRHFAUSUKZMFUXC6MBRGIZTINJWG44DSOR3HQ6T4P2AIFBEGRCFIZDUQSKKJNGE2TSPKBIVEU2UKVLFOWCZLJNVYXK6L5QGCYTDMRSWMZ3INFVGW3DNNZXXA4LSON2HK5TXPB4XU634PV7H7AEBQKBYJBMGQ6EITCULRSGY5D4QSGJJHFEVS2LZRGM2TOOJ3HU7UCQ2FI5EUWTKPKFJVKV2ZLNOV6YLDMVTWS23NN5YXG5LXPF5X274BQOCYPCMLRWHZDE4VS6MZXHM7UGR2LJ5JVOW27MNTWW33TO55X7A4HROHZHF43T6R2PK5PWO33XP6DY7F47U6X3PP6HZ7L57Z7P674======";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "To Base32 Standard: nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "To Base32",
|
||||
args: [ALPHABET_OPTIONS[0].value],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "To Base32 Hex Extended: nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "To Base32",
|
||||
args: [ALPHABET_OPTIONS[1].value],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "From Base32 Standard: nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Base32",
|
||||
args: [ALPHABET_OPTIONS[0].value, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "From Base32 Hex Extended: nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Base32",
|
||||
args: [ALPHABET_OPTIONS[1].value, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "To Base32 Standard: " + STANDARD_INP,
|
||||
input: STANDARD_INP,
|
||||
expectedOutput: STANDARD_OUT,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "To Base32",
|
||||
args: [ALPHABET_OPTIONS[0].value],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "To Base32 Hex Extended: " + EXTENDED_INP,
|
||||
input: EXTENDED_INP,
|
||||
expectedOutput: EXTENDED_OUT,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "To Base32",
|
||||
args: [ALPHABET_OPTIONS[1].value],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "From Base32 Standard: " + STANDARD_OUT,
|
||||
input: STANDARD_OUT,
|
||||
expectedOutput: STANDARD_INP,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Base32",
|
||||
args: [ALPHABET_OPTIONS[0].value, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "From Base32 Hex Extended: " + EXTENDED_OUT,
|
||||
input: EXTENDED_OUT,
|
||||
expectedOutput: EXTENDED_INP,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Base32",
|
||||
args: [ALPHABET_OPTIONS[1].value, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "To Base32 Hex Standard: All Bytes",
|
||||
input: ALL_BYTES,
|
||||
expectedOutput: ALL_BYTES_STANDARD_OUT,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "To Base32",
|
||||
args: [ALPHABET_OPTIONS[0].value],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "To Base32 Hex Extended: All Bytes",
|
||||
input: ALL_BYTES,
|
||||
expectedOutput: ALL_BYTES_EXTENDED_OUT,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "To Base32",
|
||||
args: [ALPHABET_OPTIONS[1].value],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "From Base32 Hex Standard: All Bytes",
|
||||
input: ALL_BYTES_STANDARD_OUT,
|
||||
expectedOutput: ALL_BYTES,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Base32",
|
||||
args: [ALPHABET_OPTIONS[0].value, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "From Base32 Hex Extended: All Bytes",
|
||||
input: ALL_BYTES_EXTENDED_OUT,
|
||||
expectedOutput: ALL_BYTES,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Base32",
|
||||
args: [ALPHABET_OPTIONS[1].value, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
2054
tests/operations/tests/CRCChecksum.mjs
Normal file
2054
tests/operations/tests/CRCChecksum.mjs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,241 +0,0 @@
|
||||
/**
|
||||
* Checksum tests.
|
||||
*
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
const BASIC_STRING = "The ships hung in the sky in much the same way that bricks don't.";
|
||||
const UTF8_STR = "ნუ პანიკას";
|
||||
const ALL_BYTES = [
|
||||
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
|
||||
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
|
||||
"\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f",
|
||||
"\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f",
|
||||
"\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f",
|
||||
"\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f",
|
||||
"\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f",
|
||||
"\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f",
|
||||
"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f",
|
||||
"\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f",
|
||||
"\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf",
|
||||
"\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf",
|
||||
"\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf",
|
||||
"\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf",
|
||||
"\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef",
|
||||
"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
|
||||
].join("");
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "CRC-8: nothing",
|
||||
input: "",
|
||||
expectedOutput: "00",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "CRC-8 Checksum",
|
||||
"args": ["CRC-8"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CRC-8: default check",
|
||||
input: "123456789",
|
||||
expectedOutput: "f4",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "CRC-8 Checksum",
|
||||
"args": ["CRC-8"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CRC-8: CDMA2000",
|
||||
input: "123456789",
|
||||
expectedOutput: "da",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "CRC-8 Checksum",
|
||||
"args": ["CRC-8/CDMA2000"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CRC-8: DARC",
|
||||
input: "123456789",
|
||||
expectedOutput: "15",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "CRC-8 Checksum",
|
||||
"args": ["CRC-8/DARC"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CRC-8: DVB-S2",
|
||||
input: "123456789",
|
||||
expectedOutput: "bc",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "CRC-8 Checksum",
|
||||
"args": ["CRC-8/DVB-S2"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CRC-8: EBU",
|
||||
input: "123456789",
|
||||
expectedOutput: "97",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "CRC-8 Checksum",
|
||||
"args": ["CRC-8/EBU"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CRC-8: I-CODE",
|
||||
input: "123456789",
|
||||
expectedOutput: "7e",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "CRC-8 Checksum",
|
||||
"args": ["CRC-8/I-CODE"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CRC-8: ITU",
|
||||
input: "123456789",
|
||||
expectedOutput: "a1",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "CRC-8 Checksum",
|
||||
"args": ["CRC-8/ITU"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CRC-8: MAXIM",
|
||||
input: "123456789",
|
||||
expectedOutput: "a1",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "CRC-8 Checksum",
|
||||
"args": ["CRC-8/MAXIM"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CRC-8: ROHC",
|
||||
input: "123456789",
|
||||
expectedOutput: "d0",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "CRC-8 Checksum",
|
||||
"args": ["CRC-8/ROHC"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CRC-8: WCDMA",
|
||||
input: "123456789",
|
||||
expectedOutput: "25",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "CRC-8 Checksum",
|
||||
"args": ["CRC-8/WCDMA"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CRC-16: nothing",
|
||||
input: "",
|
||||
expectedOutput: "0000",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "CRC-16 Checksum",
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CRC-16: basic string",
|
||||
input: BASIC_STRING,
|
||||
expectedOutput: "0c70",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "CRC-16 Checksum",
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CRC-16: UTF-8",
|
||||
input: UTF8_STR,
|
||||
expectedOutput: "dcf6",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "CRC-16 Checksum",
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CRC-16: all bytes",
|
||||
input: ALL_BYTES,
|
||||
expectedOutput: "bad3",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "CRC-16 Checksum",
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CRC-32: nothing",
|
||||
input: "",
|
||||
expectedOutput: "00000000",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "CRC-32 Checksum",
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CRC-32: basic string",
|
||||
input: BASIC_STRING,
|
||||
expectedOutput: "bf4b739c",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "CRC-32 Checksum",
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CRC-32: UTF-8",
|
||||
input: UTF8_STR,
|
||||
expectedOutput: "87553290",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "CRC-32 Checksum",
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CRC-32: all bytes",
|
||||
input: ALL_BYTES,
|
||||
expectedOutput: "29058c73",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "CRC-32 Checksum",
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
||||
@@ -528,4 +528,15 @@ TestRegister.addTests([
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Rail Fence Cipher Encode: Normal with Offset with Spaces",
|
||||
input: "No one expects the spanish Inquisition.",
|
||||
expectedOutput: " e n ut.ooeepcstesaihIqiiinNnxthpsnso",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Rail Fence Cipher Encode",
|
||||
"args": [3, 2]
|
||||
}
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
55
tests/operations/tests/ConvertLeetSpeak.mjs
Normal file
55
tests/operations/tests/ConvertLeetSpeak.mjs
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* @author bartblaze []
|
||||
* @copyright Crown Copyright 2025
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Convert to Leet Speak: basic text",
|
||||
input: "leet",
|
||||
expectedOutput: "l337",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Convert Leet Speak",
|
||||
args: ["To Leet Speak"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Convert from Leet Speak: basic leet",
|
||||
input: "l337",
|
||||
expectedOutput: "leet",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Convert Leet Speak",
|
||||
args: ["From Leet Speak"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Convert to Leet Speak: basic text, keep case",
|
||||
input: "HELLO",
|
||||
expectedOutput: "H3LL0",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Convert Leet Speak",
|
||||
args: ["To Leet Speak"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Convert from Leet Speak: basic leet, keep case",
|
||||
input: "H3LL0",
|
||||
expectedOutput: "HeLLo",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Convert Leet Speak",
|
||||
args: ["From Leet Speak"]
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
||||
|
||||
@@ -580,8 +580,7 @@ Tag: a8f04c4d93bbef82bef61a103371aef9`,
|
||||
input: "",
|
||||
expectedOutput: `Invalid key length: 0 bytes
|
||||
|
||||
DES uses a key length of 8 bytes (64 bits).
|
||||
Triple DES uses a key length of 24 bytes (192 bits).`,
|
||||
DES uses a key length of 8 bytes (64 bits).`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "DES Encrypt",
|
||||
@@ -674,8 +673,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`,
|
||||
input: "",
|
||||
expectedOutput: `Invalid key length: 0 bytes
|
||||
|
||||
Triple DES uses a key length of 24 bytes (192 bits).
|
||||
DES uses a key length of 8 bytes (64 bits).`,
|
||||
Triple DES uses a key length of 24 bytes (192 bits).`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Triple DES Encrypt",
|
||||
@@ -1300,8 +1298,7 @@ The following algorithms will be used based on the size of the key:
|
||||
input: "",
|
||||
expectedOutput: `Invalid key length: 0 bytes
|
||||
|
||||
DES uses a key length of 8 bytes (64 bits).
|
||||
Triple DES uses a key length of 24 bytes (192 bits).`,
|
||||
DES uses a key length of 8 bytes (64 bits).`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "DES Decrypt",
|
||||
@@ -1394,8 +1391,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`,
|
||||
input: "",
|
||||
expectedOutput: `Invalid key length: 0 bytes
|
||||
|
||||
Triple DES uses a key length of 24 bytes (192 bits).
|
||||
DES uses a key length of 8 bytes (64 bits).`,
|
||||
Triple DES uses a key length of 24 bytes (192 bits).`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Triple DES Decrypt",
|
||||
@@ -1579,19 +1575,31 @@ DES uses a key length of 8 bytes (64 bits).`,
|
||||
from Crypto.Cipher import Blowfish
|
||||
import binascii
|
||||
|
||||
input_data = b"The quick brown fox jumps over the lazy dog."
|
||||
# Blowfish cipher parameters - key, mode, iv, segment_size, nonce
|
||||
key = binascii.unhexlify("0011223344556677")
|
||||
iv = binascii.unhexlify("0000000000000000")
|
||||
mode = Blowfish.MODE_CBC
|
||||
kwargs = {}
|
||||
iv = binascii.unhexlify("ffeeddccbbaa9988")
|
||||
if mode in [Blowfish.MODE_CBC, Blowfish.MODE_CFB, Blowfish.MODE_OFB]:
|
||||
kwargs = {"iv": iv}
|
||||
if mode == Blowfish.MODE_CFB:
|
||||
kwargs["segment_size"] = 64
|
||||
if mode == Blowfish.MODE_CTR:
|
||||
nonce = binascii.unhexlify("0000000000000000")
|
||||
nonce = nonce[:7]
|
||||
kwargs["nonce"] = nonce
|
||||
|
||||
cipher = Blowfish.new(key, mode, **kwargs)
|
||||
|
||||
# Input data and padding
|
||||
input_data = b"The quick brown fox jumps over the lazy dog."
|
||||
if mode == Blowfish.MODE_ECB or mode == Blowfish.MODE_CBC:
|
||||
padding_len = 8-(len(input_data) & 7)
|
||||
for i in range(padding_len):
|
||||
input_data += bytes([padding_len])
|
||||
|
||||
cipher = Blowfish.new(key, mode) # set iv, nonce, segment_size etc. here
|
||||
# Encrypted text
|
||||
cipher_text = cipher.encrypt(input_data)
|
||||
|
||||
cipher_text = binascii.hexlify(cipher_text).decode("UTF-8")
|
||||
|
||||
print("Encrypted: {}".format(cipher_text))
|
||||
|
||||
123
tests/operations/tests/DropNthBytes.mjs
Normal file
123
tests/operations/tests/DropNthBytes.mjs
Normal file
@@ -0,0 +1,123 @@
|
||||
/**
|
||||
* @author Oshawk [oshawk@protonmail.com]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
/**
|
||||
* Drop nth bytes tests
|
||||
*/
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Drop nth bytes: Nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Drop nth bytes",
|
||||
args: [4, 0, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Drop nth bytes: Nothing (apply to each line)",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Drop nth bytes",
|
||||
args: [4, 0, true],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Drop nth bytes: Basic single line",
|
||||
input: "0123456789",
|
||||
expectedOutput: "1235679",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Drop nth bytes",
|
||||
args: [4, 0, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Drop nth bytes: Basic single line (apply to each line)",
|
||||
input: "0123456789",
|
||||
expectedOutput: "1235679",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Drop nth bytes",
|
||||
args: [4, 0, true],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Drop nth bytes: Complex single line",
|
||||
input: "0123456789",
|
||||
expectedOutput: "01234678",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Drop nth bytes",
|
||||
args: [4, 5, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Drop nth bytes: Complex single line (apply to each line)",
|
||||
input: "0123456789",
|
||||
expectedOutput: "01234678",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Drop nth bytes",
|
||||
args: [4, 5, true],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Drop nth bytes: Basic multi line",
|
||||
input: "01234\n56789",
|
||||
expectedOutput: "123\n5689",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Drop nth bytes",
|
||||
args: [4, 0, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Drop nth bytes: Basic multi line (apply to each line)",
|
||||
input: "01234\n56789",
|
||||
expectedOutput: "123\n678",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Drop nth bytes",
|
||||
args: [4, 0, true],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Drop nth bytes: Complex multi line",
|
||||
input: "01234\n56789",
|
||||
expectedOutput: "012345679",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Drop nth bytes",
|
||||
args: [4, 5, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Drop nth bytes: Complex multi line (apply to each line)",
|
||||
input: "012345\n6789ab",
|
||||
expectedOutput: "01234\n6789a",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Drop nth bytes",
|
||||
args: [4, 5, true],
|
||||
},
|
||||
],
|
||||
}
|
||||
]);
|
||||
@@ -6,7 +6,10 @@
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
import { ASCII_TEXT } from "../../samples/Ciphers.mjs";
|
||||
import {ALL_BYTES, ASCII_TEXT, UTF8_TEXT} from "../../samples/Ciphers.mjs";
|
||||
|
||||
const SOME_HEX_BYTES = "cdb23f958e018418621d9e489b7bba0f0c481f604eba2eb1ea35e38f99490cc0";
|
||||
const SOME_BASE64_BYTES = "zbI/lY4BhBhiHZ5Im3u6DwxIH2BOui6x6jXjj5lJDMA=";
|
||||
|
||||
const P256 = {
|
||||
// openssl ecparam -name prime256v1 -genkey -noout -out p256.priv.key
|
||||
@@ -104,7 +107,7 @@ TestRegister.addTests([
|
||||
},
|
||||
{
|
||||
"op": "ECDSA Verify",
|
||||
"args": ["ASN.1 HEX", "MD5", P256.publicKey, ASCII_TEXT]
|
||||
"args": ["ASN.1 HEX", "MD5", P256.publicKey, ASCII_TEXT, "Raw"]
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -119,7 +122,7 @@ TestRegister.addTests([
|
||||
},
|
||||
{
|
||||
"op": "ECDSA Verify",
|
||||
"args": ["ASN.1 HEX", "SHA-1", P256.publicKey, ASCII_TEXT]
|
||||
"args": ["ASN.1 HEX", "SHA-1", P256.publicKey, ASCII_TEXT, "Raw"]
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -134,7 +137,7 @@ TestRegister.addTests([
|
||||
},
|
||||
{
|
||||
"op": "ECDSA Verify",
|
||||
"args": ["ASN.1 HEX", "SHA-256", P256.publicKey, ASCII_TEXT]
|
||||
"args": ["ASN.1 HEX", "SHA-256", P256.publicKey, ASCII_TEXT, "Raw"]
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -149,7 +152,7 @@ TestRegister.addTests([
|
||||
},
|
||||
{
|
||||
"op": "ECDSA Verify",
|
||||
"args": ["ASN.1 HEX", "SHA-384", P256.publicKey, ASCII_TEXT]
|
||||
"args": ["ASN.1 HEX", "SHA-384", P256.publicKey, ASCII_TEXT, "Raw"]
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -164,7 +167,7 @@ TestRegister.addTests([
|
||||
},
|
||||
{
|
||||
"op": "ECDSA Verify",
|
||||
"args": ["ASN.1 HEX", "SHA-512", P256.publicKey, ASCII_TEXT]
|
||||
"args": ["ASN.1 HEX", "SHA-512", P256.publicKey, ASCII_TEXT, "Raw"]
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -179,7 +182,7 @@ TestRegister.addTests([
|
||||
},
|
||||
{
|
||||
"op": "ECDSA Verify",
|
||||
"args": ["ASN.1 HEX", "SHA-256", P256.publicKey, ASCII_TEXT]
|
||||
"args": ["ASN.1 HEX", "SHA-256", P256.publicKey, ASCII_TEXT, "Raw"]
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -194,7 +197,7 @@ TestRegister.addTests([
|
||||
},
|
||||
{
|
||||
"op": "ECDSA Verify",
|
||||
"args": ["ASN.1 HEX", "SHA-384", P384.publicKey, ASCII_TEXT]
|
||||
"args": ["ASN.1 HEX", "SHA-384", P384.publicKey, ASCII_TEXT, "Raw"]
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -209,7 +212,7 @@ TestRegister.addTests([
|
||||
},
|
||||
{
|
||||
"op": "ECDSA Verify",
|
||||
"args": ["ASN.1 HEX", "SHA-512", P521.publicKey, ASCII_TEXT]
|
||||
"args": ["ASN.1 HEX", "SHA-512", P521.publicKey, ASCII_TEXT, "Raw"]
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -246,7 +249,7 @@ TestRegister.addTests([
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "ECDSA Verify",
|
||||
"args": ["Auto", "SHA-256", P256.publicKey, ASCII_TEXT]
|
||||
"args": ["Auto", "SHA-256", P256.publicKey, ASCII_TEXT, "Raw"]
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -257,7 +260,7 @@ TestRegister.addTests([
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "ECDSA Verify",
|
||||
"args": ["Auto", "SHA-256", P256.publicKey, ASCII_TEXT]
|
||||
"args": ["Auto", "SHA-256", P256.publicKey, ASCII_TEXT, "Raw"]
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -268,7 +271,7 @@ TestRegister.addTests([
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "ECDSA Verify",
|
||||
"args": ["Auto", "SHA-256", P256.publicKey, ASCII_TEXT]
|
||||
"args": ["Auto", "SHA-256", P256.publicKey, ASCII_TEXT, "Raw"]
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -279,7 +282,7 @@ TestRegister.addTests([
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "ECDSA Verify",
|
||||
"args": ["Auto", "SHA-256", P256.publicKey, ASCII_TEXT]
|
||||
"args": ["Auto", "SHA-256", P256.publicKey, ASCII_TEXT, "Raw"]
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -290,7 +293,7 @@ TestRegister.addTests([
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "ECDSA Verify",
|
||||
"args": ["Auto", "SHA-256", P256.publicKey, ASCII_TEXT]
|
||||
"args": ["Auto", "SHA-256", P256.publicKey, ASCII_TEXT, "Raw"]
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -301,7 +304,7 @@ TestRegister.addTests([
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "ECDSA Verify",
|
||||
"args": ["Auto", "SHA-256", P256.publicKey, ASCII_TEXT]
|
||||
"args": ["Auto", "SHA-256", P256.publicKey, ASCII_TEXT, "Raw"]
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -312,7 +315,7 @@ TestRegister.addTests([
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "ECDSA Verify",
|
||||
"args": ["ASN.1 HEX", "SHA-256", P256.privateKeyPkcs1, ASCII_TEXT]
|
||||
"args": ["ASN.1 HEX", "SHA-256", P256.privateKeyPkcs1, ASCII_TEXT, "Raw"]
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -323,7 +326,7 @@ TestRegister.addTests([
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "ECDSA Verify",
|
||||
"args": ["ASN.1 HEX", "SHA-256", PEM_PUB_RSA512, ASCII_TEXT]
|
||||
"args": ["ASN.1 HEX", "SHA-256", PEM_PUB_RSA512, ASCII_TEXT, "Raw"]
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -460,5 +463,73 @@ TestRegister.addTests([
|
||||
"args": ["Auto", "Raw JSON"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "ECDSA Sign/Verify: P-256 with SHA256 UTF8",
|
||||
input: UTF8_TEXT,
|
||||
expectedOutput: "Verified OK",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "ECDSA Sign",
|
||||
"args": [P256.privateKeyPkcs1, "SHA-256", "ASN.1 HEX"]
|
||||
},
|
||||
{
|
||||
"op": "ECDSA Verify",
|
||||
"args": ["ASN.1 HEX", "SHA-256", P256.publicKey, UTF8_TEXT, "Raw"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "ECDSA Sign/Verify: P-256 with SHA256 bytes raw",
|
||||
input: ALL_BYTES,
|
||||
expectedOutput: "Verified OK",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "ECDSA Sign",
|
||||
"args": [P256.privateKeyPkcs1, "SHA-256", "ASN.1 HEX"]
|
||||
},
|
||||
{
|
||||
"op": "ECDSA Verify",
|
||||
"args": ["ASN.1 HEX", "SHA-256", P256.publicKey, ALL_BYTES, "Raw"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "ECDSA Sign/Verify: P-256 with SHA256 bytes hex",
|
||||
input: SOME_HEX_BYTES,
|
||||
expectedOutput: "Verified OK",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["Auto"]
|
||||
},
|
||||
{
|
||||
"op": "ECDSA Sign",
|
||||
"args": [P256.privateKeyPkcs1, "SHA-256", "ASN.1 HEX"]
|
||||
},
|
||||
{
|
||||
"op": "ECDSA Verify",
|
||||
"args": ["ASN.1 HEX", "SHA-256", P256.publicKey, SOME_HEX_BYTES, "Hex"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "ECDSA Sign/Verify: P-256 with SHA256 bytes Base64",
|
||||
input: SOME_BASE64_BYTES,
|
||||
expectedOutput: "Verified OK",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "From Base64",
|
||||
"args": ["A-Za-z0-9+/=", true]
|
||||
},
|
||||
{
|
||||
"op": "ECDSA Sign",
|
||||
"args": [P256.privateKeyPkcs1, "SHA-256", "ASN.1 HEX"]
|
||||
},
|
||||
{
|
||||
"op": "ECDSA Verify",
|
||||
"args": ["ASN.1 HEX", "SHA-256", P256.publicKey, SOME_BASE64_BYTES, "Base64"]
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
||||
|
||||
133
tests/operations/tests/ExtractIPAddresses.mjs
Normal file
133
tests/operations/tests/ExtractIPAddresses.mjs
Normal file
@@ -0,0 +1,133 @@
|
||||
/**
|
||||
* ExtractIPAddresses tests.
|
||||
*
|
||||
* @author gchqdev365 [gchqdev365@outlook.com]
|
||||
* @copyright Crown Copyright 2025
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "ExtractIPAddress All Zeros",
|
||||
input: "0.0.0.0",
|
||||
expectedOutput: "0.0.0.0",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Extract IP addresses",
|
||||
"args": [true, true, false, false, false, false]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ExtractIPAddress All 10s",
|
||||
input: "10.10.10.10",
|
||||
expectedOutput: "10.10.10.10",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Extract IP addresses",
|
||||
"args": [true, true, false, false, false, false]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ExtractIPAddress All 10s",
|
||||
input: "100.100.100.100",
|
||||
expectedOutput: "100.100.100.100",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Extract IP addresses",
|
||||
"args": [true, true, false, false, false, false]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ExtractIPAddress 255s",
|
||||
input: "255.255.255.255",
|
||||
expectedOutput: "255.255.255.255",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Extract IP addresses",
|
||||
"args": [true, true, false, false, false, false]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ExtractIPAddress double digits",
|
||||
input: "10.10.10.10 25.25.25.25 99.99.99.99",
|
||||
expectedOutput: "10.10.10.10\n25.25.25.25\n99.99.99.99",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Extract IP addresses",
|
||||
"args": [true, true, false, false, false, false]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ExtractIPAddress 256 in middle",
|
||||
input: "255.256.255.255 255.255.256.255",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Extract IP addresses",
|
||||
"args": [true, true, false, false, false, false]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ExtractIPAddress 256 at each end",
|
||||
input: "256.255.255.255 255.255.255.256",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Extract IP addresses",
|
||||
"args": [true, true, false, false, false, false]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ExtractIPAddress silly example",
|
||||
input: "710.65.0.456",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Extract IP addresses",
|
||||
"args": [true, true, false, false, false, false]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ExtractIPAddress longer dotted decimal",
|
||||
input: "1.2.3.4.5.6.7.8",
|
||||
expectedOutput: "1.2.3.4\n5.6.7.8",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Extract IP addresses",
|
||||
"args": [true, true, false, false, false, false]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ExtractIPAddress octal valid",
|
||||
input: "01.01.01.01 0123.0123.0123.0123 0377.0377.0377.0377",
|
||||
expectedOutput: "01.01.01.01\n0123.0123.0123.0123\n0377.0377.0377.0377",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Extract IP addresses",
|
||||
"args": [true, true, false, false, false, false]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ExtractIPAddress octal invalid",
|
||||
input: "0378.01.01.01 03.0377.2.3",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Extract IP addresses",
|
||||
"args": [true, true, false, false, false, false]
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
805
tests/operations/tests/GenerateAllChecksums.mjs
Normal file
805
tests/operations/tests/GenerateAllChecksums.mjs
Normal file
@@ -0,0 +1,805 @@
|
||||
/**
|
||||
* GenerateAllChecksums tests.
|
||||
*
|
||||
* @author r4mos [2k95ljkhg@mozmail.com]
|
||||
* @copyright Crown Copyright 2025
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
const CHECK_STRING = "123456789";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Full generate all checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-3/GSM: 4
|
||||
CRC-3/ROHC: 6
|
||||
CRC-4/G-704: 7
|
||||
CRC-4/INTERLAKEN: b
|
||||
CRC-4/ITU: 7
|
||||
CRC-5/EPC: 00
|
||||
CRC-5/EPC-C1G2: 00
|
||||
CRC-5/G-704: 07
|
||||
CRC-5/ITU: 07
|
||||
CRC-5/USB: 19
|
||||
CRC-6/CDMA2000-A: 0d
|
||||
CRC-6/CDMA2000-B: 3b
|
||||
CRC-6/DARC: 26
|
||||
CRC-6/G-704: 06
|
||||
CRC-6/GSM: 13
|
||||
CRC-6/ITU: 06
|
||||
CRC-7/MMC: 75
|
||||
CRC-7/ROHC: 53
|
||||
CRC-7/UMTS: 61
|
||||
CRC-8: f4
|
||||
CRC-8/8H2F: df
|
||||
CRC-8/AES: 97
|
||||
CRC-8/AUTOSAR: df
|
||||
CRC-8/BLUETOOTH: 26
|
||||
CRC-8/CDMA2000: da
|
||||
CRC-8/DARC: 15
|
||||
CRC-8/DVB-S2: bc
|
||||
CRC-8/EBU: 97
|
||||
CRC-8/GSM-A: 37
|
||||
CRC-8/GSM-B: 94
|
||||
CRC-8/HITAG: b4
|
||||
CRC-8/I-432-1: a1
|
||||
CRC-8/I-CODE: 7e
|
||||
CRC-8/ITU: a1
|
||||
CRC-8/LTE: ea
|
||||
CRC-8/MAXIM: a1
|
||||
CRC-8/MAXIM-DOW: a1
|
||||
CRC-8/MIFARE-MAD: 99
|
||||
CRC-8/NRSC-5: f7
|
||||
CRC-8/OPENSAFETY: 3e
|
||||
CRC-8/ROHC: d0
|
||||
CRC-8/SAE-J1850: 4b
|
||||
CRC-8/SAE-J1850-ZERO: 37
|
||||
CRC-8/SMBUS: f4
|
||||
CRC-8/TECH-3250: 97
|
||||
CRC-8/WCDMA: 25
|
||||
Fletcher-8: 0c
|
||||
CRC-10/ATM: 199
|
||||
CRC-10/CDMA2000: 233
|
||||
CRC-10/GSM: 12a
|
||||
CRC-10/I-610: 199
|
||||
CRC-11/FLEXRAY: 5a3
|
||||
CRC-11/UMTS: 061
|
||||
CRC-12/3GPP: daf
|
||||
CRC-12/CDMA2000: d4d
|
||||
CRC-12/DECT: f5b
|
||||
CRC-12/GSM: b34
|
||||
CRC-12/UMTS: daf
|
||||
CRC-13/BBC: 04fa
|
||||
CRC-14/DARC: 082d
|
||||
CRC-14/GSM: 30ae
|
||||
CRC-15/CAN: 059e
|
||||
CRC-15/MPT1327: 2566
|
||||
CRC-16: bb3d
|
||||
CRC-16/A: bf05
|
||||
CRC-16/ACORN: 31c3
|
||||
CRC-16/ARC: bb3d
|
||||
CRC-16/AUG-CCITT: e5cc
|
||||
CRC-16/AUTOSAR: 29b1
|
||||
CRC-16/B: 906e
|
||||
CRC-16/BLUETOOTH: 2189
|
||||
CRC-16/BUYPASS: fee8
|
||||
CRC-16/CCITT: 2189
|
||||
CRC-16/CCITT-FALSE: 29b1
|
||||
CRC-16/CCITT-TRUE: 2189
|
||||
CRC-16/CCITT-ZERO: 31c3
|
||||
CRC-16/CDMA2000: 4c06
|
||||
CRC-16/CMS: aee7
|
||||
CRC-16/DARC: d64e
|
||||
CRC-16/DDS-110: 9ecf
|
||||
CRC-16/DECT-R: 007e
|
||||
CRC-16/DECT-X: 007f
|
||||
CRC-16/DNP: ea82
|
||||
CRC-16/EN-13757: c2b7
|
||||
CRC-16/EPC: d64e
|
||||
CRC-16/EPC-C1G2: d64e
|
||||
CRC-16/GENIBUS: d64e
|
||||
CRC-16/GSM: ce3c
|
||||
CRC-16/I-CODE: d64e
|
||||
CRC-16/IBM: bb3d
|
||||
CRC-16/IBM-3740: 29b1
|
||||
CRC-16/IBM-SDLC: 906e
|
||||
CRC-16/IEC-61158-2: a819
|
||||
CRC-16/ISO-HDLC: 906e
|
||||
CRC-16/ISO-IEC-14443-3-A: bf05
|
||||
CRC-16/ISO-IEC-14443-3-B: 906e
|
||||
CRC-16/KERMIT: 2189
|
||||
CRC-16/LHA: bb3d
|
||||
CRC-16/LJ1200: bdf4
|
||||
CRC-16/LTE: 31c3
|
||||
CRC-16/M17: 772b
|
||||
CRC-16/MAXIM: 44c2
|
||||
CRC-16/MAXIM-DOW: 44c2
|
||||
CRC-16/MCRF4XX: 6f91
|
||||
CRC-16/MODBUS: 4b37
|
||||
CRC-16/NRSC-5: a066
|
||||
CRC-16/OPENSAFETY-A: 5d38
|
||||
CRC-16/OPENSAFETY-B: 20fe
|
||||
CRC-16/PROFIBUS: a819
|
||||
CRC-16/RIELLO: 63d0
|
||||
CRC-16/SPI-FUJITSU: e5cc
|
||||
CRC-16/T10-DIF: d0db
|
||||
CRC-16/TELEDISK: 0fb3
|
||||
CRC-16/TMS37157: 26b1
|
||||
CRC-16/UMTS: fee8
|
||||
CRC-16/USB: b4c8
|
||||
CRC-16/V-41-LSB: 2189
|
||||
CRC-16/V-41-MSB: 31c3
|
||||
CRC-16/VERIFONE: fee8
|
||||
CRC-16/X-25: 906e
|
||||
CRC-16/XMODEM: 31c3
|
||||
CRC-16/ZMODEM: 31c3
|
||||
Fletcher-16: 1ede
|
||||
CRC-17/CAN-FD: 04f03
|
||||
CRC-21/CAN-FD: 0ed841
|
||||
CRC-24/BLE: c25a56
|
||||
CRC-24/FLEXRAY-A: 7979bd
|
||||
CRC-24/FLEXRAY-B: 1f23b8
|
||||
CRC-24/INTERLAKEN: b4f3e6
|
||||
CRC-24/LTE-A: cde703
|
||||
CRC-24/LTE-B: 23ef52
|
||||
CRC-24/OPENPGP: 21cf02
|
||||
CRC-24/OS-9: 200fa5
|
||||
CRC-30/CDMA: 04c34abf
|
||||
CRC-31/PHILIPS: 0ce9e46c
|
||||
Adler-32: 091e01de
|
||||
CRC-32: cbf43926
|
||||
CRC-32/AAL5: fc891918
|
||||
CRC-32/ADCCP: cbf43926
|
||||
CRC-32/AIXM: 3010bf7f
|
||||
CRC-32/AUTOSAR: 1697d06a
|
||||
CRC-32/BASE91-C: e3069283
|
||||
CRC-32/BASE91-D: 87315576
|
||||
CRC-32/BZIP2: fc891918
|
||||
CRC-32/C: e3069283
|
||||
CRC-32/CASTAGNOLI: e3069283
|
||||
CRC-32/CD-ROM-EDC: 6ec2edc4
|
||||
CRC-32/CKSUM: 765e7680
|
||||
CRC-32/D: 87315576
|
||||
CRC-32/DECT-B: fc891918
|
||||
CRC-32/INTERLAKEN: e3069283
|
||||
CRC-32/ISCSI: e3069283
|
||||
CRC-32/ISO-HDLC: cbf43926
|
||||
CRC-32/JAMCRC: 340bc6d9
|
||||
CRC-32/MEF: d2c22f51
|
||||
CRC-32/MPEG-2: 0376e6e7
|
||||
CRC-32/NVME: e3069283
|
||||
CRC-32/PKZIP: cbf43926
|
||||
CRC-32/POSIX: 765e7680
|
||||
CRC-32/Q: 3010bf7f
|
||||
CRC-32/SATA: cf72afe8
|
||||
CRC-32/V-42: cbf43926
|
||||
CRC-32/XFER: bd0be338
|
||||
CRC-32/XZ: cbf43926
|
||||
Fletcher-32: df09d509
|
||||
CRC-40/GSM: d4164fc646
|
||||
CRC-64/ECMA-182: 6c40df5f0b497347
|
||||
CRC-64/GO-ECMA: 995dc9bbdf1939fa
|
||||
CRC-64/GO-ISO: b90956c775a41001
|
||||
CRC-64/MS: 75d4b74f024eceea
|
||||
CRC-64/NVME: ae8b14860a799888
|
||||
CRC-64/REDIS: e9c6d914c4b8d9ca
|
||||
CRC-64/WE: 62ec59e3f1a4f00a
|
||||
CRC-64/XZ: 995dc9bbdf1939fa
|
||||
Fletcher-64: 0d0803376c6a689f
|
||||
CRC-82/DARC: 09ea83f625023801fd612
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["All", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate all checksums without name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `4
|
||||
6
|
||||
7
|
||||
b
|
||||
7
|
||||
00
|
||||
00
|
||||
07
|
||||
07
|
||||
19
|
||||
0d
|
||||
3b
|
||||
26
|
||||
06
|
||||
13
|
||||
06
|
||||
75
|
||||
53
|
||||
61
|
||||
f4
|
||||
df
|
||||
97
|
||||
df
|
||||
26
|
||||
da
|
||||
15
|
||||
bc
|
||||
97
|
||||
37
|
||||
94
|
||||
b4
|
||||
a1
|
||||
7e
|
||||
a1
|
||||
ea
|
||||
a1
|
||||
a1
|
||||
99
|
||||
f7
|
||||
3e
|
||||
d0
|
||||
4b
|
||||
37
|
||||
f4
|
||||
97
|
||||
25
|
||||
0c
|
||||
199
|
||||
233
|
||||
12a
|
||||
199
|
||||
5a3
|
||||
061
|
||||
daf
|
||||
d4d
|
||||
f5b
|
||||
b34
|
||||
daf
|
||||
04fa
|
||||
082d
|
||||
30ae
|
||||
059e
|
||||
2566
|
||||
bb3d
|
||||
bf05
|
||||
31c3
|
||||
bb3d
|
||||
e5cc
|
||||
29b1
|
||||
906e
|
||||
2189
|
||||
fee8
|
||||
2189
|
||||
29b1
|
||||
2189
|
||||
31c3
|
||||
4c06
|
||||
aee7
|
||||
d64e
|
||||
9ecf
|
||||
007e
|
||||
007f
|
||||
ea82
|
||||
c2b7
|
||||
d64e
|
||||
d64e
|
||||
d64e
|
||||
ce3c
|
||||
d64e
|
||||
bb3d
|
||||
29b1
|
||||
906e
|
||||
a819
|
||||
906e
|
||||
bf05
|
||||
906e
|
||||
2189
|
||||
bb3d
|
||||
bdf4
|
||||
31c3
|
||||
772b
|
||||
44c2
|
||||
44c2
|
||||
6f91
|
||||
4b37
|
||||
a066
|
||||
5d38
|
||||
20fe
|
||||
a819
|
||||
63d0
|
||||
e5cc
|
||||
d0db
|
||||
0fb3
|
||||
26b1
|
||||
fee8
|
||||
b4c8
|
||||
2189
|
||||
31c3
|
||||
fee8
|
||||
906e
|
||||
31c3
|
||||
31c3
|
||||
1ede
|
||||
04f03
|
||||
0ed841
|
||||
c25a56
|
||||
7979bd
|
||||
1f23b8
|
||||
b4f3e6
|
||||
cde703
|
||||
23ef52
|
||||
21cf02
|
||||
200fa5
|
||||
04c34abf
|
||||
0ce9e46c
|
||||
091e01de
|
||||
cbf43926
|
||||
fc891918
|
||||
cbf43926
|
||||
3010bf7f
|
||||
1697d06a
|
||||
e3069283
|
||||
87315576
|
||||
fc891918
|
||||
e3069283
|
||||
e3069283
|
||||
6ec2edc4
|
||||
765e7680
|
||||
87315576
|
||||
fc891918
|
||||
e3069283
|
||||
e3069283
|
||||
cbf43926
|
||||
340bc6d9
|
||||
d2c22f51
|
||||
0376e6e7
|
||||
e3069283
|
||||
cbf43926
|
||||
765e7680
|
||||
3010bf7f
|
||||
cf72afe8
|
||||
cbf43926
|
||||
bd0be338
|
||||
cbf43926
|
||||
df09d509
|
||||
d4164fc646
|
||||
6c40df5f0b497347
|
||||
995dc9bbdf1939fa
|
||||
b90956c775a41001
|
||||
75d4b74f024eceea
|
||||
ae8b14860a799888
|
||||
e9c6d914c4b8d9ca
|
||||
62ec59e3f1a4f00a
|
||||
995dc9bbdf1939fa
|
||||
0d0803376c6a689f
|
||||
09ea83f625023801fd612
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["All", false]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 3 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-3/GSM: 4
|
||||
CRC-3/ROHC: 6
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["3", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 4 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-4/G-704: 7
|
||||
CRC-4/INTERLAKEN: b
|
||||
CRC-4/ITU: 7
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["4", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 5 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-5/EPC: 00
|
||||
CRC-5/EPC-C1G2: 00
|
||||
CRC-5/G-704: 07
|
||||
CRC-5/ITU: 07
|
||||
CRC-5/USB: 19
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["5", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 6 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-6/CDMA2000-A: 0d
|
||||
CRC-6/CDMA2000-B: 3b
|
||||
CRC-6/DARC: 26
|
||||
CRC-6/G-704: 06
|
||||
CRC-6/GSM: 13
|
||||
CRC-6/ITU: 06
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["6", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 7 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-7/MMC: 75
|
||||
CRC-7/ROHC: 53
|
||||
CRC-7/UMTS: 61
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["7", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 8 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-8: f4
|
||||
CRC-8/8H2F: df
|
||||
CRC-8/AES: 97
|
||||
CRC-8/AUTOSAR: df
|
||||
CRC-8/BLUETOOTH: 26
|
||||
CRC-8/CDMA2000: da
|
||||
CRC-8/DARC: 15
|
||||
CRC-8/DVB-S2: bc
|
||||
CRC-8/EBU: 97
|
||||
CRC-8/GSM-A: 37
|
||||
CRC-8/GSM-B: 94
|
||||
CRC-8/HITAG: b4
|
||||
CRC-8/I-432-1: a1
|
||||
CRC-8/I-CODE: 7e
|
||||
CRC-8/ITU: a1
|
||||
CRC-8/LTE: ea
|
||||
CRC-8/MAXIM: a1
|
||||
CRC-8/MAXIM-DOW: a1
|
||||
CRC-8/MIFARE-MAD: 99
|
||||
CRC-8/NRSC-5: f7
|
||||
CRC-8/OPENSAFETY: 3e
|
||||
CRC-8/ROHC: d0
|
||||
CRC-8/SAE-J1850: 4b
|
||||
CRC-8/SAE-J1850-ZERO: 37
|
||||
CRC-8/SMBUS: f4
|
||||
CRC-8/TECH-3250: 97
|
||||
CRC-8/WCDMA: 25
|
||||
Fletcher-8: 0c
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["8", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 10 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-10/ATM: 199
|
||||
CRC-10/CDMA2000: 233
|
||||
CRC-10/GSM: 12a
|
||||
CRC-10/I-610: 199
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["10", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 11 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-11/FLEXRAY: 5a3
|
||||
CRC-11/UMTS: 061
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["11", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 12 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-12/3GPP: daf
|
||||
CRC-12/CDMA2000: d4d
|
||||
CRC-12/DECT: f5b
|
||||
CRC-12/GSM: b34
|
||||
CRC-12/UMTS: daf
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["12", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 13 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-13/BBC: 04fa
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["13", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 14 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-14/DARC: 082d
|
||||
CRC-14/GSM: 30ae
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["14", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 15 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-15/CAN: 059e
|
||||
CRC-15/MPT1327: 2566
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["15", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 16 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-16: bb3d
|
||||
CRC-16/A: bf05
|
||||
CRC-16/ACORN: 31c3
|
||||
CRC-16/ARC: bb3d
|
||||
CRC-16/AUG-CCITT: e5cc
|
||||
CRC-16/AUTOSAR: 29b1
|
||||
CRC-16/B: 906e
|
||||
CRC-16/BLUETOOTH: 2189
|
||||
CRC-16/BUYPASS: fee8
|
||||
CRC-16/CCITT: 2189
|
||||
CRC-16/CCITT-FALSE: 29b1
|
||||
CRC-16/CCITT-TRUE: 2189
|
||||
CRC-16/CCITT-ZERO: 31c3
|
||||
CRC-16/CDMA2000: 4c06
|
||||
CRC-16/CMS: aee7
|
||||
CRC-16/DARC: d64e
|
||||
CRC-16/DDS-110: 9ecf
|
||||
CRC-16/DECT-R: 007e
|
||||
CRC-16/DECT-X: 007f
|
||||
CRC-16/DNP: ea82
|
||||
CRC-16/EN-13757: c2b7
|
||||
CRC-16/EPC: d64e
|
||||
CRC-16/EPC-C1G2: d64e
|
||||
CRC-16/GENIBUS: d64e
|
||||
CRC-16/GSM: ce3c
|
||||
CRC-16/I-CODE: d64e
|
||||
CRC-16/IBM: bb3d
|
||||
CRC-16/IBM-3740: 29b1
|
||||
CRC-16/IBM-SDLC: 906e
|
||||
CRC-16/IEC-61158-2: a819
|
||||
CRC-16/ISO-HDLC: 906e
|
||||
CRC-16/ISO-IEC-14443-3-A: bf05
|
||||
CRC-16/ISO-IEC-14443-3-B: 906e
|
||||
CRC-16/KERMIT: 2189
|
||||
CRC-16/LHA: bb3d
|
||||
CRC-16/LJ1200: bdf4
|
||||
CRC-16/LTE: 31c3
|
||||
CRC-16/M17: 772b
|
||||
CRC-16/MAXIM: 44c2
|
||||
CRC-16/MAXIM-DOW: 44c2
|
||||
CRC-16/MCRF4XX: 6f91
|
||||
CRC-16/MODBUS: 4b37
|
||||
CRC-16/NRSC-5: a066
|
||||
CRC-16/OPENSAFETY-A: 5d38
|
||||
CRC-16/OPENSAFETY-B: 20fe
|
||||
CRC-16/PROFIBUS: a819
|
||||
CRC-16/RIELLO: 63d0
|
||||
CRC-16/SPI-FUJITSU: e5cc
|
||||
CRC-16/T10-DIF: d0db
|
||||
CRC-16/TELEDISK: 0fb3
|
||||
CRC-16/TMS37157: 26b1
|
||||
CRC-16/UMTS: fee8
|
||||
CRC-16/USB: b4c8
|
||||
CRC-16/V-41-LSB: 2189
|
||||
CRC-16/V-41-MSB: 31c3
|
||||
CRC-16/VERIFONE: fee8
|
||||
CRC-16/X-25: 906e
|
||||
CRC-16/XMODEM: 31c3
|
||||
CRC-16/ZMODEM: 31c3
|
||||
Fletcher-16: 1ede
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["16", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 17 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-17/CAN-FD: 04f03
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["17", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 21 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-21/CAN-FD: 0ed841
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["21", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 24 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-24/BLE: c25a56
|
||||
CRC-24/FLEXRAY-A: 7979bd
|
||||
CRC-24/FLEXRAY-B: 1f23b8
|
||||
CRC-24/INTERLAKEN: b4f3e6
|
||||
CRC-24/LTE-A: cde703
|
||||
CRC-24/LTE-B: 23ef52
|
||||
CRC-24/OPENPGP: 21cf02
|
||||
CRC-24/OS-9: 200fa5
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["24", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 30 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-30/CDMA: 04c34abf
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["30", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 31 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-31/PHILIPS: 0ce9e46c
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["31", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 32 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `Adler-32: 091e01de
|
||||
CRC-32: cbf43926
|
||||
CRC-32/AAL5: fc891918
|
||||
CRC-32/ADCCP: cbf43926
|
||||
CRC-32/AIXM: 3010bf7f
|
||||
CRC-32/AUTOSAR: 1697d06a
|
||||
CRC-32/BASE91-C: e3069283
|
||||
CRC-32/BASE91-D: 87315576
|
||||
CRC-32/BZIP2: fc891918
|
||||
CRC-32/C: e3069283
|
||||
CRC-32/CASTAGNOLI: e3069283
|
||||
CRC-32/CD-ROM-EDC: 6ec2edc4
|
||||
CRC-32/CKSUM: 765e7680
|
||||
CRC-32/D: 87315576
|
||||
CRC-32/DECT-B: fc891918
|
||||
CRC-32/INTERLAKEN: e3069283
|
||||
CRC-32/ISCSI: e3069283
|
||||
CRC-32/ISO-HDLC: cbf43926
|
||||
CRC-32/JAMCRC: 340bc6d9
|
||||
CRC-32/MEF: d2c22f51
|
||||
CRC-32/MPEG-2: 0376e6e7
|
||||
CRC-32/NVME: e3069283
|
||||
CRC-32/PKZIP: cbf43926
|
||||
CRC-32/POSIX: 765e7680
|
||||
CRC-32/Q: 3010bf7f
|
||||
CRC-32/SATA: cf72afe8
|
||||
CRC-32/V-42: cbf43926
|
||||
CRC-32/XFER: bd0be338
|
||||
CRC-32/XZ: cbf43926
|
||||
Fletcher-32: df09d509
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["32", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 40 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-40/GSM: d4164fc646
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["40", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 64 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-64/ECMA-182: 6c40df5f0b497347
|
||||
CRC-64/GO-ECMA: 995dc9bbdf1939fa
|
||||
CRC-64/GO-ISO: b90956c775a41001
|
||||
CRC-64/MS: 75d4b74f024eceea
|
||||
CRC-64/NVME: ae8b14860a799888
|
||||
CRC-64/REDIS: e9c6d914c4b8d9ca
|
||||
CRC-64/WE: 62ec59e3f1a4f00a
|
||||
CRC-64/XZ: 995dc9bbdf1939fa
|
||||
Fletcher-64: 0d0803376c6a689f
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["64", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Full generate 82 bits checksums with name",
|
||||
input: CHECK_STRING,
|
||||
expectedOutput: `CRC-82/DARC: 09ea83f625023801fd612
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all checksums",
|
||||
"args": ["82", true]
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
||||
@@ -54,16 +54,6 @@ LM Hash: 01FC5A6BE7BC6929AAD3B435B51404EE
|
||||
NT Hash: 0CB6948805F797BF2A82807973B89537
|
||||
SSDEEP: 3:Hn:Hn
|
||||
CTPH: A:E:E
|
||||
|
||||
Checksums:
|
||||
Fletcher-8: 3d
|
||||
Fletcher-16: 5dc1
|
||||
Fletcher-32: 3f5cd9e7
|
||||
Fletcher-64: 7473657474736574
|
||||
Adler-32: 045d01c1
|
||||
CRC-8: b9
|
||||
CRC-16: f82e
|
||||
CRC-32: d87f7e0c
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
|
||||
63
tests/operations/tests/IPv6Transition.mjs
Normal file
63
tests/operations/tests/IPv6Transition.mjs
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* IPv6Transition tests.
|
||||
*
|
||||
* @author jb30795
|
||||
*
|
||||
* @copyright Crown Copyright 2024
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "IPv6 Transition: IPv4 to IPv6",
|
||||
input: "198.51.100.7",
|
||||
expectedOutput: "6to4: 2002:c633:6407::/48\nIPv4 Mapped: ::ffff:c633:6407\nIPv4 Translated: ::ffff:0:c633:6407\nNat 64: 64:ff9b::c633:6407",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "IPv6 Transition Addresses",
|
||||
args: [true, false],
|
||||
},
|
||||
],
|
||||
}, {
|
||||
name: "IPv6 Transition: IPv4 /24 Range to IPv6",
|
||||
input: "198.51.100.0/24",
|
||||
expectedOutput: "6to4: 2002:c633:6400::/40\nIPv4 Mapped: ::ffff:c633:6400/120\nIPv4 Translated: ::ffff:0:c633:6400/120\nNat 64: 64:ff9b::c633:6400/120",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "IPv6 Transition Addresses",
|
||||
args: [false, false],
|
||||
},
|
||||
],
|
||||
}, {
|
||||
name: "IPv6 Transition: IPv4 to IPv6 Remove headers",
|
||||
input: "198.51.100.7",
|
||||
expectedOutput: "2002:c633:6407::/48\n::ffff:c633:6407\n::ffff:0:c633:6407\n64:ff9b::c633:6407",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "IPv6 Transition Addresses",
|
||||
args: [true, true],
|
||||
},
|
||||
],
|
||||
}, {
|
||||
name: "IPv6 Transition: IPv6 to IPv4",
|
||||
input: "64:ff9b::c633:6407",
|
||||
expectedOutput: "IPv4: 198.51.100.7",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "IPv6 Transition Addresses",
|
||||
args: [true, false],
|
||||
},
|
||||
],
|
||||
}, {
|
||||
name: "IPv6 Transition: MAC to EUI-64",
|
||||
input: "a1:b2:c3:d4:e5:f6",
|
||||
expectedOutput: "EUI-64 Interface ID: a3b2:c3ff:fed4:e5f6",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "IPv6 Transition Addresses",
|
||||
args: [true, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
41
tests/operations/tests/JSONtoYAML.mjs
Normal file
41
tests/operations/tests/JSONtoYAML.mjs
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* YAML tests.
|
||||
*
|
||||
* @author ccarpo [ccarpo@gmx.net]
|
||||
*
|
||||
* @copyright Crown Copyright 2021
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
const EXAMPLE_YAML = `number: 3\nplain: string\nblock: |\n two\n lines`;
|
||||
const EXAMPLE_JSON = `{ "number": 3, "plain": "string" }`;
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "YAML to JSON",
|
||||
input: EXAMPLE_YAML,
|
||||
expectedOutput: JSON.stringify({
|
||||
"number": 3,
|
||||
"plain": "string",
|
||||
"block": "two\nlines\n"
|
||||
}, null, 4),
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "YAML to JSON",
|
||||
args: [],
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "JSON to YAML",
|
||||
input: EXAMPLE_JSON,
|
||||
expectedOutput: `number: 3\nplain: string\n`,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "JSON to YAML",
|
||||
args: [],
|
||||
}
|
||||
],
|
||||
},
|
||||
]);
|
||||
551
tests/operations/tests/Jsonata.mjs
Normal file
551
tests/operations/tests/Jsonata.mjs
Normal file
@@ -0,0 +1,551 @@
|
||||
/**
|
||||
* Jsonata Query tests.
|
||||
*
|
||||
* @author Jon King [jon@ajarsoftware.com]
|
||||
*
|
||||
* @copyright Crown Copyright 2025
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
const INPUT_JSON_OBJECT_WITH_ARRAYS = `{
|
||||
"FirstName": "Fred",
|
||||
"Surname": "Smith",
|
||||
"Age": 28,
|
||||
"Address": {
|
||||
"Street": "Hursley Park",
|
||||
"City": "Winchester",
|
||||
"Postcode": "SO21 2JN"
|
||||
},
|
||||
"Phone": [
|
||||
{
|
||||
"type": "home",
|
||||
"number": "0203 544 1234"
|
||||
},
|
||||
{
|
||||
"type": "office",
|
||||
"number": "01962 001234"
|
||||
},
|
||||
{
|
||||
"type": "office",
|
||||
"number": "01962 001235"
|
||||
},
|
||||
{
|
||||
"type": "mobile",
|
||||
"number": "077 7700 1234"
|
||||
}
|
||||
],
|
||||
"Email": [
|
||||
{
|
||||
"type": "work",
|
||||
"address": ["fred.smith@my-work.com", "fsmith@my-work.com"]
|
||||
},
|
||||
{
|
||||
"type": "home",
|
||||
"address": ["freddy@my-social.com", "frederic.smith@very-serious.com"]
|
||||
}
|
||||
],
|
||||
"Other": {
|
||||
"Over 18 ?": true,
|
||||
"Misc": null,
|
||||
"Alternative.Address": {
|
||||
"Street": "Brick Lane",
|
||||
"City": "London",
|
||||
"Postcode": "E1 6RF"
|
||||
}
|
||||
}
|
||||
}`;
|
||||
|
||||
const INPUT_ARRAY_OF_OBJECTS = `[
|
||||
{ "ref": [ 1,2 ] },
|
||||
{ "ref": [ 3,4 ] }
|
||||
]`;
|
||||
|
||||
const INPUT_NUMBER_ARRAY = `{
|
||||
"Numbers": [1, 2.4, 3.5, 10, 20.9, 30]
|
||||
}`;
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Jsonata: Returns a JSON string (double quoted)",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: '"Smith"',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Surname"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Returns a JSON number",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: "28",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Age"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Field references are separated by '.'",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: '"Winchester"',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Address.City"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Matched the path and returns the null value",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: "null",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Other.Misc"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Path not found. Returns nothing",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: '""',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Other.DoesntExist"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Field references containing whitespace or reserved tokens can be enclosed in backticks",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: "true",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Other.`Over 18 ?`"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Returns the first item (an object)",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: '{"type":"home","number":"0203 544 1234"}',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Phone[0]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Returns the second item",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: '{"type":"office","number":"01962 001234"}',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Phone[1]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Returns the last item",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: '{"type":"mobile","number":"077 7700 1234"}',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Phone[-1]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Negative indexed count from the end",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: '{"type":"office","number":"01962 001235"}',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Phone[-2]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Doesn't exist - returns nothing",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: '""',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Phone[8]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Selects the number field in the first item",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: '"0203 544 1234"',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Phone[0].number"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: No index is given to Phone so it selects all of them (the whole array), then it selects all the number fields for each of them",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput:
|
||||
'["0203 544 1234","01962 001234","01962 001235","077 7700 1234"]',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Phone.number"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Might expect it to just return the first number, but it returns the first number of each of the items selected by Phone",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput:
|
||||
'["0203 544 1234","01962 001234","01962 001235","077 7700 1234"]',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Phone.number[0]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Applies the index to the array returned by Phone.number.",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: '"0203 544 1234"',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["(Phone.number)[0]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Returns a range of items by creating an array of indexes",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput:
|
||||
'[{"type":"home","number":"0203 544 1234"},{"type":"office","number":"01962 001234"}]',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Phone[[0..1]]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
// Predicates
|
||||
{
|
||||
name: "Jsonata: Select the Phone items that have a type field that equals 'mobile'",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: '{"type":"mobile","number":"077 7700 1234"}',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Phone[type='mobile']"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Select the mobile phone number",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: '"077 7700 1234"',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Phone[type='mobile'].number"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Select the office phone numbers - there are two of them",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: '["01962 001234","01962 001235"]',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Phone[type='office'].number"],
|
||||
},
|
||||
],
|
||||
},
|
||||
// Wildcards
|
||||
{
|
||||
name: "Jsonata: Select the values of all the fields of 'Address'",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: '["Hursley Park","Winchester","SO21 2JN"]',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Address.*"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Select the 'Postcode' value of any child object",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: '"SO21 2JN"',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["*.Postcode"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Select all Postcode values, regardless of how deeply nested they are in the structure",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: '["SO21 2JN","E1 6RF"]',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["**.Postcode"],
|
||||
},
|
||||
],
|
||||
},
|
||||
// String Expressions
|
||||
{
|
||||
name: "Jsonata: Concatenate 'FirstName' followed by space followed by 'Surname'",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: '"Fred Smith"',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["FirstName & ' ' & Surname"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Concatenates the 'Street' and 'City' from the 'Address' object with a comma separator",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: '"Hursley Park, Winchester"',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Address.(Street & ', ' & City)"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Casts the operands to strings, if necessary",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: '"50true"',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["5&0&true"],
|
||||
},
|
||||
],
|
||||
},
|
||||
// Numeric Expressions
|
||||
{
|
||||
name: "Jsonata: Addition",
|
||||
input: INPUT_NUMBER_ARRAY,
|
||||
expectedOutput: "3.4",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Numbers[0] + Numbers[1]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Subtraction",
|
||||
input: INPUT_NUMBER_ARRAY,
|
||||
expectedOutput: "-19.9",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Numbers[0] - Numbers[4]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Multiplication",
|
||||
input: INPUT_NUMBER_ARRAY,
|
||||
expectedOutput: "30",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Numbers[0] * Numbers[5]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Division",
|
||||
input: INPUT_NUMBER_ARRAY,
|
||||
expectedOutput: "0.04784688995215311",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Numbers[0] / Numbers[4]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Modulus",
|
||||
input: INPUT_NUMBER_ARRAY,
|
||||
expectedOutput: "3.5",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Numbers[2] % Numbers[5]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Equality",
|
||||
input: INPUT_NUMBER_ARRAY,
|
||||
expectedOutput: "false",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Numbers[0] = Numbers[5]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Inequality",
|
||||
input: INPUT_NUMBER_ARRAY,
|
||||
expectedOutput: "true",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Numbers[0] != Numbers[4]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Less than",
|
||||
input: INPUT_NUMBER_ARRAY,
|
||||
expectedOutput: "true",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Numbers[0] < Numbers[4]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Less than or equal to",
|
||||
input: INPUT_NUMBER_ARRAY,
|
||||
expectedOutput: "true",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Numbers[0] <= Numbers[4]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Greater than",
|
||||
input: INPUT_NUMBER_ARRAY,
|
||||
expectedOutput: "false",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Numbers[0] > Numbers[4]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Greater than or equal to",
|
||||
input: INPUT_NUMBER_ARRAY,
|
||||
expectedOutput: "false",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["Numbers[2] >= Numbers[4]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: Value is contained in",
|
||||
input: INPUT_JSON_OBJECT_WITH_ARRAYS,
|
||||
expectedOutput: "true",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ['"01962 001234" in Phone.number'],
|
||||
},
|
||||
],
|
||||
},
|
||||
// Boolean Expressions
|
||||
{
|
||||
name: "Jsonata: and",
|
||||
input: INPUT_NUMBER_ARRAY,
|
||||
expectedOutput: "true",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["(Numbers[2] != 0) and (Numbers[5] != Numbers[1])"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: or",
|
||||
input: INPUT_NUMBER_ARRAY,
|
||||
expectedOutput: "true",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["(Numbers[2] != 0) or (Numbers[5] = Numbers[1])"],
|
||||
},
|
||||
],
|
||||
},
|
||||
// Array tests
|
||||
{
|
||||
name: "Jsonata: $ at the start of an expression refers to the entire input document, subscripting it with 0 selects the first item",
|
||||
input: INPUT_ARRAY_OF_OBJECTS,
|
||||
expectedOutput: '{"ref":[1,2]}',
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["$[0]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: .ref here returns the entire internal array",
|
||||
input: INPUT_ARRAY_OF_OBJECTS,
|
||||
expectedOutput: "[1,2]",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["$[0].ref"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: returns element on first position of the internal array",
|
||||
input: INPUT_ARRAY_OF_OBJECTS,
|
||||
expectedOutput: "1",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["$[0].ref[0]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jsonata: $.field_reference flattens the result into a single array",
|
||||
input: INPUT_ARRAY_OF_OBJECTS,
|
||||
expectedOutput: "[1,2,3,4]",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jsonata Query",
|
||||
args: ["$.ref"],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
@@ -2,11 +2,392 @@
|
||||
* From Decimal tests
|
||||
*
|
||||
* @author n1073645 [n1073645@gmail.com]
|
||||
* @author k3ach [k3ach@proton.me]
|
||||
* @copyright Crown Copyright 2020
|
||||
* @licence Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
const testCases = [
|
||||
{
|
||||
radix: 2,
|
||||
input: "01",
|
||||
checksum: "1",
|
||||
checkdigit: "1",
|
||||
}, {
|
||||
radix: 2,
|
||||
input: "001111",
|
||||
checksum: "0",
|
||||
checkdigit: "0",
|
||||
}, {
|
||||
radix: 2,
|
||||
input: "00011101",
|
||||
checksum: "0",
|
||||
checkdigit: "0",
|
||||
}, {
|
||||
radix: 2,
|
||||
input: "0100101101",
|
||||
checksum: "1",
|
||||
checkdigit: "1",
|
||||
}, {
|
||||
radix: 4,
|
||||
input: "0123",
|
||||
checksum: "1",
|
||||
checkdigit: "1",
|
||||
}, {
|
||||
radix: 4,
|
||||
input: "130100",
|
||||
checksum: "2",
|
||||
checkdigit: "2",
|
||||
}, {
|
||||
radix: 4,
|
||||
input: "32020313",
|
||||
checksum: "3",
|
||||
checkdigit: "0",
|
||||
}, {
|
||||
radix: 4,
|
||||
input: "302233210112",
|
||||
checksum: "3",
|
||||
checkdigit: "0",
|
||||
}, {
|
||||
radix: 6,
|
||||
input: "012345",
|
||||
checksum: "4",
|
||||
checkdigit: "4",
|
||||
}, {
|
||||
radix: 6,
|
||||
input: "134255",
|
||||
checksum: "2",
|
||||
checkdigit: "4",
|
||||
}, {
|
||||
radix: 6,
|
||||
input: "15021453",
|
||||
checksum: "5",
|
||||
checkdigit: "4",
|
||||
}, {
|
||||
radix: 6,
|
||||
input: "211450230513",
|
||||
checksum: "3",
|
||||
checkdigit: "1",
|
||||
}, {
|
||||
radix: 8,
|
||||
input: "01234567",
|
||||
checksum: "2",
|
||||
checkdigit: "2",
|
||||
}, {
|
||||
radix: 8,
|
||||
input: "340624",
|
||||
checksum: "0",
|
||||
checkdigit: "4",
|
||||
}, {
|
||||
radix: 8,
|
||||
input: "07260247",
|
||||
checksum: "3",
|
||||
checkdigit: "3",
|
||||
}, {
|
||||
radix: 8,
|
||||
input: "026742114675",
|
||||
checksum: "7",
|
||||
checkdigit: "1",
|
||||
}, {
|
||||
radix: 10,
|
||||
input: "0123456789",
|
||||
checksum: "7",
|
||||
checkdigit: "7",
|
||||
}, {
|
||||
radix: 10,
|
||||
input: "468543",
|
||||
checksum: "7",
|
||||
checkdigit: "4",
|
||||
}, {
|
||||
radix: 10,
|
||||
input: "59377601",
|
||||
checksum: "5",
|
||||
checkdigit: "6",
|
||||
}, {
|
||||
radix: 10,
|
||||
input: "013909981254",
|
||||
checksum: "1",
|
||||
checkdigit: "3",
|
||||
}, {
|
||||
radix: 12,
|
||||
input: "0123456789ab",
|
||||
checksum: "3",
|
||||
checkdigit: "3",
|
||||
}, {
|
||||
radix: 12,
|
||||
input: "284685",
|
||||
checksum: "0",
|
||||
checkdigit: "6",
|
||||
}, {
|
||||
radix: 12,
|
||||
input: "951a2661",
|
||||
checksum: "0",
|
||||
checkdigit: "8",
|
||||
}, {
|
||||
radix: 12,
|
||||
input: "898202676387",
|
||||
checksum: "b",
|
||||
checkdigit: "9",
|
||||
}, {
|
||||
radix: 14,
|
||||
input: "0123456789abcd",
|
||||
checksum: "a",
|
||||
checkdigit: "a",
|
||||
}, {
|
||||
radix: 14,
|
||||
input: "33db25",
|
||||
checksum: "0",
|
||||
checkdigit: "d",
|
||||
}, {
|
||||
radix: 14,
|
||||
input: "0b4ac128",
|
||||
checksum: "b",
|
||||
checkdigit: "3",
|
||||
}, {
|
||||
radix: 14,
|
||||
input: "3d1c6d16160d",
|
||||
checksum: "3",
|
||||
checkdigit: "c",
|
||||
}, {
|
||||
radix: 16,
|
||||
input: "0123456789abcdef",
|
||||
checksum: "4",
|
||||
checkdigit: "4",
|
||||
}, {
|
||||
radix: 16,
|
||||
input: "e1fe64",
|
||||
checksum: "b",
|
||||
checkdigit: "6",
|
||||
}, {
|
||||
radix: 16,
|
||||
input: "241a5dcd",
|
||||
checksum: "1",
|
||||
checkdigit: "9",
|
||||
}, {
|
||||
radix: 16,
|
||||
input: "1fea740e0e1f",
|
||||
checksum: "7",
|
||||
checkdigit: "4",
|
||||
}, {
|
||||
radix: 18,
|
||||
input: "0123456789abcdefgh",
|
||||
checksum: "d",
|
||||
checkdigit: "d",
|
||||
}, {
|
||||
radix: 18,
|
||||
input: "995dgf",
|
||||
checksum: "9",
|
||||
checkdigit: "1",
|
||||
}, {
|
||||
radix: 18,
|
||||
input: "9f80h32h",
|
||||
checksum: "1",
|
||||
checkdigit: "0",
|
||||
}, {
|
||||
radix: 18,
|
||||
input: "5f9428e493g4",
|
||||
checksum: "8",
|
||||
checkdigit: "c",
|
||||
}, {
|
||||
radix: 20,
|
||||
input: "0123456789abcdefghij",
|
||||
checksum: "5",
|
||||
checkdigit: "5",
|
||||
}, {
|
||||
radix: 20,
|
||||
input: "918jci",
|
||||
checksum: "h",
|
||||
checkdigit: "d",
|
||||
}, {
|
||||
radix: 20,
|
||||
input: "jab7j50d",
|
||||
checksum: "g",
|
||||
checkdigit: "j",
|
||||
}, {
|
||||
radix: 20,
|
||||
input: "c56fe85eb6gg",
|
||||
checksum: "g",
|
||||
checkdigit: "5",
|
||||
}, {
|
||||
radix: 22,
|
||||
input: "0123456789abcdefghijkl",
|
||||
checksum: "g",
|
||||
checkdigit: "g",
|
||||
}, {
|
||||
radix: 22,
|
||||
input: "de57le",
|
||||
checksum: "5",
|
||||
checkdigit: "l",
|
||||
}, {
|
||||
radix: 22,
|
||||
input: "e3fg6dfc",
|
||||
checksum: "f",
|
||||
checkdigit: "d",
|
||||
}, {
|
||||
radix: 22,
|
||||
input: "1f8l80ai4kbg",
|
||||
checksum: "l",
|
||||
checkdigit: "f",
|
||||
}, {
|
||||
radix: 24,
|
||||
input: "0123456789abcdefghijklmn",
|
||||
checksum: "6",
|
||||
checkdigit: "6",
|
||||
}, {
|
||||
radix: 24,
|
||||
input: "agne7d",
|
||||
checksum: "4",
|
||||
checkdigit: "f",
|
||||
}, {
|
||||
radix: 24,
|
||||
input: "1l4d9cf4",
|
||||
checksum: "d",
|
||||
checkdigit: "c",
|
||||
}, {
|
||||
radix: 24,
|
||||
input: "blc1j09i3296",
|
||||
checksum: "8",
|
||||
checkdigit: "7",
|
||||
}, {
|
||||
radix: 26,
|
||||
input: "0123456789abcdefghijklmnop",
|
||||
checksum: "j",
|
||||
checkdigit: "j",
|
||||
}, {
|
||||
radix: 26,
|
||||
input: "82n9op",
|
||||
checksum: "i",
|
||||
checkdigit: "2",
|
||||
}, {
|
||||
radix: 26,
|
||||
input: "e9cddn70",
|
||||
checksum: "9",
|
||||
checkdigit: "i",
|
||||
}, {
|
||||
radix: 26,
|
||||
input: "ck0ep419knom",
|
||||
checksum: "p",
|
||||
checkdigit: "g",
|
||||
}, {
|
||||
radix: 28,
|
||||
input: "0123456789abcdefghijklmnopqr",
|
||||
checksum: "7",
|
||||
checkdigit: "7",
|
||||
}, {
|
||||
radix: 28,
|
||||
input: "a6hnoo",
|
||||
checksum: "h",
|
||||
checkdigit: "9",
|
||||
}, {
|
||||
radix: 28,
|
||||
input: "lblc7kh0",
|
||||
checksum: "a",
|
||||
checkdigit: "f",
|
||||
}, {
|
||||
radix: 28,
|
||||
input: "64k5piod3lmf",
|
||||
checksum: "0",
|
||||
checkdigit: "p",
|
||||
}, {
|
||||
radix: 30,
|
||||
input: "0123456789abcdefghijklmnopqrst",
|
||||
checksum: "m",
|
||||
checkdigit: "m",
|
||||
}, {
|
||||
radix: 30,
|
||||
input: "t69j7d",
|
||||
checksum: "9",
|
||||
checkdigit: "s",
|
||||
}, {
|
||||
radix: 30,
|
||||
input: "p54o9ig3",
|
||||
checksum: "a",
|
||||
checkdigit: "o",
|
||||
}, {
|
||||
radix: 30,
|
||||
input: "gc1njrt55030",
|
||||
checksum: "6",
|
||||
checkdigit: "1",
|
||||
}, {
|
||||
radix: 32,
|
||||
input: "0123456789abcdefghijklmnopqrstuv",
|
||||
checksum: "8",
|
||||
checkdigit: "8",
|
||||
}, {
|
||||
radix: 32,
|
||||
input: "rdou19",
|
||||
checksum: "u",
|
||||
checkdigit: "3",
|
||||
}, {
|
||||
radix: 32,
|
||||
input: "ighj0pc7",
|
||||
checksum: "3",
|
||||
checkdigit: "8",
|
||||
}, {
|
||||
radix: 32,
|
||||
input: "op4nn5fvjsrs",
|
||||
checksum: "g",
|
||||
checkdigit: "j",
|
||||
}, {
|
||||
radix: 34,
|
||||
input: "0123456789abcdefghijklmnopqrstuvwx",
|
||||
checksum: "p",
|
||||
checkdigit: "p",
|
||||
}, {
|
||||
radix: 34,
|
||||
input: "nvftj5",
|
||||
checksum: "b",
|
||||
checkdigit: "f",
|
||||
}, {
|
||||
radix: 34,
|
||||
input: "u9v9g162",
|
||||
checksum: "j",
|
||||
checkdigit: "b",
|
||||
}, {
|
||||
radix: 34,
|
||||
input: "o5gqg5d7gjh9",
|
||||
checksum: "5",
|
||||
checkdigit: "q",
|
||||
}, {
|
||||
radix: 36,
|
||||
input: "0123456789abcdefghijklmnopqrstuvwxyz",
|
||||
checksum: "9",
|
||||
checkdigit: "9",
|
||||
}, {
|
||||
radix: 36,
|
||||
input: "29zehu",
|
||||
checksum: "i",
|
||||
checkdigit: "j",
|
||||
}, {
|
||||
radix: 36,
|
||||
input: "1snmikbu",
|
||||
checksum: "s",
|
||||
checkdigit: "v",
|
||||
}, {
|
||||
radix: 36,
|
||||
input: "jpkar545q7gb",
|
||||
checksum: "3",
|
||||
checkdigit: "d",
|
||||
},
|
||||
];
|
||||
|
||||
testCases.forEach(element => {
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Luhn Checksum Mod " + element.radix + " on " + element.input,
|
||||
input: element.input,
|
||||
expectedOutput: "Checksum: " + element.checksum + "\nCheckdigit: " + element.checkdigit + "\nLuhn Validated String: " + element.input + element.checkdigit,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Luhn Checksum",
|
||||
args: [element.radix]
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Luhn Checksum on standard data",
|
||||
@@ -15,7 +396,7 @@ TestRegister.addTests([
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Luhn Checksum",
|
||||
args: []
|
||||
args: [10]
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -26,7 +407,7 @@ TestRegister.addTests([
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Luhn Checksum",
|
||||
args: []
|
||||
args: [10]
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -37,18 +418,7 @@ TestRegister.addTests([
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Luhn Checksum",
|
||||
args: []
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Luhn Checksum on invalid data",
|
||||
input: "35641709b012469",
|
||||
expectedOutput: "Character: b is not a digit.",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Luhn Checksum",
|
||||
args: []
|
||||
args: [10]
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -59,8 +429,8 @@ TestRegister.addTests([
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Luhn Checksum",
|
||||
args: []
|
||||
args: [10]
|
||||
},
|
||||
],
|
||||
}
|
||||
},
|
||||
]);
|
||||
|
||||
89
tests/operations/tests/MIMEDecoding.mjs
Normal file
89
tests/operations/tests/MIMEDecoding.mjs
Normal file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* MIME Header Decoding tests
|
||||
*
|
||||
* @author mshwed [m@ttshwed.com]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Encoded comments",
|
||||
input: "(=?ISO-8859-1?Q?a?=)",
|
||||
expectedOutput: "(a)",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "MIME Decoding",
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Encoded adjacent comments whitespace",
|
||||
input: "(=?ISO-8859-1?Q?a?= b)",
|
||||
expectedOutput: "(a b)",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "MIME Decoding",
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Encoded adjacent single whitespace ignored",
|
||||
input: "(=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=)",
|
||||
expectedOutput: "(ab)",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "MIME Decoding",
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Encoded adjacent double whitespace ignored",
|
||||
input: "(=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=)",
|
||||
expectedOutput: "(ab)",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "MIME Decoding",
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Encoded adjacent CRLF whitespace ignored",
|
||||
input: "(=?ISO-8859-1?Q?a?=\r\n =?ISO-8859-1?Q?b?=)",
|
||||
expectedOutput: "(ab)",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "MIME Decoding",
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "UTF-8 Encodings Multiple Headers",
|
||||
input: "=?utf-8?q?=C3=89ric?= <eric@example.org>, =?utf-8?q?Ana=C3=AFs?= <anais@example.org>",
|
||||
expectedOutput: "Éric <eric@example.org>, Anaïs <anais@example.org>",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "MIME Decoding",
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "ISO Decoding",
|
||||
input: "From: =?US-ASCII?Q?Keith_Moore?= <moore@cs.utk.edu>\nTo: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <keld@dkuug.dk>\nCC: =?ISO-8859-1?Q?Andr=E9?= Pirard <PIRARD@vm1.ulg.ac.be>\nSubject: =?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=\n=?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=",
|
||||
expectedOutput: "From: Keith Moore <moore@cs.utk.edu>\nTo: Keld Jørn Simonsen <keld@dkuug.dk>\nCC: André Pirard <PIRARD@vm1.ulg.ac.be>\nSubject: If you can read this you understand the example.",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "MIME Decoding",
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
||||
150
tests/operations/tests/Modhex.mjs
Normal file
150
tests/operations/tests/Modhex.mjs
Normal file
@@ -0,0 +1,150 @@
|
||||
/**
|
||||
* Modhex operation tests.
|
||||
* @author linuxgemini [ilteris@asenkron.com.tr]
|
||||
* @copyright Crown Copyright 2024
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "ASCII to Modhex stream",
|
||||
input: "aberystwyth",
|
||||
expectedOutput: "hbhdhgidikieifiiikifhj",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "To Modhex",
|
||||
"args": [
|
||||
"None",
|
||||
0
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "ASCII to Modhex with colon deliminator",
|
||||
input: "aberystwyth",
|
||||
expectedOutput: "hb:hd:hg:id:ik:ie:if:ii:ik:if:hj",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "To Modhex",
|
||||
"args": [
|
||||
"Colon",
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Modhex stream to UTF-8",
|
||||
input: "uhkgkbuhkgkbugltlkugltkc",
|
||||
expectedOutput: "救救孩子",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "From Modhex",
|
||||
"args": [
|
||||
"Auto"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
},
|
||||
{
|
||||
name: "Mixed case Modhex stream to UTF-8",
|
||||
input: "uhKGkbUHkgkBUGltlkugltkc",
|
||||
expectedOutput: "救救孩子",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "From Modhex",
|
||||
"args": [
|
||||
"Auto"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
},
|
||||
{
|
||||
name: "Mutiline Modhex with comma to ASCII (Auto Mode)",
|
||||
input: "fk,dc,ie,hb,ii,dc,ht,ik,ie,hg,hr,hh,dc,ie,hk,\n\
|
||||
if,if,hk,hu,hi,dc,hk,hu,dc,if,hj,hg,dc,he,id,\n\
|
||||
hv,if,he,hj,dc,hv,hh,dc,if,hj,hg,dc,if,hj,hk,\n\
|
||||
ie,dc,hh,hk,hi,dc,if,id,hg,hg,dr,dc,ie,if,hb,\n\
|
||||
id,ih,hk,hu,hi,dc,if,hv,dc,hf,hg,hb,if,hj,dr,\n\
|
||||
dc,hl,ig,ie,if,dc,hd,hg,he,hb,ig,ie,hg,dc,fk,\n\
|
||||
dc,he,hv,ig,hr,hf,hu,di,if,dc,ht,hb,hn,hg,dc,\n\
|
||||
ig,ic,dc,ht,ik,dc,ht,hk,hu,hf,dc,ii,hj,hk,he,\n\
|
||||
hj,dc,hv,hh,dc,if,hj,hg,dc,hh,hk,hi,ie,dc,fk,\n\
|
||||
dc,ii,hv,ig,hr,hf,dc,he,hj,hv,hv,ie,hg,du",
|
||||
expectedOutput: "I saw myself sitting in the crotch of the this fig tree, starving to death, just because I couldn't make up my mind which of the figs I would choose.",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "From Modhex",
|
||||
"args": [
|
||||
"Auto"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
},
|
||||
{
|
||||
name: "Mutiline Modhex with percent to ASCII (Percent Mode)",
|
||||
input: "fk%dc%ie%hb%ii%dc%ht%ik%ie%hg%hr%hh%dc%ie%hk%\n\
|
||||
if%if%hk%hu%hi%dc%hk%hu%dc%if%hj%hg%dc%he%id%\n\
|
||||
hv%if%he%hj%dc%hv%hh%dc%if%hj%hg%dc%if%hj%hk%\n\
|
||||
ie%dc%hh%hk%hi%dc%if%id%hg%hg%dr%dc%ie%if%hb%\n\
|
||||
id%ih%hk%hu%hi%dc%if%hv%dc%hf%hg%hb%if%hj%dr%\n\
|
||||
dc%hl%ig%ie%if%dc%hd%hg%he%hb%ig%ie%hg%dc%fk%\n\
|
||||
dc%he%hv%ig%hr%hf%hu%di%if%dc%ht%hb%hn%hg%dc%\n\
|
||||
ig%ic%dc%ht%ik%dc%ht%hk%hu%hf%dc%ii%hj%hk%he%\n\
|
||||
hj%dc%hv%hh%dc%if%hj%hg%dc%hh%hk%hi%ie%dc%fk%\n\
|
||||
dc%ii%hv%ig%hr%hf%dc%he%hj%hv%hv%ie%hg%du",
|
||||
expectedOutput: "I saw myself sitting in the crotch of the this fig tree, starving to death, just because I couldn't make up my mind which of the figs I would choose.",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "From Modhex",
|
||||
"args": [
|
||||
"Percent"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
},
|
||||
{
|
||||
name: "Mutiline Modhex with semicolon to ASCII (Semi-colon Mode)",
|
||||
input: "fk;dc;ie;hb;ii;dc;ht;ik;ie;hg;hr;hh;dc;ie;hk;\n\
|
||||
if;if;hk;hu;hi;dc;hk;hu;dc;if;hj;hg;dc;he;id;\n\
|
||||
hv;if;he;hj;dc;hv;hh;dc;if;hj;hg;dc;if;hj;hk;\n\
|
||||
ie;dc;hh;hk;hi;dc;if;id;hg;hg;dr;dc;ie;if;hb;\n\
|
||||
id;ih;hk;hu;hi;dc;if;hv;dc;hf;hg;hb;if;hj;dr;\n\
|
||||
dc;hl;ig;ie;if;dc;hd;hg;he;hb;ig;ie;hg;dc;fk;\n\
|
||||
dc;he;hv;ig;hr;hf;hu;di;if;dc;ht;hb;hn;hg;dc;\n\
|
||||
ig;ic;dc;ht;ik;dc;ht;hk;hu;hf;dc;ii;hj;hk;he;\n\
|
||||
hj;dc;hv;hh;dc;if;hj;hg;dc;hh;hk;hi;ie;dc;fk;\n\
|
||||
dc;ii;hv;ig;hr;hf;dc;he;hj;hv;hv;ie;hg;du",
|
||||
expectedOutput: "I saw myself sitting in the crotch of the this fig tree, starving to death, just because I couldn't make up my mind which of the figs I would choose.",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "From Modhex",
|
||||
"args": [
|
||||
"Semi-colon"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
},
|
||||
{
|
||||
name: "ASCII to Modhex with comma and line breaks",
|
||||
input: "aberystwyth",
|
||||
expectedOutput: "hb,hd,hg,id,\nik,ie,if,ii,\nik,if,hj",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "To Modhex",
|
||||
"args": [
|
||||
"Comma",
|
||||
4
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
]);
|
||||
@@ -11,12 +11,12 @@ import TestRegister from "../../lib/TestRegister.mjs";
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Generate HOTP",
|
||||
input: "12345678901234567890",
|
||||
expectedOutput: "URI: otpauth://hotp/OTPAuthentication?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ\n\nPassword: 755224",
|
||||
input: "JBSWY3DPEHPK3PXP",
|
||||
expectedOutput: `URI: otpauth://hotp/?secret=JBSWY3DPEHPK3PXP&algorithm=SHA1&digits=6&counter=0\n\nPassword: 282760`,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Generate HOTP",
|
||||
args: ["", 32, 6, 0],
|
||||
args: ["", 6, 0], // [Name, Code length, Counter]
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
112
tests/operations/tests/PHPSerialize.mjs
Normal file
112
tests/operations/tests/PHPSerialize.mjs
Normal file
@@ -0,0 +1,112 @@
|
||||
/**
|
||||
* PHP Serialization tests.
|
||||
*
|
||||
* @author brun0ne [brunonblok@gmail.com]
|
||||
*
|
||||
* @copyright Crown Copyright 2023
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "PHP Serialize empty array",
|
||||
input: "[]",
|
||||
expectedOutput: "a:0:{}",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "PHP Serialize",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "PHP Serialize empty object",
|
||||
input: "{}",
|
||||
expectedOutput: "a:0:{}",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "PHP Serialize",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "PHP Serialize null",
|
||||
input: "null",
|
||||
expectedOutput: "N;",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "PHP Serialize",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "PHP Serialize integer",
|
||||
input: "10",
|
||||
expectedOutput: "i:10;",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "PHP Serialize",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "PHP Serialize float",
|
||||
input: "14.523",
|
||||
expectedOutput: "d:14.523;",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "PHP Serialize",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "PHP Serialize boolean",
|
||||
input: "[true, false]",
|
||||
expectedOutput: "a:2:{i:0;b:1;i:1;b:0;}",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "PHP Serialize",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "PHP Serialize string",
|
||||
input: "\"Test string to serialize\"",
|
||||
expectedOutput: "s:24:\"Test string to serialize\";",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "PHP Serialize",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "PHP Serialize object",
|
||||
input: "{\"a\": 10,\"0\": {\"ab\": true}}",
|
||||
expectedOutput: "a:2:{s:1:\"0\";a:1:{s:2:\"ab\";b:1;}s:1:\"a\";i:10;}",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "PHP Serialize",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "PHP Serialize array",
|
||||
input: "[1,\"abc\",true,{\"x\":1,\"y\":2}]",
|
||||
expectedOutput: "a:4:{i:0;i:1;i:1;s:3:\"abc\";i:2;b:1;i:3;a:2:{s:1:\"x\";i:1;s:1:\"y\";i:2;}}",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "PHP Serialize",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
||||
@@ -135,10 +135,21 @@ TestRegister.addTests([
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ROT13: no shift amount",
|
||||
input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
|
||||
expectedOutput: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "ROT13",
|
||||
args: [true, true, true, 0]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ROT13: normal",
|
||||
input: "The Quick Brown Fox Jumped Over The Lazy Dog.",
|
||||
expectedOutput: "Gur Dhvpx Oebja Sbk Whzcrq Bire Gur Ynml Qbt.",
|
||||
input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
|
||||
expectedOutput: "Gur Dhvpx Oebja Sbk Whzcrq Bire Gur Ynml Qbt. 3456789012",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "ROT13",
|
||||
@@ -146,10 +157,21 @@ TestRegister.addTests([
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ROT13: negative shift amount",
|
||||
input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
|
||||
expectedOutput: "Gur Dhvpx Oebja Sbk Whzcrq Bire Gur Ynml Qbt. 7890123456",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "ROT13",
|
||||
args: [true, true, true, -13]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ROT13: full loop",
|
||||
input: "The Quick Brown Fox Jumped Over The Lazy Dog.",
|
||||
expectedOutput: "The Quick Brown Fox Jumped Over The Lazy Dog.",
|
||||
input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
|
||||
expectedOutput: "The Quick Brown Fox Jumped Over The Lazy Dog. 6789012345",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "ROT13",
|
||||
@@ -157,10 +179,21 @@ TestRegister.addTests([
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ROT13: full loop (negative shift amount)",
|
||||
input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
|
||||
expectedOutput: "The Quick Brown Fox Jumped Over The Lazy Dog. 4567890123",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "ROT13",
|
||||
args: [true, true, true, -26]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ROT13: lowercase only",
|
||||
input: "The Quick Brown Fox Jumped Over The Lazy Dog.",
|
||||
expectedOutput: "Tur Qhvpx Bebja Fbk Jhzcrq Oire Tur Lnml Dbt.",
|
||||
input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
|
||||
expectedOutput: "Tur Qhvpx Bebja Fbk Jhzcrq Oire Tur Lnml Dbt. 0123456789",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "ROT13",
|
||||
@@ -170,8 +203,8 @@ TestRegister.addTests([
|
||||
},
|
||||
{
|
||||
name: "ROT13: uppercase only",
|
||||
input: "The Quick Brown Fox Jumped Over The Lazy Dog.",
|
||||
expectedOutput: "Ghe Duick Orown Sox Wumped Bver Ghe Yazy Qog.",
|
||||
input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
|
||||
expectedOutput: "Ghe Duick Orown Sox Wumped Bver Ghe Yazy Qog. 0123456789",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "ROT13",
|
||||
@@ -179,6 +212,50 @@ TestRegister.addTests([
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ROT13: numbers only",
|
||||
input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
|
||||
expectedOutput: "The Quick Brown Fox Jumped Over The Lazy Dog. 5678901234",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "ROT13",
|
||||
args: [false, false, true, 5]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ROT13: numbers only (negative shift amount)",
|
||||
input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
|
||||
expectedOutput: "The Quick Brown Fox Jumped Over The Lazy Dog. 5678901234",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "ROT13",
|
||||
args: [false, false, true, 5]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ROT13: numbers only loop",
|
||||
input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
|
||||
expectedOutput: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "ROT13",
|
||||
args: [false, false, true, 10]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ROT13: numbers only loop (negative shift amount)",
|
||||
input: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
|
||||
expectedOutput: "The Quick Brown Fox Jumped Over The Lazy Dog. 0123456789",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "ROT13",
|
||||
args: [false, false, true, -10]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ROT47: nothing",
|
||||
input: "",
|
||||
|
||||
135
tests/operations/tests/SM2.mjs
Normal file
135
tests/operations/tests/SM2.mjs
Normal file
@@ -0,0 +1,135 @@
|
||||
/**
|
||||
* SM2 Tests
|
||||
*
|
||||
* @author flakjacket95 [dflack95@gmail.com]
|
||||
* @copyright Crown Copyright 2024
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
/* Plaintexts */
|
||||
|
||||
const SMALL_PLAIN = "I am a small plaintext";
|
||||
const LARGE_PLAIN = "I am a larger plaintext, that will require the encryption KDF to generate a much larger key to properly encrypt me";
|
||||
|
||||
/* Test Key Parameters */
|
||||
const PUBLIC_X = "f7d903cab7925066c31150a92b31e548e63f954f92d01eaa0271fb2a336baef8";
|
||||
const PUBLIC_Y = "fb0c45e410ef7a6cdae724e6a78dbff52562e97ede009e762b667d9b14adea6c";
|
||||
const PRIVATE_K = "e74a72505084c3269aa9b696d603e3e08c74c6740212c11a31e26cdfe08bdf6a";
|
||||
|
||||
const CURVE = "sm2p256v1";
|
||||
|
||||
/* Decryption Test Ciphertext*/
|
||||
|
||||
const CIPHERTEXT_1 = "9a31bc0adb4677cdc4141479e3949572a55c3e6fb52094721f741c2bd2e179aaa87be6263bc1be602e473be3d5de5dce97f8248948b3a7e15f9f67f64aef21575e0c05e6171870a10ff9ab778dbef24267ad90e1a9d47d68f757d57c4816612e9829f804025dea05a511cda39371c22a2828f976f72e";
|
||||
const CIPHERTEXT_2 = "d3647d68568a2e7a4f8e843286be7bf2b4d80256697d19a73df306ae1a7e6d0364d942e23d2340606e7a2502a838b132f9242587b2ea7e4c207e87242eea8cae68f5ff4da2a95a7f6d350608ae5b6777e1d925bf9c560087af84aba7befba713130106ddb4082d803811bca3864594722f3198d58257fe4ba37f4aa540adf4cb0568bddd2d8140ad3030deea0a87e3198655cc4d22bfc3d73b1c4afec2ff15d68c8d1298d97132cace922ee8a4e41ca288a7e748b77ca94aa81dc283439923ae7939e00898e16fe5111fbe1d928d152b216a";
|
||||
const CIPHERTEXT_3 = "5f340eeb4398fa8950ee3408d0e3fe34bf7728c9fdb060c94b916891b5c693610274160b52a7132a2bf16ad5cdb57d1e00da2f3ddbd55350729aa9c268b53e40c05ccce9912daa14406e8c132e389484e69757350be25351755dcc6c25c94b3c1a448b2cf8c2017582125eb6cf782055b199a875e966";
|
||||
const CIPHERTEXT_4 = "0649bac46c3f9fd7fb3b2be4bff27414d634651efd02ca67d8c802bbc5468e77d035c39b581d6b56227f5d87c0b4efbea5032c0761139295ae194b9f1fce698f2f4b51d89fa5554171a1aad2e61fe9de89831aec472ecc5ab178ebf4d2230c1fb94fca03e536b87b9eba6db71ba9939260a08ffd230ca86cb45cf754854222364231bdb8b873791d63ad57a4b3fa5b6375388dc879373f5f1be9051bc5072a8afbec5b7b034e4907aa5bb4b6b1f50e725d09cb6a02e07ce20263005f6c9157ce05d3ea739d231d4f09396fb72aa680884d78";
|
||||
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "SM2 Decrypt: Small Input; Format One",
|
||||
input: CIPHERTEXT_1,
|
||||
expectedOutput: SMALL_PLAIN,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "SM2 Decrypt",
|
||||
"args": [PRIVATE_K, "C1C3C2", CURVE]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "SM2 Decrypt: Large Input; Format One",
|
||||
input: CIPHERTEXT_2,
|
||||
expectedOutput: LARGE_PLAIN,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "SM2 Decrypt",
|
||||
"args": [PRIVATE_K, "C1C3C2", CURVE]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "SM2 Decrypt: Small Input; Format Two",
|
||||
input: CIPHERTEXT_3,
|
||||
expectedOutput: SMALL_PLAIN,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "SM2 Decrypt",
|
||||
"args": [PRIVATE_K, "C1C2C3", CURVE]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "SM2 Decrypt: Large Input; Format Two",
|
||||
input: CIPHERTEXT_4,
|
||||
expectedOutput: LARGE_PLAIN,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "SM2 Decrypt",
|
||||
"args": [PRIVATE_K, "C1C2C3", CURVE]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "SM2 Encrypt And Decrypt: Small Input; Format One",
|
||||
input: SMALL_PLAIN,
|
||||
expectedOutput: SMALL_PLAIN,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "SM2 Encrypt",
|
||||
"args": [PUBLIC_X, PUBLIC_Y, "C1C3C2", CURVE],
|
||||
},
|
||||
{
|
||||
"op": "SM2 Decrypt",
|
||||
"args": [PRIVATE_K, "C1C3C2", CURVE]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "SM2 Encrypt And Decrypt: Large Input; Format One",
|
||||
input: LARGE_PLAIN,
|
||||
expectedOutput: LARGE_PLAIN,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "SM2 Encrypt",
|
||||
"args": [PUBLIC_X, PUBLIC_Y, "C1C3C2", CURVE],
|
||||
},
|
||||
{
|
||||
"op": "SM2 Decrypt",
|
||||
"args": [PRIVATE_K, "C1C3C2", CURVE]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "SM2 Encrypt And Decrypt: Small Input; Format Two",
|
||||
input: SMALL_PLAIN,
|
||||
expectedOutput: SMALL_PLAIN,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "SM2 Encrypt",
|
||||
"args": [PUBLIC_X, PUBLIC_Y, "C1C2C3", CURVE],
|
||||
},
|
||||
{
|
||||
"op": "SM2 Decrypt",
|
||||
"args": [PRIVATE_K, "C1C2C2", CURVE]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "SM2 Encrypt And Decrypt: Large Input; Format Two",
|
||||
input: LARGE_PLAIN,
|
||||
expectedOutput: LARGE_PLAIN,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "SM2 Encrypt",
|
||||
"args": [PUBLIC_X, PUBLIC_Y, "C1C2C3", CURVE],
|
||||
},
|
||||
{
|
||||
"op": "SM2 Decrypt",
|
||||
"args": [PRIVATE_K, "C1C2C3", CURVE]
|
||||
}
|
||||
]
|
||||
},
|
||||
]);
|
||||
126
tests/operations/tests/StripIPv4Header.mjs
Normal file
126
tests/operations/tests/StripIPv4Header.mjs
Normal file
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* Strip IPv4 header tests.
|
||||
*
|
||||
* @author c65722 []
|
||||
* @copyright Crown Copyright 2024
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Strip IPv4 header: No options, No payload",
|
||||
input: "450000140005400080060000c0a80001c0a80002",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Hex",
|
||||
args: ["None"]
|
||||
},
|
||||
{
|
||||
op: "Strip IPv4 header",
|
||||
args: [],
|
||||
},
|
||||
{
|
||||
op: "To Hex",
|
||||
args: ["None", 0]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Strip IPv4 header: No options, Payload",
|
||||
input: "450000140005400080060000c0a80001c0a80002ffffffffffffffff",
|
||||
expectedOutput: "ffffffffffffffff",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Hex",
|
||||
args: ["None"]
|
||||
},
|
||||
{
|
||||
op: "Strip IPv4 header",
|
||||
args: [],
|
||||
},
|
||||
{
|
||||
op: "To Hex",
|
||||
args: ["None", 0]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Strip IPv4 header: Options, No payload",
|
||||
input: "460000140005400080060000c0a80001c0a8000207000000",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Hex",
|
||||
args: ["None"]
|
||||
},
|
||||
{
|
||||
op: "Strip IPv4 header",
|
||||
args: [],
|
||||
},
|
||||
{
|
||||
op: "To Hex",
|
||||
args: ["None", 0]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Strip IPv4 header: Options, Payload",
|
||||
input: "460000140005400080060000c0a80001c0a8000207000000ffffffffffffffff",
|
||||
expectedOutput: "ffffffffffffffff",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Hex",
|
||||
args: ["None"]
|
||||
},
|
||||
{
|
||||
op: "Strip IPv4 header",
|
||||
args: [],
|
||||
},
|
||||
{
|
||||
op: "To Hex",
|
||||
args: ["None", 0]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Strip IPv4 header: Input length lesss than minimum header length",
|
||||
input: "450000140005400080060000c0a80001c0a800",
|
||||
expectedOutput: "Input length is less than minimum IPv4 header length",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Hex",
|
||||
args: ["None"]
|
||||
},
|
||||
{
|
||||
op: "Strip IPv4 header",
|
||||
args: [],
|
||||
},
|
||||
{
|
||||
op: "To Hex",
|
||||
args: ["None", 0]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Strip IPv4 header: Input length less than IHL",
|
||||
input: "460000140005400080060000c0a80001c0a80000",
|
||||
expectedOutput: "Input length is less than IHL",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Hex",
|
||||
args: ["None"]
|
||||
},
|
||||
{
|
||||
op: "Strip IPv4 header",
|
||||
args: [],
|
||||
},
|
||||
{
|
||||
op: "To Hex",
|
||||
args: ["None", 0]
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
||||
123
tests/operations/tests/TakeNthBytes.mjs
Normal file
123
tests/operations/tests/TakeNthBytes.mjs
Normal file
@@ -0,0 +1,123 @@
|
||||
/**
|
||||
* @author Oshawk [oshawk@protonmail.com]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
/**
|
||||
* Take nth bytes tests
|
||||
*/
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Take nth bytes: Nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Take nth bytes",
|
||||
args: [4, 0, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Take nth bytes: Nothing (apply to each line)",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Take nth bytes",
|
||||
args: [4, 0, true],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Take nth bytes: Basic single line",
|
||||
input: "0123456789",
|
||||
expectedOutput: "048",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Take nth bytes",
|
||||
args: [4, 0, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Take nth bytes: Basic single line (apply to each line)",
|
||||
input: "0123456789",
|
||||
expectedOutput: "048",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Take nth bytes",
|
||||
args: [4, 0, true],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Take nth bytes: Complex single line",
|
||||
input: "0123456789",
|
||||
expectedOutput: "59",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Take nth bytes",
|
||||
args: [4, 5, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Take nth bytes: Complex single line (apply to each line)",
|
||||
input: "0123456789",
|
||||
expectedOutput: "59",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Take nth bytes",
|
||||
args: [4, 5, true],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Take nth bytes: Basic multi line",
|
||||
input: "01234\n56789",
|
||||
expectedOutput: "047",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Take nth bytes",
|
||||
args: [4, 0, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Take nth bytes: Basic multi line (apply to each line)",
|
||||
input: "01234\n56789",
|
||||
expectedOutput: "04\n59",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Take nth bytes",
|
||||
args: [4, 0, true],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Take nth bytes: Complex multi line",
|
||||
input: "01234\n56789",
|
||||
expectedOutput: "\n8",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Take nth bytes",
|
||||
args: [4, 5, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Take nth bytes: Complex multi line (apply to each line)",
|
||||
input: "012345\n6789ab",
|
||||
expectedOutput: "5\nb",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Take nth bytes",
|
||||
args: [4, 5, true],
|
||||
},
|
||||
],
|
||||
}
|
||||
]);
|
||||
92
tests/operations/tests/URLEncodeDecode.mjs
Normal file
92
tests/operations/tests/URLEncodeDecode.mjs
Normal file
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* URLEncode and URLDecode tests.
|
||||
*
|
||||
* @author es45411 [135977478+es45411@users.noreply.github.com]
|
||||
*
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
// URL Decode
|
||||
{
|
||||
name: "URLDecode: nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "URL Decode",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "URLDecode: spaces without special chars",
|
||||
input: "Hello%20world%21",
|
||||
expectedOutput: "Hello world!",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "URL Decode",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "URLDecode: spaces with special chars",
|
||||
input: "Hello%20world!",
|
||||
expectedOutput: "Hello world!",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "URL Decode",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "URLDecode: decode plus as space",
|
||||
input: "Hello%20world!",
|
||||
expectedOutput: "Hello world!",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "URL Decode",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
// URL Encode
|
||||
{
|
||||
name: "URLEncode: nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "URL Encode",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "URLEncode: spaces without special chars",
|
||||
input: "Hello world!",
|
||||
expectedOutput: "Hello%20world!",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "URL Encode",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "URLEncode: spaces with special chars",
|
||||
input: "Hello world!",
|
||||
expectedOutput: "Hello%20world%21",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "URL Encode",
|
||||
args: [true],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
120
tests/operations/tests/XORChecksum.mjs
Normal file
120
tests/operations/tests/XORChecksum.mjs
Normal file
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* Checksum tests.
|
||||
*
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
const BASIC_STRING = "The ships hung in the sky in much the same way that bricks don't.";
|
||||
const UTF8_STR = "ნუ პანიკას";
|
||||
const ALL_BYTES = [
|
||||
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
|
||||
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
|
||||
"\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f",
|
||||
"\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f",
|
||||
"\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f",
|
||||
"\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f",
|
||||
"\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f",
|
||||
"\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f",
|
||||
"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f",
|
||||
"\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f",
|
||||
"\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf",
|
||||
"\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf",
|
||||
"\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf",
|
||||
"\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf",
|
||||
"\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef",
|
||||
"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
|
||||
].join("");
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "XOR Checksum (1): nothing",
|
||||
input: "",
|
||||
expectedOutput: "00",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "XOR Checksum",
|
||||
"args": [1]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "XOR Checksum (1): basic string",
|
||||
input: BASIC_STRING,
|
||||
expectedOutput: "08",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "XOR Checksum",
|
||||
"args": [1]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "XOR Checksum (1): UTF-8",
|
||||
input: UTF8_STR,
|
||||
expectedOutput: "df",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "XOR Checksum",
|
||||
"args": [1]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "XOR Checksum (1): all bytes",
|
||||
input: ALL_BYTES,
|
||||
expectedOutput: "00",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "XOR Checksum",
|
||||
"args": [1]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "XOR Checksum (4): nothing",
|
||||
input: "",
|
||||
expectedOutput: "00000000",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "XOR Checksum",
|
||||
"args": [4]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "XOR Checksum (4): basic string",
|
||||
input: BASIC_STRING,
|
||||
expectedOutput: "4918421b",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "XOR Checksum",
|
||||
"args": [4]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "XOR Checksum (4): UTF-8",
|
||||
input: UTF8_STR,
|
||||
expectedOutput: "83a424dc",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "XOR Checksum",
|
||||
"args": [4]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "XOR Checksum (4): all bytes",
|
||||
input: ALL_BYTES,
|
||||
expectedOutput: "00000000",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "XOR Checksum",
|
||||
"args": [4]
|
||||
}
|
||||
]
|
||||
},
|
||||
]);
|
||||
Reference in New Issue
Block a user