Merge branch 'master' into 2209-bug-report-jq-operation-broken-in-latest-update
This commit is contained in:
commit
aa9befce15
@ -10,13 +10,7 @@ module.exports = function(api) {
|
|||||||
}]
|
}]
|
||||||
],
|
],
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"dynamic-import-node",
|
|
||||||
"@babel/plugin-syntax-import-assertions",
|
"@babel/plugin-syntax-import-assertions",
|
||||||
[
|
|
||||||
"babel-plugin-transform-builtin-extend", {
|
|
||||||
"globals": ["Error"]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
[
|
||||||
"@babel/plugin-transform-runtime", {
|
"@babel/plugin-transform-runtime", {
|
||||||
"regenerator": true
|
"regenerator": true
|
||||||
|
|||||||
951
package-lock.json
generated
951
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
31
package.json
31
package.json
@ -39,21 +39,18 @@
|
|||||||
"node >= 16"
|
"node >= 16"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.29.0",
|
|
||||||
"@babel/eslint-parser": "^7.28.6",
|
"@babel/eslint-parser": "^7.28.6",
|
||||||
"@babel/plugin-syntax-import-assertions": "^7.28.6",
|
"@babel/plugin-syntax-import-assertions": "^7.28.6",
|
||||||
"@babel/plugin-transform-runtime": "^7.29.0",
|
"@babel/plugin-transform-runtime": "^7.29.0",
|
||||||
"@babel/preset-env": "^7.29.0",
|
"@babel/preset-env": "^7.29.0",
|
||||||
"@babel/runtime": "^7.28.6",
|
"@babel/runtime": "^7.28.6",
|
||||||
"@codemirror/commands": "^6.10.2",
|
"@codemirror/commands": "^6.10.2",
|
||||||
"@codemirror/language": "^6.12.1",
|
"@codemirror/language": "^6.12.2",
|
||||||
"@codemirror/search": "^6.6.0",
|
"@codemirror/search": "^6.6.0",
|
||||||
"@codemirror/state": "^6.5.4",
|
"@codemirror/state": "^6.5.4",
|
||||||
"@codemirror/view": "^6.39.15",
|
"@codemirror/view": "^6.39.17",
|
||||||
"autoprefixer": "^10.4.24",
|
"autoprefixer": "^10.4.27",
|
||||||
"babel-loader": "^10.0.0",
|
"babel-loader": "^10.0.0",
|
||||||
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
||||||
"babel-plugin-transform-builtin-extend": "1.1.2",
|
|
||||||
"base64-loader": "^1.0.0",
|
"base64-loader": "^1.0.0",
|
||||||
"chromedriver": "^130.0.4",
|
"chromedriver": "^130.0.4",
|
||||||
"cli-progress": "^3.12.0",
|
"cli-progress": "^3.12.0",
|
||||||
@ -63,8 +60,8 @@
|
|||||||
"core-js": "^3.48.0",
|
"core-js": "^3.48.0",
|
||||||
"cspell": "^8.19.4",
|
"cspell": "^8.19.4",
|
||||||
"css-loader": "7.1.4",
|
"css-loader": "7.1.4",
|
||||||
"eslint": "^9.39.3",
|
"eslint": "^9.39.4",
|
||||||
"eslint-plugin-jsdoc": "^48.11.0",
|
"eslint-plugin-jsdoc": "^50.8.0",
|
||||||
"globals": "^15.15.0",
|
"globals": "^15.15.0",
|
||||||
"grunt": "^1.6.1",
|
"grunt": "^1.6.1",
|
||||||
"grunt-chmod": "~1.1.1",
|
"grunt-chmod": "~1.1.1",
|
||||||
@ -79,25 +76,25 @@
|
|||||||
"grunt-zip": "^1.0.0",
|
"grunt-zip": "^1.0.0",
|
||||||
"html-webpack-plugin": "^5.6.6",
|
"html-webpack-plugin": "^5.6.6",
|
||||||
"imports-loader": "^5.0.0",
|
"imports-loader": "^5.0.0",
|
||||||
"mini-css-extract-plugin": "2.10.0",
|
"mini-css-extract-plugin": "2.10.1",
|
||||||
"modify-source-webpack-plugin": "^4.1.0",
|
"modify-source-webpack-plugin": "^4.1.0",
|
||||||
"nightwatch": "^3.15.0",
|
"nightwatch": "^3.15.0",
|
||||||
"postcss": "^8.5.6",
|
"postcss": "^8.5.8",
|
||||||
"postcss-css-variables": "^0.19.0",
|
"postcss-css-variables": "^0.19.0",
|
||||||
"postcss-import": "^16.1.1",
|
"postcss-import": "^16.1.1",
|
||||||
"postcss-loader": "^8.2.1",
|
"postcss-loader": "^8.2.1",
|
||||||
"prompt": "^1.3.0",
|
"prompt": "^1.3.0",
|
||||||
"sitemap": "^8.0.2",
|
"sitemap": "^8.0.3",
|
||||||
"terser": "^5.46.0",
|
"terser": "^5.46.0",
|
||||||
"webpack": "^5.105.2",
|
"webpack": "^5.105.4",
|
||||||
"webpack-bundle-analyzer": "^4.10.2",
|
"webpack-bundle-analyzer": "^4.10.2",
|
||||||
"webpack-dev-server": "5.0.4",
|
"webpack-dev-server": "5.0.4",
|
||||||
"webpack-node-externals": "^3.0.0",
|
"webpack-node-externals": "^3.0.0",
|
||||||
"worker-loader": "^3.0.8"
|
"worker-loader": "^3.0.8"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@alexaltea/capstone-js": "^3.0.5",
|
||||||
"@astronautlabs/amf": "^0.0.6",
|
"@astronautlabs/amf": "^0.0.6",
|
||||||
"@babel/polyfill": "^7.12.1",
|
|
||||||
"@blu3r4y/lzma": "^2.3.3",
|
"@blu3r4y/lzma": "^2.3.3",
|
||||||
"@wavesenterprise/crypto-gost-js": "^2.1.0-RC1",
|
"@wavesenterprise/crypto-gost-js": "^2.1.0-RC1",
|
||||||
"@xmldom/xmldom": "^0.8.11",
|
"@xmldom/xmldom": "^0.8.11",
|
||||||
@ -124,7 +121,7 @@
|
|||||||
"d3": "7.9.0",
|
"d3": "7.9.0",
|
||||||
"d3-hexbin": "^0.2.2",
|
"d3-hexbin": "^0.2.2",
|
||||||
"diff": "^5.2.2",
|
"diff": "^5.2.2",
|
||||||
"dompurify": "^3.3.1",
|
"dompurify": "^3.3.3",
|
||||||
"es6-promisify": "^7.0.0",
|
"es6-promisify": "^7.0.0",
|
||||||
"escodegen": "^2.1.0",
|
"escodegen": "^2.1.0",
|
||||||
"esprima": "^4.0.1",
|
"esprima": "^4.0.1",
|
||||||
@ -140,13 +137,14 @@
|
|||||||
"ieee754": "^1.2.1",
|
"ieee754": "^1.2.1",
|
||||||
"jimp": "^1.6.0",
|
"jimp": "^1.6.0",
|
||||||
"jq-web": "^0.5.1",
|
"jq-web": "^0.5.1",
|
||||||
|
"jq-wasm": "^1.1.0-jq-1.8.1",
|
||||||
"jquery": "3.7.1",
|
"jquery": "3.7.1",
|
||||||
"js-sha3": "^0.9.3",
|
"js-sha3": "^0.9.3",
|
||||||
"jsesc": "^3.1.0",
|
"jsesc": "^3.1.0",
|
||||||
"json5": "^2.2.3",
|
"json5": "^2.2.3",
|
||||||
"jsonata": "^2.1.0",
|
"jsonata": "^2.1.0",
|
||||||
"jsonpath-plus": "^10.4.0",
|
"jsonpath-plus": "^10.4.0",
|
||||||
"jsonwebtoken": "8.5.1",
|
"jsonwebtoken": "9.0.3",
|
||||||
"jsqr": "^1.4.0",
|
"jsqr": "^1.4.0",
|
||||||
"jsrsasign": "^11.1.1",
|
"jsrsasign": "^11.1.1",
|
||||||
"kbpgp": "^2.1.17",
|
"kbpgp": "^2.1.17",
|
||||||
@ -179,9 +177,10 @@
|
|||||||
"snackbarjs": "^1.1.0",
|
"snackbarjs": "^1.1.0",
|
||||||
"sortablejs": "^1.15.7",
|
"sortablejs": "^1.15.7",
|
||||||
"split.js": "^1.6.5",
|
"split.js": "^1.6.5",
|
||||||
|
"sql-formatter": "^15.6.12",
|
||||||
"ssdeep.js": "0.0.3",
|
"ssdeep.js": "0.0.3",
|
||||||
"stream-browserify": "^3.0.0",
|
"stream-browserify": "^3.0.0",
|
||||||
"tesseract.js": "5.1.1",
|
"tesseract.js": "^6.0.1",
|
||||||
"ua-parser-js": "^1.0.41",
|
"ua-parser-js": "^1.0.41",
|
||||||
"unorm": "^1.6.0",
|
"unorm": "^1.6.0",
|
||||||
"url": "^0.11.4",
|
"url": "^0.11.4",
|
||||||
|
|||||||
@ -41,6 +41,7 @@
|
|||||||
"From Base",
|
"From Base",
|
||||||
"To BCD",
|
"To BCD",
|
||||||
"From BCD",
|
"From BCD",
|
||||||
|
"Text-Integer Conversion",
|
||||||
"To HTML Entity",
|
"To HTML Entity",
|
||||||
"From HTML Entity",
|
"From HTML Entity",
|
||||||
"URL Encode",
|
"URL Encode",
|
||||||
@ -109,6 +110,8 @@
|
|||||||
"Rabbit",
|
"Rabbit",
|
||||||
"SM4 Encrypt",
|
"SM4 Encrypt",
|
||||||
"SM4 Decrypt",
|
"SM4 Decrypt",
|
||||||
|
"RC6 Encrypt",
|
||||||
|
"RC6 Decrypt",
|
||||||
"GOST Encrypt",
|
"GOST Encrypt",
|
||||||
"GOST Decrypt",
|
"GOST Decrypt",
|
||||||
"GOST Sign",
|
"GOST Sign",
|
||||||
@ -164,7 +167,10 @@
|
|||||||
"Typex",
|
"Typex",
|
||||||
"Lorenz",
|
"Lorenz",
|
||||||
"Colossus",
|
"Colossus",
|
||||||
"SIGABA"
|
"SIGABA",
|
||||||
|
"Flask Session Decode",
|
||||||
|
"Flask Session Sign",
|
||||||
|
"Flask Session Verify"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -222,6 +228,9 @@
|
|||||||
"Subtract",
|
"Subtract",
|
||||||
"Multiply",
|
"Multiply",
|
||||||
"Divide",
|
"Divide",
|
||||||
|
"Modular Exponentiation",
|
||||||
|
"Modular Inverse",
|
||||||
|
"Extended GCD",
|
||||||
"Mean",
|
"Mean",
|
||||||
"Median",
|
"Median",
|
||||||
"Standard Deviation",
|
"Standard Deviation",
|
||||||
@ -550,7 +559,9 @@
|
|||||||
"Chi Square",
|
"Chi Square",
|
||||||
"P-list Viewer",
|
"P-list Viewer",
|
||||||
"Disassemble x86",
|
"Disassemble x86",
|
||||||
|
"Disassemble ARM",
|
||||||
"Pseudo-Random Number Generator",
|
"Pseudo-Random Number Generator",
|
||||||
|
"Pseudo-Random Integer Generator",
|
||||||
"Generate De Bruijn Sequence",
|
"Generate De Bruijn Sequence",
|
||||||
"Generate UUID",
|
"Generate UUID",
|
||||||
"Analyse UUID",
|
"Analyse UUID",
|
||||||
|
|||||||
73
src/core/lib/BigIntUtils.mjs
Normal file
73
src/core/lib/BigIntUtils.mjs
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/**
|
||||||
|
* @author p-leriche [philip.leriche@cantab.net]
|
||||||
|
* @copyright Crown Copyright 2025
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number theory utilities used by cryptographic operations.
|
||||||
|
*
|
||||||
|
* Currently provides:
|
||||||
|
* - parseBigInt
|
||||||
|
* - Extended Euclidean Algorithm
|
||||||
|
* - Modular Exponentiation
|
||||||
|
*
|
||||||
|
* Additional algorithms may be added as required.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* parseBigInt helper operation
|
||||||
|
*/
|
||||||
|
export function parseBigInt(value, param) {
|
||||||
|
const v = (value ?? "").trim();
|
||||||
|
if (/^0x[0-9a-f]+$/i.test(v)) return BigInt(v);
|
||||||
|
if (/^[+-]?[0-9]+$/.test(v)) return BigInt(v);
|
||||||
|
throw new OperationError(param + " must be decimal or hex (0x...)");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extended Euclidean Algorithm
|
||||||
|
*
|
||||||
|
* Returns [g, x, y] such that:
|
||||||
|
* a*x + b*y = g = gcd(a, b)
|
||||||
|
*
|
||||||
|
* (Uses an iterative algorithm to avoid possible stack overflow)
|
||||||
|
*/
|
||||||
|
export function egcd(a, b) {
|
||||||
|
let oldR = a, r = b;
|
||||||
|
let oldS = 1n, s = 0n;
|
||||||
|
let oldT = 0n, t = 1n;
|
||||||
|
|
||||||
|
while (r !== 0n) {
|
||||||
|
const quotient = oldR / r;
|
||||||
|
|
||||||
|
[oldR, r] = [r, oldR - quotient * r];
|
||||||
|
[oldS, s] = [s, oldS - quotient * s];
|
||||||
|
[oldT, t] = [t, oldT - quotient * t];
|
||||||
|
}
|
||||||
|
|
||||||
|
// oldR is the gcd
|
||||||
|
// oldS and oldT are the Bézout coefficients
|
||||||
|
return [oldR, oldS, oldT];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modular exponentiation
|
||||||
|
*/
|
||||||
|
export function modPow(base, exponent, modulus) {
|
||||||
|
let result = 1n;
|
||||||
|
base %= modulus;
|
||||||
|
|
||||||
|
while (exponent > 0n) {
|
||||||
|
if (exponent & 1n) {
|
||||||
|
result = (result * base) % modulus;
|
||||||
|
}
|
||||||
|
base = (base * base) % modulus;
|
||||||
|
exponent >>= 1n;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
625
src/core/lib/RC6.mjs
Normal file
625
src/core/lib/RC6.mjs
Normal file
@ -0,0 +1,625 @@
|
|||||||
|
/**
|
||||||
|
* Complete implementation of RC6 block cipher encryption/decryption with
|
||||||
|
* configurable word size (w), rounds (r), and key length (b).
|
||||||
|
*
|
||||||
|
* RC6 was an AES finalist designed by Ron Rivest, Matt Robshaw, Ray Sidney, and Yiqun Lisa Yin.
|
||||||
|
* Reference: https://en.wikipedia.org/wiki/RC6
|
||||||
|
* Test Vectors: https://datatracker.ietf.org/doc/html/draft-krovetz-rc6-rc5-vectors-00
|
||||||
|
*
|
||||||
|
* The P and Q constants are derived from mathematical constants e (Euler's number) and
|
||||||
|
* φ (golden ratio) as specified in the IETF draft. Master 256-bit values are scaled to
|
||||||
|
* any word size.
|
||||||
|
*
|
||||||
|
* @author Medjedtxm
|
||||||
|
* @copyright Crown Copyright 2026
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Master P constant (256-bit) from IETF draft-krovetz-rc6-rc5-vectors-00
|
||||||
|
* Derived from Odd((e-2) * 2^256) where e = 2.71828...
|
||||||
|
*/
|
||||||
|
const P_256 = 0xb7e151628aed2a6abf7158809cf4f3c762e7160f38b4da56a784d9045190cfefn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Master Q constant (256-bit) from IETF draft-krovetz-rc6-rc5-vectors-00
|
||||||
|
* Derived from Odd((φ-1) * 2^256) where φ = 1.61803... (golden ratio)
|
||||||
|
*/
|
||||||
|
const Q_256 = 0x9e3779b97f4a7c15f39cc0605cedc8341082276bf3a27251f86c6a11d0c18e95n;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get P constant for given word size by scaling the 256-bit master constant
|
||||||
|
* @param {number} w - Word size in bits
|
||||||
|
* @returns {bigint} - P constant for word size w
|
||||||
|
*/
|
||||||
|
function getP(w) {
|
||||||
|
return (P_256 >> BigInt(256 - w)) | 1n; // Ensure odd
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Q constant for given word size by scaling the 256-bit master constant
|
||||||
|
* @param {number} w - Word size in bits
|
||||||
|
* @returns {bigint} - Q constant for word size w
|
||||||
|
*/
|
||||||
|
function getQ(w) {
|
||||||
|
return (Q_256 >> BigInt(256 - w)) | 1n; // Ensure odd
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get block size in bytes for given word size
|
||||||
|
* Block size = 4 words = 4 * (w/8) bytes
|
||||||
|
* @param {number} w - Word size in bits
|
||||||
|
* @returns {number} - Block size in bytes
|
||||||
|
*/
|
||||||
|
export function getBlockSize(w) {
|
||||||
|
return 4 * (w / 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get recommended number of rounds for given word size
|
||||||
|
* @param {number} w - Word size in bits
|
||||||
|
* @returns {number} - Recommended rounds
|
||||||
|
*/
|
||||||
|
export function getDefaultRounds(w) {
|
||||||
|
if (w <= 16) return 16;
|
||||||
|
if (w <= 32) return 20;
|
||||||
|
if (w <= 64) return 24;
|
||||||
|
return 28;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create mask for w-bit word
|
||||||
|
* @param {number} w - Word size in bits
|
||||||
|
* @returns {bigint} - Mask with w bits set
|
||||||
|
*/
|
||||||
|
function wordMask(w) {
|
||||||
|
return (1n << BigInt(w)) - 1n;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotate left for arbitrary word size using BigInt
|
||||||
|
* Uses lower lg(w) bits of n for rotation amount (RC6 spec)
|
||||||
|
* @param {bigint} x - Value to rotate
|
||||||
|
* @param {bigint} n - Rotation amount
|
||||||
|
* @param {number} w - Word size in bits
|
||||||
|
* @param {bigint} lgMask - Mask for lower lg(w) bits
|
||||||
|
* @returns {bigint} - Rotated value
|
||||||
|
*/
|
||||||
|
function ROL(x, n, w, lgMask) {
|
||||||
|
const mask = wordMask(w);
|
||||||
|
// Mask to lg(w) bits, then mod w for non-power-of-2 word sizes
|
||||||
|
// For power-of-2, (n & lgMask) < w always, so mod w is no-op
|
||||||
|
const shift = (n & lgMask) % BigInt(w);
|
||||||
|
return ((x << shift) | (x >> (BigInt(w) - shift))) & mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotate right for arbitrary word size using BigInt
|
||||||
|
* Uses lower lg(w) bits of n for rotation amount (RC6 spec)
|
||||||
|
* @param {bigint} x - Value to rotate
|
||||||
|
* @param {bigint} n - Rotation amount
|
||||||
|
* @param {number} w - Word size in bits
|
||||||
|
* @param {bigint} lgMask - Mask for lower lg(w) bits
|
||||||
|
* @returns {bigint} - Rotated value
|
||||||
|
*/
|
||||||
|
function ROR(x, n, w, lgMask) {
|
||||||
|
const mask = wordMask(w);
|
||||||
|
// Mask to lg(w) bits, then mod w for non-power-of-2 word sizes
|
||||||
|
// For power-of-2, (n & lgMask) < w always, so mod w is no-op
|
||||||
|
const shift = (n & lgMask) % BigInt(w);
|
||||||
|
return ((x >> shift) | (x << (BigInt(w) - shift))) & mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert byte array to word array (little-endian) using BigInt
|
||||||
|
* @param {number[]} bytes - Input byte array
|
||||||
|
* @param {number} w - Word size in bits
|
||||||
|
* @returns {bigint[]} - Array of w-bit words as BigInt
|
||||||
|
*/
|
||||||
|
function bytesToWords(bytes, w) {
|
||||||
|
const bytesPerWord = w / 8;
|
||||||
|
const words = [];
|
||||||
|
for (let i = 0; i < bytes.length; i += bytesPerWord) {
|
||||||
|
let word = 0n;
|
||||||
|
for (let j = 0; j < bytesPerWord && (i + j) < bytes.length; j++) {
|
||||||
|
word |= BigInt(bytes[i + j] || 0) << BigInt(j * 8);
|
||||||
|
}
|
||||||
|
words.push(word);
|
||||||
|
}
|
||||||
|
return words;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert word array to byte array (little-endian) using BigInt
|
||||||
|
* @param {bigint[]} words - Array of words
|
||||||
|
* @param {number} w - Word size in bits
|
||||||
|
* @returns {number[]} - Output byte array
|
||||||
|
*/
|
||||||
|
function wordsToBytes(words, w) {
|
||||||
|
const bytesPerWord = w / 8;
|
||||||
|
const bytes = [];
|
||||||
|
for (const word of words) {
|
||||||
|
for (let j = 0; j < bytesPerWord; j++) {
|
||||||
|
bytes.push(Number((word >> BigInt(j * 8)) & 0xFFn));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate round subkeys from user key
|
||||||
|
*
|
||||||
|
* @param {number[]} key - User key as byte array
|
||||||
|
* @param {number} rounds - Number of rounds
|
||||||
|
* @param {number} w - Word size in bits
|
||||||
|
* @returns {bigint[]} - Array of 2r+4 subkeys as BigInt
|
||||||
|
*/
|
||||||
|
function generateSubkeys(key, rounds, w) {
|
||||||
|
const bytesPerWord = w / 8;
|
||||||
|
const b = key.length;
|
||||||
|
const c = Math.max(Math.ceil(b / bytesPerWord), 1);
|
||||||
|
|
||||||
|
// Convert key bytes to words, pad with zeros if needed
|
||||||
|
const paddedKey = [...key];
|
||||||
|
while (paddedKey.length < c * bytesPerWord) {
|
||||||
|
paddedKey.push(0);
|
||||||
|
}
|
||||||
|
const L = bytesToWords(paddedKey, w);
|
||||||
|
|
||||||
|
// Number of subkeys: 2*r + 4
|
||||||
|
const t = 2 * rounds + 4;
|
||||||
|
|
||||||
|
// Get P and Q for this word size
|
||||||
|
const P = getP(w);
|
||||||
|
const Q = getQ(w);
|
||||||
|
const mask = wordMask(w);
|
||||||
|
|
||||||
|
// lg(w) mask for rotation amounts (floor of log2(w), per RC6 spec)
|
||||||
|
const lgw = Math.floor(Math.log2(w));
|
||||||
|
const lgMask = (1n << BigInt(lgw)) - 1n;
|
||||||
|
|
||||||
|
// Initialise S array with magic constants
|
||||||
|
const S = new Array(t);
|
||||||
|
S[0] = P;
|
||||||
|
for (let i = 1; i < t; i++) {
|
||||||
|
S[i] = (S[i - 1] + Q) & mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mix key into S
|
||||||
|
let A = 0n, B = 0n;
|
||||||
|
let i = 0, j = 0;
|
||||||
|
const v = 3 * Math.max(c, t);
|
||||||
|
|
||||||
|
for (let s = 0; s < v; s++) {
|
||||||
|
A = S[i] = ROL((S[i] + A + B) & mask, 3n, w, lgMask);
|
||||||
|
B = L[j] = ROL((L[j] + A + B) & mask, A + B, w, lgMask);
|
||||||
|
i = (i + 1) % t;
|
||||||
|
j = (j + 1) % c;
|
||||||
|
}
|
||||||
|
|
||||||
|
return S;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encrypt a single block using RC6
|
||||||
|
*
|
||||||
|
* @param {number[]} block - Plaintext block (4*w/8 bytes)
|
||||||
|
* @param {bigint[]} S - Subkeys array
|
||||||
|
* @param {number} rounds - Number of rounds
|
||||||
|
* @param {number} w - Word size in bits
|
||||||
|
* @returns {number[]} - Ciphertext block
|
||||||
|
*/
|
||||||
|
function encryptBlock(block, S, rounds, w) {
|
||||||
|
const mask = wordMask(w);
|
||||||
|
const lgw = BigInt(Math.floor(Math.log2(w)));
|
||||||
|
const lgMask = (1n << lgw) - 1n;
|
||||||
|
|
||||||
|
// Convert block to 4 words (A, B, C, D)
|
||||||
|
let [A, B, C, D] = bytesToWords(block, w);
|
||||||
|
|
||||||
|
// Pre-whitening
|
||||||
|
B = (B + S[0]) & mask;
|
||||||
|
D = (D + S[1]) & mask;
|
||||||
|
|
||||||
|
// Main rounds
|
||||||
|
for (let i = 1; i <= rounds; i++) {
|
||||||
|
// t = ROL(B * (2B + 1), lg(w))
|
||||||
|
const t = ROL((B * ((2n * B + 1n) & mask)) & mask, lgw, w, lgMask);
|
||||||
|
|
||||||
|
// u = ROL(D * (2D + 1), lg(w))
|
||||||
|
const u = ROL((D * ((2n * D + 1n) & mask)) & mask, lgw, w, lgMask);
|
||||||
|
|
||||||
|
// A = ROL(A ^ t, u) + S[2i]
|
||||||
|
A = (ROL(A ^ t, u, w, lgMask) + S[2 * i]) & mask;
|
||||||
|
|
||||||
|
// C = ROL(C ^ u, t) + S[2i + 1]
|
||||||
|
C = (ROL(C ^ u, t, w, lgMask) + S[2 * i + 1]) & mask;
|
||||||
|
|
||||||
|
// Rotate registers: (A, B, C, D) = (B, C, D, A)
|
||||||
|
const temp = A;
|
||||||
|
A = B;
|
||||||
|
B = C;
|
||||||
|
C = D;
|
||||||
|
D = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Post-whitening
|
||||||
|
A = (A + S[2 * rounds + 2]) & mask;
|
||||||
|
C = (C + S[2 * rounds + 3]) & mask;
|
||||||
|
|
||||||
|
// Convert words back to bytes
|
||||||
|
return wordsToBytes([A, B, C, D], w);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrypt a single block using RC6
|
||||||
|
*
|
||||||
|
* @param {number[]} block - Ciphertext block (4*w/8 bytes)
|
||||||
|
* @param {bigint[]} S - Subkeys array
|
||||||
|
* @param {number} rounds - Number of rounds
|
||||||
|
* @param {number} w - Word size in bits
|
||||||
|
* @returns {number[]} - Plaintext block
|
||||||
|
*/
|
||||||
|
function decryptBlock(block, S, rounds, w) {
|
||||||
|
const mask = wordMask(w);
|
||||||
|
const lgw = BigInt(Math.floor(Math.log2(w)));
|
||||||
|
const lgMask = (1n << lgw) - 1n;
|
||||||
|
|
||||||
|
// Convert block to 4 words (A, B, C, D)
|
||||||
|
let [A, B, C, D] = bytesToWords(block, w);
|
||||||
|
|
||||||
|
// Reverse post-whitening
|
||||||
|
C = (C - S[2 * rounds + 3] + (1n << BigInt(w))) & mask;
|
||||||
|
A = (A - S[2 * rounds + 2] + (1n << BigInt(w))) & mask;
|
||||||
|
|
||||||
|
// Main rounds in reverse
|
||||||
|
for (let i = rounds; i >= 1; i--) {
|
||||||
|
// Reverse rotate registers: (A, B, C, D) = (D, A, B, C)
|
||||||
|
const temp = D;
|
||||||
|
D = C;
|
||||||
|
C = B;
|
||||||
|
B = A;
|
||||||
|
A = temp;
|
||||||
|
|
||||||
|
// u = ROL(D * (2D + 1), lg(w))
|
||||||
|
const u = ROL((D * ((2n * D + 1n) & mask)) & mask, lgw, w, lgMask);
|
||||||
|
|
||||||
|
// t = ROL(B * (2B + 1), lg(w))
|
||||||
|
const t = ROL((B * ((2n * B + 1n) & mask)) & mask, lgw, w, lgMask);
|
||||||
|
|
||||||
|
// C = ROR(C - S[2i + 1], t) ^ u
|
||||||
|
C = ROR((C - S[2 * i + 1] + (1n << BigInt(w))) & mask, t, w, lgMask) ^ u;
|
||||||
|
|
||||||
|
// A = ROR(A - S[2i], u) ^ t
|
||||||
|
A = ROR((A - S[2 * i] + (1n << BigInt(w))) & mask, u, w, lgMask) ^ t;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reverse pre-whitening
|
||||||
|
D = (D - S[1] + (1n << BigInt(w))) & mask;
|
||||||
|
B = (B - S[0] + (1n << BigInt(w))) & mask;
|
||||||
|
|
||||||
|
// Convert words back to bytes
|
||||||
|
return wordsToBytes([A, B, C, D], w);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XOR two blocks
|
||||||
|
* @param {number[]} a - First block
|
||||||
|
* @param {number[]} b - Second block
|
||||||
|
* @returns {number[]} - XOR result
|
||||||
|
*/
|
||||||
|
function xorBlocks(a, b) {
|
||||||
|
const result = new Array(a.length);
|
||||||
|
for (let i = 0; i < a.length; i++) {
|
||||||
|
result[i] = a[i] ^ b[i];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increment counter (little-endian)
|
||||||
|
* @param {number[]} counter - Counter block
|
||||||
|
* @returns {number[]} - Incremented counter
|
||||||
|
*/
|
||||||
|
function incrementCounter(counter) {
|
||||||
|
const result = [...counter];
|
||||||
|
for (let i = 0; i < result.length; i++) {
|
||||||
|
result[i]++;
|
||||||
|
if (result[i] <= 255) break;
|
||||||
|
result[i] = 0;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply padding to message
|
||||||
|
* @param {number[]} message - Original message
|
||||||
|
* @param {string} padding - Padding type ("NO", "PKCS5", "ZERO", "RANDOM", "BIT")
|
||||||
|
* @param {number} blockSize - Block size in bytes
|
||||||
|
* @returns {number[]} - Padded message
|
||||||
|
*/
|
||||||
|
function applyPadding(message, padding, blockSize) {
|
||||||
|
const remainder = message.length % blockSize;
|
||||||
|
let nPadding = remainder === 0 ? 0 : blockSize - remainder;
|
||||||
|
|
||||||
|
// For PKCS5, always add at least one byte (full block if already aligned)
|
||||||
|
if (padding === "PKCS5" && remainder === 0) {
|
||||||
|
nPadding = blockSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nPadding === 0) return [...message];
|
||||||
|
|
||||||
|
const paddedMessage = [...message];
|
||||||
|
|
||||||
|
switch (padding) {
|
||||||
|
case "NO":
|
||||||
|
throw new OperationError(`No padding requested but input is not a ${blockSize}-byte multiple.`);
|
||||||
|
|
||||||
|
case "PKCS5":
|
||||||
|
for (let i = 0; i < nPadding; i++) {
|
||||||
|
paddedMessage.push(nPadding);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "ZERO":
|
||||||
|
for (let i = 0; i < nPadding; i++) {
|
||||||
|
paddedMessage.push(0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "RANDOM":
|
||||||
|
for (let i = 0; i < nPadding; i++) {
|
||||||
|
paddedMessage.push(Math.floor(Math.random() * 256));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "BIT":
|
||||||
|
paddedMessage.push(0x80);
|
||||||
|
for (let i = 1; i < nPadding; i++) {
|
||||||
|
paddedMessage.push(0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new OperationError(`Unknown padding type: ${padding}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return paddedMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove padding from message
|
||||||
|
* @param {number[]} message - Padded message
|
||||||
|
* @param {string} padding - Padding type ("NO", "PKCS5", "ZERO", "RANDOM", "BIT")
|
||||||
|
* @param {number} blockSize - Block size in bytes
|
||||||
|
* @returns {number[]} - Unpadded message
|
||||||
|
*/
|
||||||
|
function removePadding(message, padding, blockSize) {
|
||||||
|
if (message.length === 0) return message;
|
||||||
|
|
||||||
|
switch (padding) {
|
||||||
|
case "NO":
|
||||||
|
case "ZERO":
|
||||||
|
case "RANDOM":
|
||||||
|
// These padding types cannot be reliably removed
|
||||||
|
return message;
|
||||||
|
|
||||||
|
case "PKCS5": {
|
||||||
|
const padByte = message[message.length - 1];
|
||||||
|
if (padByte > 0 && padByte <= blockSize) {
|
||||||
|
// Verify padding
|
||||||
|
for (let i = 0; i < padByte; i++) {
|
||||||
|
if (message[message.length - 1 - i] !== padByte) {
|
||||||
|
throw new OperationError("Invalid PKCS#5 padding.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return message.slice(0, message.length - padByte);
|
||||||
|
}
|
||||||
|
throw new OperationError("Invalid PKCS#5 padding.");
|
||||||
|
}
|
||||||
|
|
||||||
|
case "BIT": {
|
||||||
|
// Find 0x80 byte working backwards, skipping zeros
|
||||||
|
for (let i = message.length - 1; i >= 0; i--) {
|
||||||
|
if (message[i] === 0x80) {
|
||||||
|
return message.slice(0, i);
|
||||||
|
} else if (message[i] !== 0) {
|
||||||
|
throw new OperationError("Invalid BIT padding.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new OperationError("Invalid BIT padding.");
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new OperationError(`Unknown padding type: ${padding}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encrypt using RC6 cipher with specified block mode
|
||||||
|
*
|
||||||
|
* @param {number[]} message - Plaintext as byte array
|
||||||
|
* @param {number[]} key - Key as byte array
|
||||||
|
* @param {number[]} iv - IV (block size bytes, not used for ECB)
|
||||||
|
* @param {string} mode - Block cipher mode ("ECB", "CBC", "CFB", "OFB", "CTR")
|
||||||
|
* @param {string} padding - Padding type ("NO", "PKCS5", "ZERO", "RANDOM", "BIT")
|
||||||
|
* @param {number} rounds - Number of rounds (default: 20)
|
||||||
|
* @param {number} w - Word size in bits (default: 32)
|
||||||
|
* @returns {number[]} - Ciphertext as byte array
|
||||||
|
*/
|
||||||
|
export function encryptRC6(message, key, iv, mode = "ECB", padding = "PKCS5", rounds = 20, w = 32) {
|
||||||
|
const blockSize = getBlockSize(w);
|
||||||
|
const messageLength = message.length;
|
||||||
|
if (messageLength === 0) return [];
|
||||||
|
|
||||||
|
const S = generateSubkeys(key, rounds, w);
|
||||||
|
|
||||||
|
// Apply padding for ECB/CBC modes
|
||||||
|
let paddedMessage;
|
||||||
|
if (mode === "ECB" || mode === "CBC") {
|
||||||
|
paddedMessage = applyPadding(message, padding, blockSize);
|
||||||
|
} else {
|
||||||
|
// Stream modes (CFB, OFB, CTR) don't need padding
|
||||||
|
paddedMessage = [...message];
|
||||||
|
}
|
||||||
|
|
||||||
|
const cipherText = [];
|
||||||
|
|
||||||
|
switch (mode) {
|
||||||
|
case "ECB":
|
||||||
|
for (let i = 0; i < paddedMessage.length; i += blockSize) {
|
||||||
|
const block = paddedMessage.slice(i, i + blockSize);
|
||||||
|
cipherText.push(...encryptBlock(block, S, rounds, w));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "CBC": {
|
||||||
|
let ivBlock = [...iv];
|
||||||
|
for (let i = 0; i < paddedMessage.length; i += blockSize) {
|
||||||
|
const block = paddedMessage.slice(i, i + blockSize);
|
||||||
|
const xored = xorBlocks(block, ivBlock);
|
||||||
|
ivBlock = encryptBlock(xored, S, rounds, w);
|
||||||
|
cipherText.push(...ivBlock);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "CFB": {
|
||||||
|
let ivBlock = [...iv];
|
||||||
|
for (let i = 0; i < paddedMessage.length; i += blockSize) {
|
||||||
|
const encrypted = encryptBlock(ivBlock, S, rounds, w);
|
||||||
|
const block = paddedMessage.slice(i, i + blockSize);
|
||||||
|
// Pad block if shorter than blockSize
|
||||||
|
while (block.length < blockSize) block.push(0);
|
||||||
|
ivBlock = xorBlocks(encrypted, block);
|
||||||
|
cipherText.push(...ivBlock);
|
||||||
|
}
|
||||||
|
return cipherText.slice(0, messageLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
case "OFB": {
|
||||||
|
let ivBlock = [...iv];
|
||||||
|
for (let i = 0; i < paddedMessage.length; i += blockSize) {
|
||||||
|
ivBlock = encryptBlock(ivBlock, S, rounds, w);
|
||||||
|
const block = paddedMessage.slice(i, i + blockSize);
|
||||||
|
// Pad block if shorter than blockSize
|
||||||
|
while (block.length < blockSize) block.push(0);
|
||||||
|
cipherText.push(...xorBlocks(ivBlock, block));
|
||||||
|
}
|
||||||
|
return cipherText.slice(0, messageLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
case "CTR": {
|
||||||
|
let counter = [...iv];
|
||||||
|
for (let i = 0; i < paddedMessage.length; i += blockSize) {
|
||||||
|
const encrypted = encryptBlock(counter, S, rounds, w);
|
||||||
|
const block = paddedMessage.slice(i, i + blockSize);
|
||||||
|
// Pad block if shorter than blockSize
|
||||||
|
while (block.length < blockSize) block.push(0);
|
||||||
|
cipherText.push(...xorBlocks(encrypted, block));
|
||||||
|
counter = incrementCounter(counter);
|
||||||
|
}
|
||||||
|
return cipherText.slice(0, messageLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new OperationError(`Invalid block cipher mode: ${mode}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cipherText;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrypt using RC6 cipher with specified block mode
|
||||||
|
*
|
||||||
|
* @param {number[]} cipherText - Ciphertext as byte array
|
||||||
|
* @param {number[]} key - Key as byte array
|
||||||
|
* @param {number[]} iv - IV (block size bytes, not used for ECB)
|
||||||
|
* @param {string} mode - Block cipher mode ("ECB", "CBC", "CFB", "OFB", "CTR")
|
||||||
|
* @param {string} padding - Padding type ("NO", "PKCS5", "ZERO", "RANDOM", "BIT")
|
||||||
|
* @param {number} rounds - Number of rounds (default: 20)
|
||||||
|
* @param {number} w - Word size in bits (default: 32)
|
||||||
|
* @returns {number[]} - Plaintext as byte array
|
||||||
|
*/
|
||||||
|
export function decryptRC6(cipherText, key, iv, mode = "ECB", padding = "PKCS5", rounds = 20, w = 32) {
|
||||||
|
const blockSize = getBlockSize(w);
|
||||||
|
const originalLength = cipherText.length;
|
||||||
|
if (originalLength === 0) return [];
|
||||||
|
|
||||||
|
const S = generateSubkeys(key, rounds, w);
|
||||||
|
|
||||||
|
if (mode === "ECB" || mode === "CBC") {
|
||||||
|
if ((originalLength % blockSize) !== 0)
|
||||||
|
throw new OperationError(`Invalid ciphertext length: ${originalLength} bytes. Must be a multiple of ${blockSize}.`);
|
||||||
|
} else {
|
||||||
|
// Pad for stream modes
|
||||||
|
while ((cipherText.length % blockSize) !== 0)
|
||||||
|
cipherText.push(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
const plainText = [];
|
||||||
|
|
||||||
|
switch (mode) {
|
||||||
|
case "ECB":
|
||||||
|
for (let i = 0; i < cipherText.length; i += blockSize) {
|
||||||
|
const block = cipherText.slice(i, i + blockSize);
|
||||||
|
plainText.push(...decryptBlock(block, S, rounds, w));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "CBC": {
|
||||||
|
let ivBlock = [...iv];
|
||||||
|
for (let i = 0; i < cipherText.length; i += blockSize) {
|
||||||
|
const block = cipherText.slice(i, i + blockSize);
|
||||||
|
const decrypted = decryptBlock(block, S, rounds, w);
|
||||||
|
plainText.push(...xorBlocks(decrypted, ivBlock));
|
||||||
|
ivBlock = block;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "CFB": {
|
||||||
|
let ivBlock = [...iv];
|
||||||
|
for (let i = 0; i < cipherText.length; i += blockSize) {
|
||||||
|
const encrypted = encryptBlock(ivBlock, S, rounds, w);
|
||||||
|
const block = cipherText.slice(i, i + blockSize);
|
||||||
|
plainText.push(...xorBlocks(encrypted, block));
|
||||||
|
ivBlock = block;
|
||||||
|
}
|
||||||
|
return plainText.slice(0, originalLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
case "OFB": {
|
||||||
|
let ivBlock = [...iv];
|
||||||
|
for (let i = 0; i < cipherText.length; i += blockSize) {
|
||||||
|
ivBlock = encryptBlock(ivBlock, S, rounds, w);
|
||||||
|
const block = cipherText.slice(i, i + blockSize);
|
||||||
|
plainText.push(...xorBlocks(ivBlock, block));
|
||||||
|
}
|
||||||
|
return plainText.slice(0, originalLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
case "CTR": {
|
||||||
|
let counter = [...iv];
|
||||||
|
for (let i = 0; i < cipherText.length; i += blockSize) {
|
||||||
|
const encrypted = encryptBlock(counter, S, rounds, w);
|
||||||
|
const block = cipherText.slice(i, i + blockSize);
|
||||||
|
plainText.push(...xorBlocks(encrypted, block));
|
||||||
|
counter = incrementCounter(counter);
|
||||||
|
}
|
||||||
|
return plainText.slice(0, originalLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new OperationError(`Invalid block cipher mode: ${mode}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove padding for ECB/CBC modes
|
||||||
|
if (mode === "ECB" || mode === "CBC") {
|
||||||
|
return removePadding(plainText, padding, blockSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
return plainText.slice(0, originalLength);
|
||||||
|
}
|
||||||
193
src/core/operations/DisassembleARM.mjs
Normal file
193
src/core/operations/DisassembleARM.mjs
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
/**
|
||||||
|
* @author MedjedThomasXM
|
||||||
|
* @copyright Crown Copyright 2024
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Operation from "../Operation.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
|
import { isWorkerEnvironment } from "../Utils.mjs";
|
||||||
|
import cs from "@alexaltea/capstone-js/dist/capstone.min.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disassemble ARM operation
|
||||||
|
*/
|
||||||
|
class DisassembleARM extends Operation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DisassembleARM constructor
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.name = "Disassemble ARM";
|
||||||
|
this.module = "Shellcode";
|
||||||
|
this.description = "Disassembles ARM machine code into assembly language.<br><br>Supports ARM (32-bit), Thumb, and ARM64 (AArch64) architectures using the Capstone disassembly framework.<br><br>Input should be in hexadecimal.";
|
||||||
|
this.infoURL = "https://wikipedia.org/wiki/ARM_architecture_family";
|
||||||
|
this.inputType = "string";
|
||||||
|
this.outputType = "string";
|
||||||
|
this.args = [
|
||||||
|
{
|
||||||
|
"name": "Architecture",
|
||||||
|
"type": "option",
|
||||||
|
"value": ["ARM (32-bit)", "ARM64 (AArch64)"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Mode",
|
||||||
|
"type": "option",
|
||||||
|
"value": ["ARM", "Thumb", "Thumb + Cortex-M", "ARMv8"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Endianness",
|
||||||
|
"type": "option",
|
||||||
|
"value": ["Little Endian", "Big Endian"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Starting address (hex)",
|
||||||
|
"type": "number",
|
||||||
|
"value": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Show instruction hex",
|
||||||
|
"type": "boolean",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Show instruction position",
|
||||||
|
"type": "boolean",
|
||||||
|
"value": true
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
async run(input, args) {
|
||||||
|
const [
|
||||||
|
architecture,
|
||||||
|
mode,
|
||||||
|
endianness,
|
||||||
|
startAddress,
|
||||||
|
showHex,
|
||||||
|
showPosition
|
||||||
|
] = args;
|
||||||
|
|
||||||
|
// Remove whitespace from input
|
||||||
|
const hexInput = input.replace(/\s/g, "");
|
||||||
|
|
||||||
|
// Validate hex input
|
||||||
|
if (!/^[0-9a-fA-F]*$/.test(hexInput)) {
|
||||||
|
throw new OperationError("Invalid hexadecimal input. Please provide valid hex characters only.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hexInput.length === 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hexInput.length % 2 !== 0) {
|
||||||
|
throw new OperationError("Invalid hexadecimal input. Length must be even.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert hex string to byte array
|
||||||
|
const bytes = [];
|
||||||
|
for (let i = 0; i < hexInput.length; i += 2) {
|
||||||
|
bytes.push(parseInt(hexInput.substr(i, 2), 16));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine architecture constant
|
||||||
|
let arch;
|
||||||
|
if (architecture === "ARM64 (AArch64)") {
|
||||||
|
arch = cs.ARCH_ARM64;
|
||||||
|
} else {
|
||||||
|
arch = cs.ARCH_ARM;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine mode constant
|
||||||
|
let modeValue = cs.MODE_LITTLE_ENDIAN;
|
||||||
|
|
||||||
|
if (architecture === "ARM (32-bit)") {
|
||||||
|
switch (mode) {
|
||||||
|
case "ARM":
|
||||||
|
modeValue = cs.MODE_ARM;
|
||||||
|
break;
|
||||||
|
case "Thumb":
|
||||||
|
modeValue = cs.MODE_THUMB;
|
||||||
|
break;
|
||||||
|
case "Thumb + Cortex-M":
|
||||||
|
modeValue = cs.MODE_THUMB | cs.MODE_MCLASS;
|
||||||
|
break;
|
||||||
|
case "ARMv8":
|
||||||
|
modeValue = cs.MODE_ARM | cs.MODE_V8;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
modeValue = cs.MODE_ARM;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// ARM64 only has one mode (ARM mode is default for ARM64)
|
||||||
|
modeValue = cs.MODE_ARM;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add endianness
|
||||||
|
if (endianness === "Big Endian") {
|
||||||
|
modeValue |= cs.MODE_BIG_ENDIAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isWorkerEnvironment()) {
|
||||||
|
self.sendStatusMessage("Disassembling...");
|
||||||
|
}
|
||||||
|
|
||||||
|
let disassembler;
|
||||||
|
try {
|
||||||
|
disassembler = new cs.Capstone(arch, modeValue);
|
||||||
|
} catch (e) {
|
||||||
|
throw new OperationError(`Failed to initialise Capstone disassembler: ${e}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
let instructions;
|
||||||
|
try {
|
||||||
|
instructions = disassembler.disasm(bytes, startAddress);
|
||||||
|
} catch (e) {
|
||||||
|
disassembler.close();
|
||||||
|
// Check if it's a "no valid instructions" error (code 0 means OK but nothing decoded)
|
||||||
|
if (e && e.includes && e.includes("code 0:")) {
|
||||||
|
throw new OperationError(`No valid ${architecture} instructions found in input. The bytes may be for a different architecture or mode.`);
|
||||||
|
}
|
||||||
|
throw new OperationError(`Disassembly failed: ${e}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format output
|
||||||
|
const output = [];
|
||||||
|
for (const insn of instructions) {
|
||||||
|
let line = "";
|
||||||
|
|
||||||
|
if (showPosition) {
|
||||||
|
// Format address as hex with 0x prefix
|
||||||
|
const addrHex = "0x" + insn.address.toString(16).padStart(8, "0");
|
||||||
|
line += addrHex + " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showHex) {
|
||||||
|
// Format instruction bytes as hex
|
||||||
|
const bytesHex = insn.bytes.map(b => b.toString(16).padStart(2, "0")).join("");
|
||||||
|
line += bytesHex.padEnd(16, " ") + " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
line += insn.mnemonic;
|
||||||
|
if (insn.op_str) {
|
||||||
|
line += " " + insn.op_str;
|
||||||
|
}
|
||||||
|
|
||||||
|
output.push(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
disassembler.close();
|
||||||
|
|
||||||
|
return output.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DisassembleARM;
|
||||||
80
src/core/operations/FlaskSessionDecode.mjs
Normal file
80
src/core/operations/FlaskSessionDecode.mjs
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/**
|
||||||
|
* @author ThePlayer372-FR []
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Operation from "../Operation.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
|
import { fromBase64 } from "../lib/Base64.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flask Session Decode operation
|
||||||
|
*/
|
||||||
|
class FlaskSessionDecode extends Operation {
|
||||||
|
/**
|
||||||
|
* FlaskSessionDecode constructor
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.name = "Flask Session Decode";
|
||||||
|
this.module = "Crypto";
|
||||||
|
this.description = "Decodes the payload of a Flask session cookie (itsdangerous) into JSON.";
|
||||||
|
this.inputType = "string";
|
||||||
|
this.outputType = "JSON";
|
||||||
|
this.args = [
|
||||||
|
{
|
||||||
|
name: "View TimeStamp",
|
||||||
|
type: "boolean",
|
||||||
|
value: false
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {Object[]}
|
||||||
|
*/
|
||||||
|
run(input, args) {
|
||||||
|
input = input.trim();
|
||||||
|
const parts = input.split(".");
|
||||||
|
if (parts.length !== 3) {
|
||||||
|
throw new OperationError("Invalid Flask token format. Expected payload.timestamp.signature");
|
||||||
|
}
|
||||||
|
|
||||||
|
const payloadB64 = parts[0];
|
||||||
|
const time = parts[1];
|
||||||
|
|
||||||
|
const timeB64 = time.replace(/-/g, "+").replace(/_/g, "/");
|
||||||
|
const binary = fromBase64(timeB64);
|
||||||
|
const bytes = new Uint8Array(4);
|
||||||
|
for (let i = 0; i < 4; i++) {
|
||||||
|
bytes[i] = binary.charCodeAt(i);
|
||||||
|
}
|
||||||
|
const view = new DataView(bytes.buffer);
|
||||||
|
const timestamp = view.getInt32(0, false);
|
||||||
|
|
||||||
|
const base64 = payloadB64.replace(/-/g, "+").replace(/_/g, "/");
|
||||||
|
const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
|
||||||
|
let payloadJson;
|
||||||
|
try {
|
||||||
|
payloadJson = fromBase64(padded);
|
||||||
|
} catch (e) {
|
||||||
|
throw new OperationError("Invalid Base64 payload");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
let data = JSON.parse(payloadJson);
|
||||||
|
|
||||||
|
if (args[0]) {
|
||||||
|
data = {payload: data, timestamp: timestamp};
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
} catch (e) {
|
||||||
|
throw new OperationError("Unable to decode JSON payload: " + e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default FlaskSessionDecode;
|
||||||
89
src/core/operations/FlaskSessionSign.mjs
Normal file
89
src/core/operations/FlaskSessionSign.mjs
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
/**
|
||||||
|
* @author ThePlayer372-FR []
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Operation from "../Operation.mjs";
|
||||||
|
import CryptoApi from "crypto-api/src/crypto-api.mjs";
|
||||||
|
import Utils from "../Utils.mjs";
|
||||||
|
import { toBase64 } from "../lib/Base64.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flask Session Sign operation
|
||||||
|
*/
|
||||||
|
class FlaskSessionSign extends Operation {
|
||||||
|
/**
|
||||||
|
* FlaskSessionSign constructor
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.name = "Flask Session Sign";
|
||||||
|
this.module = "Crypto";
|
||||||
|
this.description = "Signs a JSON payload to produce a Flask session cookie (itsdangerous HMAC).";
|
||||||
|
this.inputType = "JSON";
|
||||||
|
this.outputType = "string";
|
||||||
|
this.args = [
|
||||||
|
{
|
||||||
|
name: "Key",
|
||||||
|
type: "toggleString",
|
||||||
|
value: "",
|
||||||
|
toggleValues: ["Hex", "Decimal", "Binary", "Base64", "UTF8", "Latin1"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Salt",
|
||||||
|
type: "toggleString",
|
||||||
|
value: "cookie-session",
|
||||||
|
toggleValues: ["UTF8", "Hex", "Decimal", "Binary", "Base64", "Latin1"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Algorithm",
|
||||||
|
type: "option",
|
||||||
|
value: ["sha1", "sha256"],
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
run(input, args) {
|
||||||
|
if (!args[0].string) {
|
||||||
|
throw new OperationError("Secret key required");
|
||||||
|
}
|
||||||
|
const key = Utils.convertToByteString(args[0].string, args[0].option);
|
||||||
|
const salt = Utils.convertToByteString(args[1].string || "cookie-session", args[1].option);
|
||||||
|
const algorithm = args[2] || "sha1";
|
||||||
|
|
||||||
|
const payloadB64 = toBase64(Utils.strToByteArray(JSON.stringify(input)));
|
||||||
|
const payload = payloadB64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
||||||
|
|
||||||
|
const derivedKey = CryptoApi.getHmac(key, CryptoApi.getHasher(algorithm));
|
||||||
|
derivedKey.update(salt);
|
||||||
|
|
||||||
|
const currentTimeStamp = Math.ceil(Date.now() / 1000);
|
||||||
|
const buffer = new ArrayBuffer(4);
|
||||||
|
const view = new DataView(buffer);
|
||||||
|
view.setInt32(0, currentTimeStamp, false);
|
||||||
|
const bytes = new Uint8Array(buffer);
|
||||||
|
let binary = "";
|
||||||
|
bytes.forEach(b => binary += String.fromCharCode(b));
|
||||||
|
const timeB64 = toBase64(Utils.strToByteArray(binary));
|
||||||
|
const time = timeB64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
||||||
|
|
||||||
|
const data = Utils.convertToByteString(payload + "." + time, "utf8");
|
||||||
|
const sign = CryptoApi.getHmac(derivedKey.finalize(), CryptoApi.getHasher(algorithm));
|
||||||
|
sign.update(data);
|
||||||
|
|
||||||
|
const signB64 = toBase64(sign.finalize());
|
||||||
|
const sign64 = signB64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
||||||
|
|
||||||
|
return payload + "." + time + "." + sign64;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default FlaskSessionSign;
|
||||||
136
src/core/operations/FlaskSessionVerify.mjs
Normal file
136
src/core/operations/FlaskSessionVerify.mjs
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
/**
|
||||||
|
* @author ThePlayer372-FR []
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Operation from "../Operation.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
|
import CryptoApi from "crypto-api/src/crypto-api.mjs";
|
||||||
|
import Utils from "../Utils.mjs";
|
||||||
|
import { toBase64, fromBase64 } from "../lib/Base64.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flask Session Verify operation
|
||||||
|
*/
|
||||||
|
class FlaskSessionVerify extends Operation {
|
||||||
|
/**
|
||||||
|
* FlaskSessionVerify constructor
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.name = "Flask Session Verify";
|
||||||
|
this.module = "Crypto";
|
||||||
|
this.description = "Verifies the HMAC signature of a Flask session cookie (itsdangerous) generated.";
|
||||||
|
this.inputType = "string";
|
||||||
|
this.outputType = "JSON";
|
||||||
|
this.args = [
|
||||||
|
{
|
||||||
|
name: "Key",
|
||||||
|
type: "toggleString",
|
||||||
|
value: "",
|
||||||
|
toggleValues: ["Hex", "Decimal", "Binary", "Base64", "UTF8", "Latin1"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Salt",
|
||||||
|
type: "toggleString",
|
||||||
|
value: "cookie-session",
|
||||||
|
toggleValues: ["UTF8", "Hex", "Decimal", "Binary", "Base64", "Latin1"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Algorithm",
|
||||||
|
type: "option",
|
||||||
|
value: ["sha1", "sha256"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "View TimeStamp",
|
||||||
|
type: "boolean",
|
||||||
|
value: true
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
run(input, args) {
|
||||||
|
|
||||||
|
if (!args[0].string) {
|
||||||
|
throw new OperationError("Secret key required");
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = Utils.convertToByteString(args[0].string, args[0].option);
|
||||||
|
const salt = Utils.convertToByteString(args[1].string || "cookie-session", args[1].option);
|
||||||
|
const algorithm = args[2] || "sha1";
|
||||||
|
|
||||||
|
input = input.trim();
|
||||||
|
|
||||||
|
const parts = input.split(".");
|
||||||
|
|
||||||
|
if (parts.length !== 3) {
|
||||||
|
throw new OperationError("Invalid Flask token format. Expected payload.timestamp.signature");
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = Utils.convertToByteString(parts[0] + "." + parts[1], "utf8");
|
||||||
|
|
||||||
|
|
||||||
|
const derivedKey = CryptoApi.getHmac(key, CryptoApi.getHasher(algorithm));
|
||||||
|
derivedKey.update(salt);
|
||||||
|
|
||||||
|
const sign = CryptoApi.getHmac(derivedKey.finalize(), CryptoApi.getHasher(algorithm));
|
||||||
|
sign.update(data);
|
||||||
|
|
||||||
|
const payloadB64 = parts[0];
|
||||||
|
const base64 = payloadB64.replace(/-/g, "+").replace(/_/g, "/");
|
||||||
|
const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
|
||||||
|
|
||||||
|
const time = parts[1];
|
||||||
|
|
||||||
|
const timeB64 = time.replace(/-/g, "+").replace(/_/g, "/");
|
||||||
|
const binary = fromBase64(timeB64);
|
||||||
|
const bytes = new Uint8Array(4);
|
||||||
|
for (let i = 0; i < 4; i++) {
|
||||||
|
bytes[i] = binary.charCodeAt(i);
|
||||||
|
}
|
||||||
|
const view = new DataView(bytes.buffer);
|
||||||
|
const timestamp = view.getInt32(0, false);
|
||||||
|
|
||||||
|
let payloadJson;
|
||||||
|
try {
|
||||||
|
payloadJson = fromBase64(padded);
|
||||||
|
} catch (e) {
|
||||||
|
throw new OperationError("Invalid Base64 payload");
|
||||||
|
}
|
||||||
|
|
||||||
|
const signB64 = toBase64(sign.finalize());
|
||||||
|
const sign64 = signB64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
||||||
|
|
||||||
|
if (sign64 !== parts[2]) {
|
||||||
|
throw new OperationError("Invalid signature!");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const decoded = JSON.parse(payloadJson);
|
||||||
|
if (!args[3]) {
|
||||||
|
return {
|
||||||
|
valid: true,
|
||||||
|
payload: decoded,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
valid: true,
|
||||||
|
payload: decoded,
|
||||||
|
timestamp: timestamp
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
throw new OperationError("Unable to decode JSON payload: " + e.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default FlaskSessionVerify;
|
||||||
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
import OperationError from "../errors/OperationError.mjs";
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
import jq from "jq-web";
|
import * as jq from "jq-wasm";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* jq operation
|
* jq operation
|
||||||
@ -40,16 +40,15 @@ class Jq extends Operation {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
|
return (async () => {
|
||||||
const [query] = args;
|
const [query] = args;
|
||||||
let result;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = jq.json(input, query);
|
const result = await jq.json(input, query);
|
||||||
|
return JSON.stringify(result);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new OperationError(`Invalid jq expression: ${err.message}`);
|
throw new OperationError(`Invalid jq expression: ${err.message}`);
|
||||||
}
|
}
|
||||||
|
})();
|
||||||
return JSON.stringify(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
164
src/core/operations/PseudoRandomIntegerGenerator.mjs
Normal file
164
src/core/operations/PseudoRandomIntegerGenerator.mjs
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
/**
|
||||||
|
* @author cktgh [chankaitung@gmail.com]
|
||||||
|
* @copyright Crown Copyright 2026
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Operation from "../Operation.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
|
import forge from "node-forge";
|
||||||
|
import Utils, { isWorkerEnvironment } from "../Utils.mjs";
|
||||||
|
import { DELIM_OPTIONS } from "../lib/Delim.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pseudo-Random Integer Generator operation
|
||||||
|
*/
|
||||||
|
class PseudoRandomIntegerGenerator extends Operation {
|
||||||
|
|
||||||
|
// in theory 2**53 is the max range, but we use Number.MAX_SAFE_INTEGER (2**53 - 1) as it is more consistent.
|
||||||
|
static MAX_RANGE = Number.MAX_SAFE_INTEGER;
|
||||||
|
// arbitrary choice
|
||||||
|
static BUFFER_SIZE = 1024;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PseudoRandomIntegerGenerator constructor
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.name = "Pseudo-Random Integer Generator";
|
||||||
|
this.module = "Ciphers";
|
||||||
|
this.description = "A cryptographically-secure pseudo-random number generator (PRNG).<br><br>Generates random integers within a specified range using the browser's built-in <code>crypto.getRandomValues()</code> method if available.<br><br>The supported range of integers is from <code>-(2^53 - 1)</code> to <code>(2^53 - 1)</code>.";
|
||||||
|
this.infoURL = "https://wikipedia.org/wiki/Pseudorandom_number_generator";
|
||||||
|
this.inputType = "string";
|
||||||
|
this.outputType = "string";
|
||||||
|
this.args = [
|
||||||
|
{
|
||||||
|
"name": "Number of Integers",
|
||||||
|
"type": "number",
|
||||||
|
"value": 1,
|
||||||
|
"min": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Min Value",
|
||||||
|
"type": "number",
|
||||||
|
"value": 0,
|
||||||
|
"min": Number.MIN_SAFE_INTEGER,
|
||||||
|
"max": Number.MAX_SAFE_INTEGER
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Max Value",
|
||||||
|
"type": "number",
|
||||||
|
"value": 99,
|
||||||
|
"min": Number.MIN_SAFE_INTEGER,
|
||||||
|
"max": Number.MAX_SAFE_INTEGER
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Delimiter",
|
||||||
|
"type": "option",
|
||||||
|
"value": DELIM_OPTIONS
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Output",
|
||||||
|
"type": "option",
|
||||||
|
"value": ["Raw", "Hex", "Decimal"]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
// not using BigUint64Array to avoid BigInt handling overhead
|
||||||
|
this.randomBuffer = new Uint32Array(PseudoRandomIntegerGenerator.BUFFER_SIZE);
|
||||||
|
this.randomBufferOffset = PseudoRandomIntegerGenerator.BUFFER_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
run(input, args) {
|
||||||
|
const [numInts, minInt, maxInt, delimiter, outputType] = args;
|
||||||
|
|
||||||
|
if (minInt === null || maxInt === null) return "";
|
||||||
|
|
||||||
|
const min = Math.ceil(minInt);
|
||||||
|
const max = Math.floor(maxInt);
|
||||||
|
const delim = Utils.charRep(delimiter || "Space");
|
||||||
|
|
||||||
|
if (!Number.isSafeInteger(min) || !Number.isSafeInteger(max)) {
|
||||||
|
throw new OperationError("Min and Max must be between `-(2^53 - 1)` and `2^53 - 1`.");
|
||||||
|
}
|
||||||
|
if (min > max) {
|
||||||
|
throw new OperationError("Min cannot be larger than Max.");
|
||||||
|
}
|
||||||
|
const range = max - min + 1; // inclusive range
|
||||||
|
if (range > PseudoRandomIntegerGenerator.MAX_RANGE) {
|
||||||
|
throw new OperationError("Range between Min and Max cannot be larger than `2^53`");
|
||||||
|
}
|
||||||
|
|
||||||
|
// as large as possible while divisible by range
|
||||||
|
const rejectionThreshold = PseudoRandomIntegerGenerator.MAX_RANGE - (PseudoRandomIntegerGenerator.MAX_RANGE % range);
|
||||||
|
const output = [];
|
||||||
|
for (let i = 0; i < numInts; i++) {
|
||||||
|
const result = this._generateRandomValue(rejectionThreshold);
|
||||||
|
const intValue = min + (result % range);
|
||||||
|
|
||||||
|
switch (outputType) {
|
||||||
|
case "Hex":
|
||||||
|
output.push(intValue.toString(16));
|
||||||
|
break;
|
||||||
|
case "Decimal":
|
||||||
|
output.push(intValue.toString(10));
|
||||||
|
break;
|
||||||
|
case "Raw":
|
||||||
|
default:
|
||||||
|
output.push(Utils.chr(intValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outputType === "Raw") {
|
||||||
|
return output.join("");
|
||||||
|
}
|
||||||
|
return output.join(delim);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random value, result will be less than the rejection threshold (exclusive).
|
||||||
|
*
|
||||||
|
* @param {number} rejectionThreshold
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
_generateRandomValue(rejectionThreshold) {
|
||||||
|
let result;
|
||||||
|
do {
|
||||||
|
if (this.randomBufferOffset + 2 > this.randomBuffer.length) {
|
||||||
|
this._resetRandomBuffer();
|
||||||
|
}
|
||||||
|
// stitching a 53 bit number; not using BigUint64Array to avoid BigInt handling overhead
|
||||||
|
result = (this.randomBuffer[this.randomBufferOffset++] & 0x1f_ffff) * 0x1_0000_0000 +
|
||||||
|
this.randomBuffer[this.randomBufferOffset++];
|
||||||
|
} while (result >= rejectionThreshold);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fill random buffer with new random values and rseet the offset.
|
||||||
|
*/
|
||||||
|
_resetRandomBuffer() {
|
||||||
|
if (isWorkerEnvironment() && self.crypto) {
|
||||||
|
self.crypto.getRandomValues(this.randomBuffer);
|
||||||
|
} else {
|
||||||
|
const bytes = forge.random.getBytesSync(this.randomBuffer.length * 4);
|
||||||
|
for (let j = 0; j < this.randomBuffer.length; j++) {
|
||||||
|
this.randomBuffer[j] = (bytes.charCodeAt(j * 4) << 24) |
|
||||||
|
(bytes.charCodeAt(j * 4 + 1) << 16) |
|
||||||
|
(bytes.charCodeAt(j * 4 + 2) << 8) |
|
||||||
|
bytes.charCodeAt(j * 4 + 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.randomBufferOffset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PseudoRandomIntegerGenerator;
|
||||||
119
src/core/operations/RC6Decrypt.mjs
Normal file
119
src/core/operations/RC6Decrypt.mjs
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
/**
|
||||||
|
* @author Medjedtxm
|
||||||
|
* @copyright Crown Copyright 2026
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Operation from "../Operation.mjs";
|
||||||
|
import Utils from "../Utils.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
|
import { toHex } from "../lib/Hex.mjs";
|
||||||
|
import { decryptRC6, getBlockSize, getDefaultRounds } from "../lib/RC6.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RC6 Decrypt operation
|
||||||
|
*/
|
||||||
|
class RC6Decrypt extends Operation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RC6Decrypt constructor
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.name = "RC6 Decrypt";
|
||||||
|
this.module = "Ciphers";
|
||||||
|
this.description = "RC6 is a symmetric key block cipher derived from RC5. It was designed by Ron Rivest, Matt Robshaw, Ray Sidney, and Yiqun Lisa Yin to meet the requirements of the AES competition, and was one of the five finalists.<br><br>RC6 is parameterised as RC6-w/r/b where w is word size in bits (any multiple of 8 from 8-256), r is the number of rounds (1-255), and b is the key length in bytes. The standard AES submission uses w=32, r=20. Common word sizes: 8, 16, 32 (standard), 64, 128.<br><br><b>IV:</b> The Initialisation Vector should be 4*w/8 bytes (e.g. 16 bytes for w=32). If not entered, it will default to null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, the PKCS#7 padding scheme is used.";
|
||||||
|
this.infoURL = "https://wikipedia.org/wiki/RC6";
|
||||||
|
this.inputType = "string";
|
||||||
|
this.outputType = "string";
|
||||||
|
this.args = [
|
||||||
|
{
|
||||||
|
"name": "Key",
|
||||||
|
"type": "toggleString",
|
||||||
|
"value": "",
|
||||||
|
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "IV",
|
||||||
|
"type": "toggleString",
|
||||||
|
"value": "",
|
||||||
|
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Mode",
|
||||||
|
"type": "option",
|
||||||
|
"value": ["CBC", "CFB", "OFB", "CTR", "ECB"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Input",
|
||||||
|
"type": "option",
|
||||||
|
"value": ["Hex", "Raw"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Output",
|
||||||
|
"type": "option",
|
||||||
|
"value": ["Raw", "Hex"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Padding",
|
||||||
|
"type": "option",
|
||||||
|
"value": ["PKCS5", "NO", "ZERO", "RANDOM", "BIT"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Word Size",
|
||||||
|
"type": "number",
|
||||||
|
"value": 32,
|
||||||
|
"min": 8,
|
||||||
|
"max": 256,
|
||||||
|
"step": 8
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Rounds",
|
||||||
|
"type": "number",
|
||||||
|
"value": 20,
|
||||||
|
"min": 1,
|
||||||
|
"max": 255
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
run(input, args) {
|
||||||
|
const key = Utils.convertToByteArray(args[0].string, args[0].option),
|
||||||
|
iv = Utils.convertToByteArray(args[1].string, args[1].option),
|
||||||
|
[,, mode, inputType, outputType, padding, wordSize, rounds] = args;
|
||||||
|
|
||||||
|
// Validate word size
|
||||||
|
if (!Number.isInteger(wordSize) || wordSize < 8 || wordSize > 256 || wordSize % 8 !== 0)
|
||||||
|
throw new OperationError(`Invalid word size: ${wordSize}. Must be a multiple of 8 between 8 and 256.`);
|
||||||
|
|
||||||
|
const blockSize = getBlockSize(wordSize);
|
||||||
|
const defaultRounds = getDefaultRounds(wordSize);
|
||||||
|
|
||||||
|
if (iv.length !== blockSize && iv.length !== 0 && mode !== "ECB")
|
||||||
|
throw new OperationError(`Invalid IV length: ${iv.length} bytes
|
||||||
|
|
||||||
|
RC6-${wordSize} uses an IV length of ${blockSize} bytes (${blockSize * 8} bits).
|
||||||
|
Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
|
||||||
|
|
||||||
|
if (!Number.isInteger(rounds) || rounds < 1 || rounds > 255)
|
||||||
|
throw new OperationError(`Invalid number of rounds: ${rounds}
|
||||||
|
|
||||||
|
Rounds must be an integer between 1 and 255. Standard for w=${wordSize} is ${defaultRounds}.`);
|
||||||
|
|
||||||
|
// Default IV to null bytes if empty (like AES)
|
||||||
|
const actualIv = iv.length === 0 ? new Array(blockSize).fill(0) : iv;
|
||||||
|
|
||||||
|
input = Utils.convertToByteArray(input, inputType);
|
||||||
|
const output = decryptRC6(input, key, actualIv, mode, padding, rounds, wordSize);
|
||||||
|
return outputType === "Hex" ? toHex(output, "") : Utils.byteArrayToUtf8(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RC6Decrypt;
|
||||||
119
src/core/operations/RC6Encrypt.mjs
Normal file
119
src/core/operations/RC6Encrypt.mjs
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
/**
|
||||||
|
* @author Medjedtxm
|
||||||
|
* @copyright Crown Copyright 2026
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Operation from "../Operation.mjs";
|
||||||
|
import Utils from "../Utils.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
|
import { toHex } from "../lib/Hex.mjs";
|
||||||
|
import { encryptRC6, getBlockSize, getDefaultRounds } from "../lib/RC6.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RC6 Encrypt operation
|
||||||
|
*/
|
||||||
|
class RC6Encrypt extends Operation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RC6Encrypt constructor
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.name = "RC6 Encrypt";
|
||||||
|
this.module = "Ciphers";
|
||||||
|
this.description = "RC6 is a symmetric key block cipher derived from RC5. It was designed by Ron Rivest, Matt Robshaw, Ray Sidney, and Yiqun Lisa Yin to meet the requirements of the AES competition, and was one of the five finalists.<br><br>RC6 is parameterised as RC6-w/r/b where w is word size in bits (any multiple of 8 from 8-256), r is the number of rounds (1-255), and b is the key length in bytes. The standard AES submission uses w=32, r=20. Common word sizes: 8, 16, 32 (standard), 64, 128.<br><br><b>IV:</b> The Initialisation Vector should be 4*w/8 bytes (e.g. 16 bytes for w=32). If not entered, it will default to null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, the PKCS#7 padding scheme is used.";
|
||||||
|
this.infoURL = "https://wikipedia.org/wiki/RC6";
|
||||||
|
this.inputType = "string";
|
||||||
|
this.outputType = "string";
|
||||||
|
this.args = [
|
||||||
|
{
|
||||||
|
"name": "Key",
|
||||||
|
"type": "toggleString",
|
||||||
|
"value": "",
|
||||||
|
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "IV",
|
||||||
|
"type": "toggleString",
|
||||||
|
"value": "",
|
||||||
|
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Mode",
|
||||||
|
"type": "option",
|
||||||
|
"value": ["CBC", "CFB", "OFB", "CTR", "ECB"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Input",
|
||||||
|
"type": "option",
|
||||||
|
"value": ["Raw", "Hex"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Output",
|
||||||
|
"type": "option",
|
||||||
|
"value": ["Hex", "Raw"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Padding",
|
||||||
|
"type": "option",
|
||||||
|
"value": ["PKCS5", "NO", "ZERO", "RANDOM", "BIT"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Word Size",
|
||||||
|
"type": "number",
|
||||||
|
"value": 32,
|
||||||
|
"min": 8,
|
||||||
|
"max": 256,
|
||||||
|
"step": 8
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Rounds",
|
||||||
|
"type": "number",
|
||||||
|
"value": 20,
|
||||||
|
"min": 1,
|
||||||
|
"max": 255
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
run(input, args) {
|
||||||
|
const key = Utils.convertToByteArray(args[0].string, args[0].option),
|
||||||
|
iv = Utils.convertToByteArray(args[1].string, args[1].option),
|
||||||
|
[,, mode, inputType, outputType, padding, wordSize, rounds] = args;
|
||||||
|
|
||||||
|
// Validate word size
|
||||||
|
if (!Number.isInteger(wordSize) || wordSize < 8 || wordSize > 256 || wordSize % 8 !== 0)
|
||||||
|
throw new OperationError(`Invalid word size: ${wordSize}. Must be a multiple of 8 between 8 and 256.`);
|
||||||
|
|
||||||
|
const blockSize = getBlockSize(wordSize);
|
||||||
|
const defaultRounds = getDefaultRounds(wordSize);
|
||||||
|
|
||||||
|
if (iv.length !== blockSize && iv.length !== 0 && mode !== "ECB")
|
||||||
|
throw new OperationError(`Invalid IV length: ${iv.length} bytes
|
||||||
|
|
||||||
|
RC6-${wordSize} uses an IV length of ${blockSize} bytes (${blockSize * 8} bits).
|
||||||
|
Make sure you have specified the type correctly (e.g. Hex vs UTF8).`);
|
||||||
|
|
||||||
|
if (!Number.isInteger(rounds) || rounds < 1 || rounds > 255)
|
||||||
|
throw new OperationError(`Invalid number of rounds: ${rounds}
|
||||||
|
|
||||||
|
Rounds must be an integer between 1 and 255. Standard for w=${wordSize} is ${defaultRounds}.`);
|
||||||
|
|
||||||
|
// Default IV to null bytes if empty (like AES)
|
||||||
|
const actualIv = iv.length === 0 ? new Array(blockSize).fill(0) : iv;
|
||||||
|
|
||||||
|
input = Utils.convertToByteArray(input, inputType);
|
||||||
|
const output = encryptRC6(input, key, actualIv, mode, padding, rounds, wordSize);
|
||||||
|
return outputType === "Hex" ? toHex(output, "") : Utils.byteArrayToUtf8(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RC6Encrypt;
|
||||||
@ -3,8 +3,7 @@
|
|||||||
* @copyright Crown Copyright 2016
|
* @copyright Crown Copyright 2016
|
||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
import { format } from "sql-formatter";
|
||||||
import vkbeautify from "vkbeautify";
|
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,7 +38,26 @@ class SQLBeautify extends Operation {
|
|||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const indentStr = args[0];
|
const indentStr = args[0];
|
||||||
return vkbeautify.sql(input, indentStr);
|
// Extract and replace bind variables like :Bind1 with __BIND_0__
|
||||||
|
const bindRegex = /:\w+/g;
|
||||||
|
const bindMap = {};
|
||||||
|
let bindCounter=0;
|
||||||
|
const placeholderInput = input.replace(bindRegex, (match) => {
|
||||||
|
const placeholder = `__BIND_${bindCounter++}__`;
|
||||||
|
bindMap[placeholder] = match;
|
||||||
|
return placeholder;
|
||||||
|
});
|
||||||
|
// Format the SQL with chosen options
|
||||||
|
let formatted= format(placeholderInput, {
|
||||||
|
language: "mysql", // Use MySQL as the default dialect for better compatibility with real-world SQL
|
||||||
|
useTabs: indentStr==="\t", // true if tab, false if spaces
|
||||||
|
tabWidth: indentStr.length || 4, // fallback if empty
|
||||||
|
indentStyle: "standard" // fine for most SQL
|
||||||
|
});
|
||||||
|
// Replace placeholders back with original bind variables
|
||||||
|
formatted = formatted.replace(/__BIND_\d+__/g, match => bindMap[match] || match);
|
||||||
|
|
||||||
|
return formatted;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
123
src/core/operations/TextIntegerConverter.mjs
Normal file
123
src/core/operations/TextIntegerConverter.mjs
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
/**
|
||||||
|
* @author p-leriche [philip.leriche@cantab.net]
|
||||||
|
* @copyright Crown Copyright 2025
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Operation from "../Operation.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
|
|
||||||
|
/* ---------- helper functions ---------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert text to BigInt (big-endian byte interpretation)
|
||||||
|
*/
|
||||||
|
function textToBigInt(text) {
|
||||||
|
if (text.length === 0) return 0n;
|
||||||
|
|
||||||
|
let result = 0n;
|
||||||
|
for (let i = 0; i < text.length; i++) {
|
||||||
|
const charCode = BigInt(text.charCodeAt(i));
|
||||||
|
if (charCode > 255n) {
|
||||||
|
throw new OperationError(
|
||||||
|
`Character at position ${i} exceeds Latin-1 range (0-255).\n` +
|
||||||
|
"Only ASCII and Latin-1 characters are supported.");
|
||||||
|
}
|
||||||
|
result = (result << 8n) | charCode;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert BigInt to text (big-endian byte interpretation)
|
||||||
|
*/
|
||||||
|
function bigIntToText(value) {
|
||||||
|
if (value === 0n) return "";
|
||||||
|
|
||||||
|
const bytes = [];
|
||||||
|
let num = value;
|
||||||
|
|
||||||
|
while (num > 0n) {
|
||||||
|
bytes.unshift(Number(num & 0xFFn));
|
||||||
|
num >>= 8n;
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.fromCharCode(...bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------- operation class ---------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text/Integer Converter operation
|
||||||
|
*/
|
||||||
|
class TextIntegerConverter extends Operation {
|
||||||
|
/**
|
||||||
|
* TextIntegerConverter constructor
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.description =
|
||||||
|
"Converts between text strings and large integers (decimal or hexadecimal).<br><br>" +
|
||||||
|
"Text is interpreted as a big-endian sequence of character codes. For example:<br>" +
|
||||||
|
"ABC is 0x414243 (hex) is 4276803 (decimal)<br>" +
|
||||||
|
"<b>Input format detection:</b><br>" +
|
||||||
|
"Decimal: digits 0-9 only<br>" +
|
||||||
|
"Hexadecimal: 0x... prefix<br>" +
|
||||||
|
"Quoted or unquoted text: treated as string<br><br>" +
|
||||||
|
"<b>Character limitations:</b><br>" +
|
||||||
|
"Text input may only contain ASCII and Latin-1 characters (code point < 256).<br>" +
|
||||||
|
"Multi-byte Unicode characters will generate an error.<br><br>." ;
|
||||||
|
this.infoURL = "https://wikipedia.org/wiki/Endianness";
|
||||||
|
this.inputType = "string";
|
||||||
|
this.outputType = "string";
|
||||||
|
this.args = [
|
||||||
|
{
|
||||||
|
name: "Output format",
|
||||||
|
type: "option",
|
||||||
|
value: ["String", "Decimal", "Hexadecimal"]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
this.name = "Text-Integer Conversion";
|
||||||
|
this.module = "Default";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
run(input, args) {
|
||||||
|
const outputFormat = args[0];
|
||||||
|
const trimmed = input.trim();
|
||||||
|
|
||||||
|
let bigIntValue;
|
||||||
|
|
||||||
|
if (!trimmed) {
|
||||||
|
// Null input - treat as zero
|
||||||
|
bigIntValue = 0;
|
||||||
|
} else if (/^0x[0-9a-f]+$/i.test(trimmed) ||
|
||||||
|
/^[+-]?[0-9]+$/.test(trimmed)) {
|
||||||
|
// Hex or decimal integer
|
||||||
|
bigIntValue = BigInt(trimmed);
|
||||||
|
} else if (/^["'].*["']$/.test(trimmed)) {
|
||||||
|
// Quoted string: Remove quotes and convert text to BigInt
|
||||||
|
const text = trimmed.slice(1, -1);
|
||||||
|
bigIntValue = textToBigInt(text);
|
||||||
|
} else {
|
||||||
|
// Assume it's unquoted text
|
||||||
|
bigIntValue = textToBigInt(trimmed);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert to output format
|
||||||
|
if (outputFormat === "String") {
|
||||||
|
return bigIntToText(bigIntValue);
|
||||||
|
} else if (outputFormat === "Decimal") {
|
||||||
|
return bigIntValue.toString();
|
||||||
|
} else { // Hexadecimal
|
||||||
|
return "0x" + bigIntValue.toString(16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TextIntegerConverter;
|
||||||
@ -49,15 +49,14 @@ class HTMLIngredient {
|
|||||||
toHtml() {
|
toHtml() {
|
||||||
let html = "",
|
let html = "",
|
||||||
i, m, eventFn;
|
i, m, eventFn;
|
||||||
|
const hintHtml = this.hint ? `data-toggle="tooltip" title="${this.hint}"` : "";
|
||||||
|
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
case "string":
|
case "string":
|
||||||
case "binaryString":
|
case "binaryString":
|
||||||
case "byteArray":
|
case "byteArray":
|
||||||
html += `<div class="form-group ing-wide">
|
html += `<div class="form-group ing-wide" ${hintHtml}>
|
||||||
<label for="${this.id}"
|
<label for="${this.id}" class="bmd-label-floating">${this.name}</label>
|
||||||
${this.hint ? `data-toggle="tooltip" title="${this.hint}"` : ""}
|
|
||||||
class="bmd-label-floating">${this.name}</label>
|
|
||||||
<input type="text"
|
<input type="text"
|
||||||
class="form-control arg"
|
class="form-control arg"
|
||||||
id="${this.id}"
|
id="${this.id}"
|
||||||
@ -70,10 +69,8 @@ class HTMLIngredient {
|
|||||||
break;
|
break;
|
||||||
case "shortString":
|
case "shortString":
|
||||||
case "binaryShortString":
|
case "binaryShortString":
|
||||||
html += `<div class="form-group ing-short">
|
html += `<div class="form-group ing-short" ${hintHtml}>
|
||||||
<label for="${this.id}"
|
<label for="${this.id}" class="bmd-label-floating inline">${this.name}</label>
|
||||||
${this.hint ? `data-toggle="tooltip" title="${this.hint}"` : ""}
|
|
||||||
class="bmd-label-floating inline">${this.name}</label>
|
|
||||||
<input type="text"
|
<input type="text"
|
||||||
class="form-control arg inline"
|
class="form-control arg inline"
|
||||||
id="${this.id}"
|
id="${this.id}"
|
||||||
@ -85,11 +82,9 @@ class HTMLIngredient {
|
|||||||
</div>`;
|
</div>`;
|
||||||
break;
|
break;
|
||||||
case "toggleString":
|
case "toggleString":
|
||||||
html += `<div class="form-group input-group ing-wide" data-help-title="Multi-type ingredients" data-help="Selecting a data type from the dropdown will change how the ingredient is interpreted by the operation.">
|
html += `<div class="form-group input-group ing-wide" data-help-title="Multi-type ingredients" data-help="Selecting a data type from the dropdown will change how the ingredient is interpreted by the operation." ${hintHtml}>
|
||||||
<div class="toggle-string">
|
<div class="toggle-string">
|
||||||
<label for="${this.id}"
|
<label for="${this.id}" class="bmd-label-floating toggle-string">${this.name}</label>
|
||||||
${this.hint ? `data-toggle="tooltip" title="${this.hint}"` : ""}
|
|
||||||
class="bmd-label-floating toggle-string">${this.name}</label>
|
|
||||||
<input type="text"
|
<input type="text"
|
||||||
class="form-control arg toggle-string"
|
class="form-control arg toggle-string"
|
||||||
id="${this.id}"
|
id="${this.id}"
|
||||||
@ -111,10 +106,8 @@ class HTMLIngredient {
|
|||||||
</div>`;
|
</div>`;
|
||||||
break;
|
break;
|
||||||
case "number":
|
case "number":
|
||||||
html += `<div class="form-group inline ing-medium">
|
html += `<div class="form-group inline ing-medium" ${hintHtml}>
|
||||||
<label for="${this.id}"
|
<label for="${this.id}" class="bmd-label-floating inline">${this.name}</label>
|
||||||
${this.hint ? `data-toggle="tooltip" title="${this.hint}"` : ""}
|
|
||||||
class="bmd-label-floating inline">${this.name}</label>
|
|
||||||
<input type="number"
|
<input type="number"
|
||||||
class="form-control arg inline"
|
class="form-control arg inline"
|
||||||
id="${this.id}"
|
id="${this.id}"
|
||||||
@ -128,9 +121,9 @@ class HTMLIngredient {
|
|||||||
</div>`;
|
</div>`;
|
||||||
break;
|
break;
|
||||||
case "boolean":
|
case "boolean":
|
||||||
html += `<div class="form-group inline boolean-arg ing-flexible">
|
html += `<div class="form-group inline boolean-arg ing-flexible" ${hintHtml}>
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
<label ${this.hint ? `data-toggle="tooltip" title="${this.hint}"` : ""}>
|
<label>
|
||||||
<input type="checkbox"
|
<input type="checkbox"
|
||||||
class="arg"
|
class="arg"
|
||||||
id="${this.id}"
|
id="${this.id}"
|
||||||
@ -144,10 +137,8 @@ class HTMLIngredient {
|
|||||||
</div>`;
|
</div>`;
|
||||||
break;
|
break;
|
||||||
case "option":
|
case "option":
|
||||||
html += `<div class="form-group ing-medium">
|
html += `<div class="form-group ing-medium" ${hintHtml}>
|
||||||
<label for="${this.id}"
|
<label for="${this.id}" class="bmd-label-floating inline">${this.name}</label>
|
||||||
${this.hint ? `data-toggle="tooltip" title="${this.hint}"` : ""}
|
|
||||||
class="bmd-label-floating inline">${this.name}</label>
|
|
||||||
<select
|
<select
|
||||||
class="form-control arg inline"
|
class="form-control arg inline"
|
||||||
id="${this.id}"
|
id="${this.id}"
|
||||||
@ -168,10 +159,8 @@ class HTMLIngredient {
|
|||||||
break;
|
break;
|
||||||
case "populateOption":
|
case "populateOption":
|
||||||
case "populateMultiOption":
|
case "populateMultiOption":
|
||||||
html += `<div class="form-group ing-medium" data-help-title="Population dropdowns" data-help="Selecting a value from this dropdown will populate some of the other ingredients for this operation with pre-canned values.">
|
html += `<div class="form-group ing-medium" data-help-title="Population dropdowns" data-help="Selecting a value from this dropdown will populate some of the other ingredients for this operation with pre-canned values." ${hintHtml}>
|
||||||
<label for="${this.id}"
|
<label for="${this.id}" class="bmd-label-floating">${this.name}</label>
|
||||||
${this.hint ? `data-toggle="tooltip" title="${this.hint}"` : ""}
|
|
||||||
class="bmd-label-floating">${this.name}</label>
|
|
||||||
<select
|
<select
|
||||||
class="form-control arg no-state-change populate-option"
|
class="form-control arg no-state-change populate-option"
|
||||||
id="${this.id}"
|
id="${this.id}"
|
||||||
@ -199,10 +188,8 @@ class HTMLIngredient {
|
|||||||
this.manager.addDynamicListener("#" + this.id, "change", eventFn, this);
|
this.manager.addDynamicListener("#" + this.id, "change", eventFn, this);
|
||||||
break;
|
break;
|
||||||
case "editableOption":
|
case "editableOption":
|
||||||
html += `<div class="form-group input-group ing-wide">
|
html += `<div class="form-group input-group ing-wide" ${hintHtml}>
|
||||||
<label for="${this.id}"
|
<label for="${this.id}" class="bmd-label-floating">${this.name}</label>
|
||||||
${this.hint ? `data-toggle="tooltip" title="${this.hint}"` : ""}
|
|
||||||
class="bmd-label-floating">${this.name}</label>
|
|
||||||
<input type="text"
|
<input type="text"
|
||||||
class="form-control arg"
|
class="form-control arg"
|
||||||
id="${this.id}"
|
id="${this.id}"
|
||||||
@ -230,10 +217,8 @@ class HTMLIngredient {
|
|||||||
this.manager.addDynamicListener(".editable-option-menu a", "click", this.editableOptionClick, this);
|
this.manager.addDynamicListener(".editable-option-menu a", "click", this.editableOptionClick, this);
|
||||||
break;
|
break;
|
||||||
case "editableOptionShort":
|
case "editableOptionShort":
|
||||||
html += `<div class="form-group input-group ing-short">
|
html += `<div class="form-group input-group ing-short" ${hintHtml}>
|
||||||
<label for="${this.id}"
|
<label for="${this.id}" class="bmd-label-floating inline">${this.name}</label>
|
||||||
${this.hint ? `data-toggle="tooltip" title="${this.hint}"` : ""}
|
|
||||||
class="bmd-label-floating inline">${this.name}</label>
|
|
||||||
<input type="text"
|
<input type="text"
|
||||||
class="form-control arg inline"
|
class="form-control arg inline"
|
||||||
id="${this.id}"
|
id="${this.id}"
|
||||||
@ -261,10 +246,8 @@ class HTMLIngredient {
|
|||||||
this.manager.addDynamicListener(".editable-option-menu a", "click", this.editableOptionClick, this);
|
this.manager.addDynamicListener(".editable-option-menu a", "click", this.editableOptionClick, this);
|
||||||
break;
|
break;
|
||||||
case "text":
|
case "text":
|
||||||
html += `<div class="form-group ing-very-wide">
|
html += `<div class="form-group ing-very-wide" ${hintHtml}>
|
||||||
<label for="${this.id}"
|
<label for="${this.id}" class="bmd-label-floating">${this.name}</label>
|
||||||
${this.hint ? `data-toggle="tooltip" title="${this.hint}"` : ""}
|
|
||||||
class="bmd-label-floating">${this.name}</label>
|
|
||||||
<textarea
|
<textarea
|
||||||
class="form-control arg"
|
class="form-control arg"
|
||||||
id="${this.id}"
|
id="${this.id}"
|
||||||
@ -275,10 +258,8 @@ class HTMLIngredient {
|
|||||||
</div>`;
|
</div>`;
|
||||||
break;
|
break;
|
||||||
case "argSelector":
|
case "argSelector":
|
||||||
html += `<div class="form-group inline ing-medium" data-help-title="Ingredient selector" data-help="Selecting options in this dropdown will configure which operation ingredients are visible.">
|
html += `<div class="form-group inline ing-medium" data-help-title="Ingredient selector" data-help="Selecting options in this dropdown will configure which operation ingredients are visible." ${hintHtml}>
|
||||||
<label for="${this.id}"
|
<label for="${this.id}" class="bmd-label-floating inline">${this.name}</label>
|
||||||
${this.hint ? `data-toggle="tooltip" title="${this.hint}"` : ""}
|
|
||||||
class="bmd-label-floating inline">${this.name}</label>
|
|
||||||
<select
|
<select
|
||||||
class="form-control arg inline arg-selector"
|
class="form-control arg inline arg-selector"
|
||||||
id="${this.id}"
|
id="${this.id}"
|
||||||
@ -298,7 +279,7 @@ class HTMLIngredient {
|
|||||||
this.manager.addDynamicListener(".arg-selector", "change", this.argSelectorChange, this);
|
this.manager.addDynamicListener(".arg-selector", "change", this.argSelectorChange, this);
|
||||||
break;
|
break;
|
||||||
case "label":
|
case "label":
|
||||||
html += `<div class="form-group ing-flexible">
|
html += `<div class="form-group ing-flexible" ${hintHtml}>
|
||||||
<label>${this.name}</label>
|
<label>${this.name}</label>
|
||||||
<input type="hidden"
|
<input type="hidden"
|
||||||
class="form-control arg"
|
class="form-control arg"
|
||||||
|
|||||||
@ -249,6 +249,13 @@ optgroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Bootstrap form inside CodeMirror editor */
|
||||||
|
|
||||||
|
.cm-panel > .bmd-form-group {
|
||||||
|
padding-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* CodeMirror */
|
/* CodeMirror */
|
||||||
|
|
||||||
.ͼ2 .cm-specialChar,
|
.ͼ2 .cm-specialChar,
|
||||||
|
|||||||
@ -417,6 +417,8 @@ class RecipeWaiter {
|
|||||||
el.classList.add("flow-control-op");
|
el.classList.add("flow-control-op");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$(el).find("[data-toggle='tooltip']").tooltip();
|
||||||
|
|
||||||
// Disable auto-bake if this is a manual op
|
// Disable auto-bake if this is a manual op
|
||||||
if (op.manualBake && this.app.autoBake_) {
|
if (op.manualBake && this.app.autoBake_) {
|
||||||
this.manager.controls.setAutoBake(false);
|
this.manager.controls.setAutoBake(false);
|
||||||
@ -442,8 +444,6 @@ class RecipeWaiter {
|
|||||||
this.buildRecipeOperation(item);
|
this.buildRecipeOperation(item);
|
||||||
document.getElementById("rec-list").appendChild(item);
|
document.getElementById("rec-list").appendChild(item);
|
||||||
|
|
||||||
$(item).find("[data-toggle='tooltip']").tooltip();
|
|
||||||
|
|
||||||
item.dispatchEvent(this.manager.operationadd);
|
item.dispatchEvent(this.manager.operationadd);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import "./tests/Dish.mjs";
|
|||||||
import "./tests/NodeDish.mjs";
|
import "./tests/NodeDish.mjs";
|
||||||
import "./tests/Utils.mjs";
|
import "./tests/Utils.mjs";
|
||||||
import "./tests/Categories.mjs";
|
import "./tests/Categories.mjs";
|
||||||
|
import "./tests/lib/BigIntUtils.mjs";
|
||||||
|
|
||||||
const testStatus = {
|
const testStatus = {
|
||||||
allTestsPassing: true,
|
allTestsPassing: true,
|
||||||
|
|||||||
150
tests/node/tests/lib/BigIntUtils.mjs
Normal file
150
tests/node/tests/lib/BigIntUtils.mjs
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
import TestRegister from "../../../lib/TestRegister.mjs";
|
||||||
|
import { parseBigInt, egcd, modPow } from "../../../../src/core/lib/BigIntUtils.mjs";
|
||||||
|
import it from "../../assertionHandler.mjs";
|
||||||
|
import assert from "assert";
|
||||||
|
|
||||||
|
TestRegister.addApiTests([
|
||||||
|
// ===== parseBigInt tests =====
|
||||||
|
it("BigIntUtils: parseBigInt - decimal number", () => {
|
||||||
|
const value = parseBigInt("1", "test value");
|
||||||
|
assert.deepStrictEqual(value, BigInt("1"));
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("BigIntUtils: parseBigInt - large decimal", () => {
|
||||||
|
const value = parseBigInt("123456789012345678901234567890", "test value");
|
||||||
|
assert.deepStrictEqual(value, BigInt("123456789012345678901234567890"));
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("BigIntUtils: parseBigInt - hexadecimal lowercase", () => {
|
||||||
|
const value = parseBigInt("0xff", "test value");
|
||||||
|
assert.deepStrictEqual(value, BigInt("255"));
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("BigIntUtils: parseBigInt - hexadecimal uppercase", () => {
|
||||||
|
const value = parseBigInt("0xFF", "test value");
|
||||||
|
assert.deepStrictEqual(value, BigInt("255"));
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("BigIntUtils: parseBigInt - large hexadecimal", () => {
|
||||||
|
const value = parseBigInt("0x123456789ABCDEF", "test value");
|
||||||
|
assert.deepStrictEqual(value, BigInt("0x123456789ABCDEF"));
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("BigIntUtils: parseBigInt - whitespace trimming", () => {
|
||||||
|
const value = parseBigInt(" 42 ", "test value");
|
||||||
|
assert.deepStrictEqual(value, BigInt("42"));
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("BigIntUtils: parseBigInt - invalid input (text)", () => {
|
||||||
|
assert.throws(() => parseBigInt("test", "test value"), {
|
||||||
|
name: "Error",
|
||||||
|
message: "test value must be decimal or hex (0x...)"
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("BigIntUtils: parseBigInt - invalid input (hex without prefix)", () => {
|
||||||
|
assert.throws(() => parseBigInt("FF", "test value"), {
|
||||||
|
name: "Error",
|
||||||
|
message: "test value must be decimal or hex (0x...)"
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("BigIntUtils: parseBigInt - invalid input (mixed)", () => {
|
||||||
|
assert.throws(() => parseBigInt("12abc", "test value"), {
|
||||||
|
name: "Error",
|
||||||
|
message: "test value must be decimal or hex (0x...)"
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
|
||||||
|
// ===== egcd tests =====
|
||||||
|
it("BigIntUtils: egcd - basic coprime", () => {
|
||||||
|
const a = BigInt("36");
|
||||||
|
const b = BigInt("48");
|
||||||
|
const gcd = BigInt("12");
|
||||||
|
const bezout1 = BigInt("-1");
|
||||||
|
const bezout2 = BigInt("1");
|
||||||
|
assert.deepStrictEqual(egcd(a, b), [gcd, bezout1, bezout2]);
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("BigIntUtils: egcd - coprime numbers", () => {
|
||||||
|
const [g, x, y] = egcd(BigInt("3"), BigInt("11"));
|
||||||
|
assert.strictEqual(g, BigInt("1"));
|
||||||
|
// Verify Bézout identity: a*x + b*y = gcd
|
||||||
|
assert.strictEqual(BigInt("3") * x + BigInt("11") * y, g);
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("BigIntUtils: egcd - non-coprime numbers", () => {
|
||||||
|
const [g, x, y] = egcd(BigInt("240"), BigInt("46"));
|
||||||
|
assert.strictEqual(g, BigInt("2"));
|
||||||
|
// Verify Bézout identity
|
||||||
|
assert.strictEqual(BigInt("240") * x + BigInt("46") * y, g);
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("BigIntUtils: egcd - with zero", () => {
|
||||||
|
const [g, x, y] = egcd(BigInt("17"), BigInt("0"));
|
||||||
|
assert.strictEqual(g, BigInt("17"));
|
||||||
|
assert.strictEqual(x, BigInt("1"));
|
||||||
|
assert.strictEqual(y, BigInt("0"));
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("BigIntUtils: egcd - identical numbers", () => {
|
||||||
|
const [g, x, y] = egcd(BigInt("42"), BigInt("42"));
|
||||||
|
assert.strictEqual(g, BigInt("42"));
|
||||||
|
// Verify Bézout identity
|
||||||
|
assert.strictEqual(BigInt("42") * x + BigInt("42") * y, g);
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("BigIntUtils: egcd - large numbers", () => {
|
||||||
|
const a = BigInt("123456789012345678901234567890");
|
||||||
|
const b = BigInt("987654321098765432109876543210");
|
||||||
|
const [g, x, y] = egcd(a, b);
|
||||||
|
// Verify Bézout identity
|
||||||
|
assert.strictEqual(a * x + b * y, g);
|
||||||
|
}),
|
||||||
|
|
||||||
|
// ===== modPow tests =====
|
||||||
|
it("BigIntUtils: modPow - basic", () => {
|
||||||
|
// 2^10 mod 1000 = 1024 mod 1000 = 24
|
||||||
|
const result = modPow(BigInt("2"), BigInt("10"), BigInt("1000"));
|
||||||
|
assert.strictEqual(result, BigInt("24"));
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("BigIntUtils: modPow - RSA-like example", () => {
|
||||||
|
// Common RSA public exponent
|
||||||
|
const base = BigInt("123456789");
|
||||||
|
const exp = BigInt("65537");
|
||||||
|
const mod = BigInt("999999999999");
|
||||||
|
const result = modPow(base, exp, mod);
|
||||||
|
// Result should be less than modulus
|
||||||
|
assert(result < mod);
|
||||||
|
assert(result >= BigInt("0"));
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("BigIntUtils: modPow - exponent zero", () => {
|
||||||
|
// Any number^0 = 1
|
||||||
|
const result = modPow(BigInt("999"), BigInt("0"), BigInt("100"));
|
||||||
|
assert.strictEqual(result, BigInt("1"));
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("BigIntUtils: modPow - base zero", () => {
|
||||||
|
// 0^n = 0
|
||||||
|
const result = modPow(BigInt("0"), BigInt("5"), BigInt("100"));
|
||||||
|
assert.strictEqual(result, BigInt("0"));
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("BigIntUtils: modPow - large exponent", () => {
|
||||||
|
// Test with very large exponent (efficient algorithm should handle this)
|
||||||
|
const result = modPow(BigInt("3"), BigInt("1000000"), BigInt("1000000007"));
|
||||||
|
assert(result >= BigInt("0"));
|
||||||
|
assert(result < BigInt("1000000007"));
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("BigIntUtils: modPow - modular inverse verification", () => {
|
||||||
|
// If a*x . 1 (mod m), then modPow(a, 1, m) * x . 1 (mod m)
|
||||||
|
const a = BigInt("3");
|
||||||
|
const m = BigInt("11");
|
||||||
|
const x = BigInt("4"); // inverse of 3 mod 11
|
||||||
|
const result = modPow(a, BigInt("1"), m) * x % m;
|
||||||
|
assert.strictEqual(result, BigInt("1"));
|
||||||
|
}),
|
||||||
|
]);
|
||||||
@ -867,13 +867,15 @@ pCGTErs=
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
it("SQL Beautify", () => {
|
it("SQL Beautify", () => {
|
||||||
const result = chef.SQLBeautify(`SELECT MONTH, ID, RAIN_I, TEMP_F
|
const result = chef.SQLBeautify(`SELECT MONTH, ID, RAIN_I, TEMP_F FROM STATS;`);
|
||||||
FROM STATS;`);
|
const expected =
|
||||||
const expected = `SELECT MONTH,
|
`SELECT
|
||||||
|
MONTH,
|
||||||
ID,
|
ID,
|
||||||
RAIN_I,
|
RAIN_I,
|
||||||
TEMP_F
|
TEMP_F
|
||||||
FROM STATS;`;
|
FROM
|
||||||
|
STATS;`;
|
||||||
assert.strictEqual(result.toString(), expected);
|
assert.strictEqual(result.toString(), expected);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|||||||
@ -61,6 +61,7 @@ import "./tests/Crypt.mjs";
|
|||||||
import "./tests/CSV.mjs";
|
import "./tests/CSV.mjs";
|
||||||
import "./tests/DateTime.mjs";
|
import "./tests/DateTime.mjs";
|
||||||
import "./tests/DefangIP.mjs";
|
import "./tests/DefangIP.mjs";
|
||||||
|
import "./tests/DisassembleARM.mjs";
|
||||||
import "./tests/DropNthBytes.mjs";
|
import "./tests/DropNthBytes.mjs";
|
||||||
import "./tests/ECDSA.mjs";
|
import "./tests/ECDSA.mjs";
|
||||||
import "./tests/ELFInfo.mjs";
|
import "./tests/ELFInfo.mjs";
|
||||||
@ -152,7 +153,9 @@ import "./tests/Shuffle.mjs";
|
|||||||
import "./tests/SIGABA.mjs";
|
import "./tests/SIGABA.mjs";
|
||||||
import "./tests/SM2.mjs";
|
import "./tests/SM2.mjs";
|
||||||
import "./tests/SM4.mjs";
|
import "./tests/SM4.mjs";
|
||||||
|
import "./tests/RC6.mjs";
|
||||||
// import "./tests/SplitColourChannels.mjs"; // Cannot test operations that use the File type yet
|
// import "./tests/SplitColourChannels.mjs"; // Cannot test operations that use the File type yet
|
||||||
|
import "./tests/SQLBeautify.mjs";
|
||||||
import "./tests/StrUtils.mjs";
|
import "./tests/StrUtils.mjs";
|
||||||
import "./tests/StripIPv4Header.mjs";
|
import "./tests/StripIPv4Header.mjs";
|
||||||
import "./tests/StripTCPHeader.mjs";
|
import "./tests/StripTCPHeader.mjs";
|
||||||
@ -163,6 +166,7 @@ import "./tests/SymmetricDifference.mjs";
|
|||||||
import "./tests/TakeNthBytes.mjs";
|
import "./tests/TakeNthBytes.mjs";
|
||||||
import "./tests/Template.mjs";
|
import "./tests/Template.mjs";
|
||||||
import "./tests/TextEncodingBruteForce.mjs";
|
import "./tests/TextEncodingBruteForce.mjs";
|
||||||
|
import "./tests/TextIntegerConverter.mjs";
|
||||||
import "./tests/ToFromInsensitiveRegex.mjs";
|
import "./tests/ToFromInsensitiveRegex.mjs";
|
||||||
import "./tests/TranslateDateTimeFormat.mjs";
|
import "./tests/TranslateDateTimeFormat.mjs";
|
||||||
import "./tests/Typex.mjs";
|
import "./tests/Typex.mjs";
|
||||||
|
|||||||
377
tests/operations/tests/DisassembleARM.mjs
Normal file
377
tests/operations/tests/DisassembleARM.mjs
Normal file
@ -0,0 +1,377 @@
|
|||||||
|
/**
|
||||||
|
* Disassemble ARM tests.
|
||||||
|
*
|
||||||
|
* @author MedjedThomasXM
|
||||||
|
*
|
||||||
|
* @copyright Crown Copyright 2024
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
import TestRegister from "../../lib/TestRegister.mjs";
|
||||||
|
|
||||||
|
TestRegister.addTests([
|
||||||
|
// ==================== ARM32 TESTS ====================
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM32 NOP (mov r0, r0)",
|
||||||
|
input: "00 00 a0 e1",
|
||||||
|
expectedMatch: /mov\s+r0,\s*r0/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM (32-bit)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM32 bx lr",
|
||||||
|
input: "1e ff 2f e1",
|
||||||
|
expectedMatch: /bx\s+lr/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM (32-bit)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM32 push {fp, lr}",
|
||||||
|
input: "00 48 2d e9",
|
||||||
|
expectedMatch: /push\s+\{fp,\s*lr\}/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM (32-bit)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM32 add fp, sp, #4",
|
||||||
|
input: "04 b0 8d e2",
|
||||||
|
expectedMatch: /add\s+fp,\s*sp/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM (32-bit)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM32 ldr r0, [r1]",
|
||||||
|
input: "00 00 91 e5",
|
||||||
|
expectedMatch: /ldr\s+r0,\s*\[r1\]/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM (32-bit)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM32 str r0, [r1]",
|
||||||
|
input: "00 00 81 e5",
|
||||||
|
expectedMatch: /str\s+r0,\s*\[r1\]/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM (32-bit)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM32 bl (branch link)",
|
||||||
|
input: "00 00 00 eb",
|
||||||
|
expectedMatch: /bl\s+/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM (32-bit)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM32 mul r0, r1, r2",
|
||||||
|
input: "91 02 00 e0",
|
||||||
|
expectedMatch: /mul\s+r0,\s*r1,\s*r2/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM (32-bit)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
// ==================== ARM32 THUMB TESTS ====================
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: Thumb mov r0, r0",
|
||||||
|
input: "00 46",
|
||||||
|
expectedMatch: /mov\s+r0,\s*r0/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM (32-bit)", "Thumb", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: Thumb bx lr",
|
||||||
|
input: "70 47",
|
||||||
|
expectedMatch: /bx\s+lr/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM (32-bit)", "Thumb", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: Thumb push {r4, lr}",
|
||||||
|
input: "10 b5",
|
||||||
|
expectedMatch: /push\s+\{r4,\s*lr\}/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM (32-bit)", "Thumb", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: Thumb pop {r4, pc}",
|
||||||
|
input: "10 bd",
|
||||||
|
expectedMatch: /pop\s+\{r4,\s*pc\}/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM (32-bit)", "Thumb", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
// ==================== ARM64 TESTS ====================
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM64 ret",
|
||||||
|
input: "c0 03 5f d6",
|
||||||
|
expectedMatch: /ret/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM64 (AArch64)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM64 mov x0, #0",
|
||||||
|
input: "00 00 80 d2",
|
||||||
|
expectedMatch: /mov[z]?\s+x0,\s*#0/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM64 (AArch64)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM64 stp x29, x30, [sp, #-16]!",
|
||||||
|
input: "fd 7b bf a9",
|
||||||
|
expectedMatch: /stp\s+x29,\s*x30,\s*\[sp/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM64 (AArch64)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM64 ldp x29, x30, [sp], #16",
|
||||||
|
input: "fd 7b c1 a8",
|
||||||
|
expectedMatch: /ldp\s+x29,\s*x30,\s*\[sp\]/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM64 (AArch64)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM64 add x0, x1, x2",
|
||||||
|
input: "20 00 02 8b",
|
||||||
|
expectedMatch: /add\s+x0,\s*x1,\s*x2/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM64 (AArch64)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM64 sub x0, x1, x2",
|
||||||
|
input: "20 00 02 cb",
|
||||||
|
expectedMatch: /sub\s+x0,\s*x1,\s*x2/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM64 (AArch64)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM64 mul x0, x1, x2",
|
||||||
|
input: "20 7c 02 9b",
|
||||||
|
expectedMatch: /mul\s+x0,\s*x1,\s*x2/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM64 (AArch64)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM64 ldr x0, [x1]",
|
||||||
|
input: "20 00 40 f9",
|
||||||
|
expectedMatch: /ldr\s+x0,\s*\[x1\]/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM64 (AArch64)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM64 str x0, [x1]",
|
||||||
|
input: "20 00 00 f9",
|
||||||
|
expectedMatch: /str\s+x0,\s*\[x1\]/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM64 (AArch64)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM64 bl (branch link)",
|
||||||
|
input: "00 00 00 94",
|
||||||
|
expectedMatch: /bl\s+/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM64 (AArch64)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM64 cbz x0",
|
||||||
|
input: "00 00 00 b4",
|
||||||
|
expectedMatch: /cbz\s+x0/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM64 (AArch64)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM64 cbnz x0",
|
||||||
|
input: "00 00 00 b5",
|
||||||
|
expectedMatch: /cbnz\s+x0/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM64 (AArch64)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM64 sub sp, sp, #0x20",
|
||||||
|
input: "ff 83 00 d1",
|
||||||
|
expectedMatch: /sub\s+sp,\s*sp/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM64 (AArch64)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM64 add sp, sp, #0x20",
|
||||||
|
input: "ff 83 00 91",
|
||||||
|
expectedMatch: /add\s+sp,\s*sp/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM64 (AArch64)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
// ==================== MULTI-INSTRUCTION TESTS ====================
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM32 multiple instructions",
|
||||||
|
input: "00 48 2d e9 04 b0 8d e2 00 00 a0 e1 00 88 bd e8",
|
||||||
|
expectedMatch: /push.*\n.*add.*\n.*mov.*\n.*pop/s,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM (32-bit)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM64 function prologue/epilogue",
|
||||||
|
input: "fd 7b bf a9 fd 03 00 91 00 00 80 52 fd 7b c1 a8 c0 03 5f d6",
|
||||||
|
expectedMatch: /stp.*\n.*mov.*\n.*mov.*\n.*ldp.*\n.*ret/s,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM64 (AArch64)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
// ==================== ADDRESS TESTS ====================
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM64 with start address 0x1000",
|
||||||
|
input: "c0 03 5f d6",
|
||||||
|
expectedMatch: /0x00001000/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM64 (AArch64)", "ARM", "Little Endian", 4096, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM32 with start address 0x8000",
|
||||||
|
input: "00 00 a0 e1",
|
||||||
|
expectedMatch: /0x00008000/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM (32-bit)", "ARM", "Little Endian", 32768, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
// ==================== ENDIANNESS TESTS ====================
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: ARM32 Big Endian",
|
||||||
|
input: "e1 a0 00 00",
|
||||||
|
expectedMatch: /mov\s+r0,\s*r0/,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM (32-bit)", "ARM", "Big Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
// ==================== EDGE CASES ====================
|
||||||
|
{
|
||||||
|
name: "Disassemble ARM: Empty input",
|
||||||
|
input: "",
|
||||||
|
expectedOutput: "",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Disassemble ARM",
|
||||||
|
args: ["ARM64 (AArch64)", "ARM", "Little Endian", 0, true, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
246
tests/operations/tests/FlaskSession.mjs
Normal file
246
tests/operations/tests/FlaskSession.mjs
Normal file
@ -0,0 +1,246 @@
|
|||||||
|
/**
|
||||||
|
* Flask Session tests
|
||||||
|
*
|
||||||
|
* @author ThePlayer372-FR []
|
||||||
|
*
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import TestRegister from "../../lib/TestRegister.mjs";
|
||||||
|
|
||||||
|
const validTokenSha1 = "eyJyb2xlIjoic3VwZXJ1c2VyIiwidXNlciI6ImFkbWluIn0.aZ-KEw.E_x6bOhA4GU9t72pMinJUjN-O3I";
|
||||||
|
const validTokenSha256 = "eyJyb2xlIjoic3VwZXJ1c2VyIiwidXNlciI6ImFkbWluIn0.aab3Ew.Jsx2DOx_H9anZg0YcvhsASxQ11897EFHeQfS2oja4y8";
|
||||||
|
|
||||||
|
const validKey = "mysecretkey";
|
||||||
|
const wrongKey = "notTheKey";
|
||||||
|
|
||||||
|
const outputObject = {
|
||||||
|
user: "admin",
|
||||||
|
role: "superuser",
|
||||||
|
};
|
||||||
|
|
||||||
|
const outputVerify = {
|
||||||
|
valid: true,
|
||||||
|
payload: outputObject,
|
||||||
|
};
|
||||||
|
|
||||||
|
TestRegister.addTests([
|
||||||
|
{
|
||||||
|
name: "Flask Session: Decode",
|
||||||
|
input: validTokenSha1,
|
||||||
|
expectedOutput: outputObject,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Flask Session Decode",
|
||||||
|
args: [
|
||||||
|
false
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Flask Session: Verify Sha1",
|
||||||
|
input: validTokenSha1,
|
||||||
|
expectedOutput: outputVerify,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Flask Session Verify",
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
string: validKey,
|
||||||
|
option: "UTF8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
string: "cookie-session",
|
||||||
|
option: "UTF8"
|
||||||
|
},
|
||||||
|
"sha1",
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Flask Session: Verify Sha256",
|
||||||
|
input: validTokenSha256,
|
||||||
|
expectedOutput: outputVerify,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Flask Session Verify",
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
string: validKey,
|
||||||
|
option: "UTF8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
string: "cookie-session",
|
||||||
|
option: "UTF8"
|
||||||
|
},
|
||||||
|
"sha256",
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Flask Session: Sign Sha1",
|
||||||
|
input: outputObject,
|
||||||
|
expectedOutput: outputVerify,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Flask Session Sign",
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
string: validKey,
|
||||||
|
option: "UTF8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
string: "cookie-session",
|
||||||
|
option: "UTF8"
|
||||||
|
},
|
||||||
|
"sha1"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "Flask Session Verify",
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
string: validKey,
|
||||||
|
option: "UTF8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
string: "cookie-session",
|
||||||
|
option: "UTF8"
|
||||||
|
},
|
||||||
|
"sha1",
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Flask Session: Sign Sha256",
|
||||||
|
input: outputObject,
|
||||||
|
expectedOutput: outputVerify,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Flask Session Sign",
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
string: validKey,
|
||||||
|
option: "UTF8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
string: "cookie-session",
|
||||||
|
option: "UTF8"
|
||||||
|
},
|
||||||
|
"sha256"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "Flask Session Verify",
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
string: validKey,
|
||||||
|
option: "UTF8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
string: "cookie-session",
|
||||||
|
option: "UTF8"
|
||||||
|
},
|
||||||
|
"sha256",
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Flask Session: Verify Sha1 Wrong Key",
|
||||||
|
input: validTokenSha1,
|
||||||
|
expectedOutput: "Invalid signature!",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Flask Session Verify",
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
string: wrongKey,
|
||||||
|
option: "UTF8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
string: "cookie-session",
|
||||||
|
option: "UTF8"
|
||||||
|
},
|
||||||
|
"sha1",
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Flask Session: Verify Sha256 Wrong Key",
|
||||||
|
input: validTokenSha256,
|
||||||
|
expectedOutput: "Invalid signature!",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Flask Session Verify",
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
string: wrongKey,
|
||||||
|
option: "UTF8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
string: "cookie-session",
|
||||||
|
option: "UTF8"
|
||||||
|
},
|
||||||
|
"sha256",
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Flask Session: Verify Sha1 Wrong Salt",
|
||||||
|
input: validTokenSha1,
|
||||||
|
expectedOutput: "Invalid signature!",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Flask Session Verify",
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
string: validKey,
|
||||||
|
option: "UTF8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
string: "notTheSalt",
|
||||||
|
option: "UTF8"
|
||||||
|
},
|
||||||
|
"sha1",
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Flask Session: Verify Sha256 Wrong Salt",
|
||||||
|
input: validTokenSha256,
|
||||||
|
expectedOutput: "Invalid signature!",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Flask Session Verify",
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
string: validKey,
|
||||||
|
option: "UTF8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
string: "notTheSalt",
|
||||||
|
option: "UTF8"
|
||||||
|
},
|
||||||
|
"sha256",
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
]);
|
||||||
@ -15,7 +15,7 @@ const inputObject = JSON.stringify({
|
|||||||
}, null, 4);
|
}, null, 4);
|
||||||
|
|
||||||
const hsKey = "secret_cat";
|
const hsKey = "secret_cat";
|
||||||
const rsKey = `-----BEGIN RSA PRIVATE KEY-----
|
const rsKey1024 = `-----BEGIN RSA PRIVATE KEY-----
|
||||||
MIICWwIBAAKBgQDdlatRjRjogo3WojgGHFHYLugdUWAY9iR3fy4arWNA1KoS8kVw
|
MIICWwIBAAKBgQDdlatRjRjogo3WojgGHFHYLugdUWAY9iR3fy4arWNA1KoS8kVw
|
||||||
33cJibXr8bvwUAUparCwlvdbH6dvEOfou0/gCFQsHUfQrSDv+MuSUMAe8jzKE4qW
|
33cJibXr8bvwUAUparCwlvdbH6dvEOfou0/gCFQsHUfQrSDv+MuSUMAe8jzKE4qW
|
||||||
+jK+xQU9a03GUnKHkkle+Q0pX/g6jXZ7r1/xAK5Do2kQ+X5xK9cipRgEKwIDAQAB
|
+jK+xQU9a03GUnKHkkle+Q0pX/g6jXZ7r1/xAK5Do2kQ+X5xK9cipRgEKwIDAQAB
|
||||||
@ -30,11 +30,52 @@ fSSjAkLRi54PKJ8TFUeOP15h9sQzydI8zJU+upvDEKZsZc/UhT/SySDOxQ4G/523
|
|||||||
Y0sz/OZtSWcol/UMgQJALesy++GdvoIDLfJX5GBQpuFgFenRiRDabxrE9MNUZ2aP
|
Y0sz/OZtSWcol/UMgQJALesy++GdvoIDLfJX5GBQpuFgFenRiRDabxrE9MNUZ2aP
|
||||||
FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==
|
FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==
|
||||||
-----END RSA PRIVATE KEY-----`;
|
-----END RSA PRIVATE KEY-----`;
|
||||||
const esKey = `-----BEGIN PRIVATE KEY-----
|
const rsKey2048 = `-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
MIIEogIBAAKCAQEAk0VOoksAblwP82DALTG6xGC86Hfho3nChbcPGWyqn+ScfHBF
|
||||||
|
cg3SeKyy6aWCyLcKfNwE5cPYzuYvVBsZyIrdfFOuV90D/aRYbuw6UkKR3cmmy9qE
|
||||||
|
qvu05dogvc0BcmkwbC37Q8JnsZBRcosoLGgTFxcK+LXdsG7DukajpsGesxQjOLb2
|
||||||
|
1jnx+ypzx74xvj7grqlXkxeDKr22q7QkO3A1ApoOuJRAU+SjEEZmqdXzRery2RWx
|
||||||
|
hkWbCXuQw4PnW5Lh3Wwabnu7XKVIa6wJa1pqL2IAxmlZ0bvGTfjtO5ggNfgJk5V4
|
||||||
|
bGSOXnsplpG71AWMrK2q6NqHjFIE1szEycUKrwIDAQABAoIBAAivyt6Zy/G2g8kC
|
||||||
|
852hfvcRubLV92eRdAmNGFqTOqaUcS00i3QZyp4MRGqxtOV/88y/nEOtP1RHkZJw
|
||||||
|
HXTjHq4JsDvwhnQR8JbCX6z1zkLQdS01u3jrwJTaPpooxdATfPlfO6CYjqM+SapB
|
||||||
|
o7dS1ZAZb4U8vPx+MWoDEVNxvO7/xyqho1Oc4H9MwqQUiyG2WfIoqxLSrBYcambv
|
||||||
|
RmySwTIpgQZTr61EeWf/0eWpV0iEYbSnkB/VaKW+5tg4gCjPgy5v6/LQ0u/pzlYz
|
||||||
|
ayCL3xN2rp0tigXsiiWz3cM5gDsnatK4nVNRs9y3JSZpWpI236ZfZjs8Lts+WBUw
|
||||||
|
hAEoE9kCgYEAyEIGD1A7R/t5EYk5HhHDH5tGdyxejAcQL5AIz0YnTZU8Iixyc7FR
|
||||||
|
uDmAMiuKIcJY/nUlxZjSxNc3MkOfZNggQvf9ONrt+ftQ1yyTjv+019NfU4w4d0Ep
|
||||||
|
LNaiAHgaPKimBUZjYXbLgiMXj/1pBaQmgUYTK/VlO3PVdowxxzxMYlMCgYEAvEOG
|
||||||
|
GrhVaQV1nAYx86BgZ3wn90hBFXZWGaN+eXUmyrast93Ih3TCSgQDKPuN3pdv/TIe
|
||||||
|
cpQv/BxEMpW+6d5Z1NP3GbrLpaZUiUNk8fqw1S3pmD5aWZrYIUaNukAyOxnZVgjv
|
||||||
|
EWD9QTpI663gODaeZZTkDYiRNzTzGOg5HtzporUCgYBBOphEtqqImNXnq13qeHip
|
||||||
|
O+eo+8/UJpzUEUN9WGmG8NxEeVvSaWin7DrgnKQCuQ5J3Biwk0XcDgoRmks6Ctf/
|
||||||
|
WE2oDk/DxGOhowhxZMMgJd6AFUVzOstRqpvcMULCjWB+iV3nqk1Bl3KeWTmzN7O/
|
||||||
|
Gfc2s1kFE4btdV7lebObtwKBgE3rkLS8eLVYCh6Cvef9CAms7Im/wRhV+zrvXWh9
|
||||||
|
4YljZEdRpy7RV5z03i33N/faLALa3JlF1jp9pIhfTD5Vxk59ULe4hZNRLYoGd+Bj
|
||||||
|
hw8kyps1q4WMvkm/fueIrIGjqD2gwvopb4iwy/+n3rbFfHfE0UL8tEXqR3eWnhW1
|
||||||
|
D4pFAoGAccR4eMJD43hJWaUQLtsj0RoW9lFKVXj7aqkIIeupXwt7Ic2z/FhCAJi+
|
||||||
|
V0MWpd3K6+kPl+ifdt8U4kcYfubPMfJhd7IkMcgQS+yZK1+5xWdRISvI8GpNwIHE
|
||||||
|
LUkVkCCadXNNZ7b1nmUKjse95u4IaE6hwAqjSTNb05gPmCfoEjg=
|
||||||
|
-----END RSA PRIVATE KEY-----`;
|
||||||
|
const esKeyP256 = `-----BEGIN PRIVATE KEY-----
|
||||||
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgevZzL1gdAFr88hb2
|
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgevZzL1gdAFr88hb2
|
||||||
OF/2NxApJCzGCEDdfSp6VQO30hyhRANCAAQRWz+jn65BtOMvdyHKcvjBeBSDZH2r
|
OF/2NxApJCzGCEDdfSp6VQO30hyhRANCAAQRWz+jn65BtOMvdyHKcvjBeBSDZH2r
|
||||||
1RTwjmYSi9R/zpBnuQ4EiMnCqfMPWiZqB4QdbAd0E7oH50VpuZ1P087G
|
1RTwjmYSi9R/zpBnuQ4EiMnCqfMPWiZqB4QdbAd0E7oH50VpuZ1P087G
|
||||||
-----END PRIVATE KEY-----`;
|
-----END PRIVATE KEY-----`;
|
||||||
|
const esKeyP384 = `-----BEGIN PRIVATE KEY-----
|
||||||
|
MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDDpgCvB2frnLKd7TuWe
|
||||||
|
JM1ejXXmr9y/5gskxKuuylLvpQTiDdtLtuhJnvw1/zWKWO6hZANiAAQ5Crhsi5FD
|
||||||
|
t55i53dCtdzG9OzCnbDFf/6136ZfEiakDTDeWCdUvNnB3WQEcVBr97BfSWLI9mO+
|
||||||
|
T5yzm0RfhgvWIq/tBou+sIDeGp6NQfJwhDhf+JsdeF174gtfNMZGj/s=
|
||||||
|
-----END PRIVATE KEY-----`;
|
||||||
|
const esKeyP521 = `-----BEGIN PRIVATE KEY-----
|
||||||
|
MIHuAgEAMBAGByqGSM49AgEGBSuBBAAjBIHWMIHTAgEBBEIA0dBErrZ5ovKq4Xf/
|
||||||
|
iTlRkYxuOfgBZ6+tWIfG13YwthB1XrH06YmteZGNjHHLZEeycwUt0jM4kUb+tOsJ
|
||||||
|
3ckhj1ihgYkDgYYABACYgsa8JWKH46CQagwNw14v/L+DIs1WAjJdMXZySjKlRkD9
|
||||||
|
LtLMxkbX2H4H4Zl2KzCMJkwTSETzSKNlXvAUJqKbRwHezCp4y5XZN9MOBYdmyylZ
|
||||||
|
NOVxwwTouimNkJ0K6A8+/Im5S3PWB8Ra1D6t+bT1WHHhEePZcltSLLFlbIIyot5m
|
||||||
|
2w==
|
||||||
|
-----END PRIVATE KEY-----`;
|
||||||
|
|
||||||
TestRegister.addTests([
|
TestRegister.addTests([
|
||||||
{
|
{
|
||||||
@ -88,7 +129,24 @@ TestRegister.addTests([
|
|||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{
|
{
|
||||||
op: "JWT Sign",
|
op: "JWT Sign",
|
||||||
args: [esKey, "ES256", "{}"],
|
args: [esKeyP256, "ES256", "{}"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "JWT Decode",
|
||||||
|
args: []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "JWT Sign: ES384 - P256 key",
|
||||||
|
input: inputObject,
|
||||||
|
expectedOutput: `Error: Have you entered the key correctly? The key should be either the secret for HMAC algorithms or the PEM-encoded private key for RSA and ECDSA.
|
||||||
|
|
||||||
|
Error: "alg" parameter "ES384" requires curve "secp384r1".`,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "JWT Sign",
|
||||||
|
args: [esKeyP256, "ES384", "{}"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "JWT Decode",
|
op: "JWT Decode",
|
||||||
@ -103,7 +161,7 @@ TestRegister.addTests([
|
|||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{
|
{
|
||||||
op: "JWT Sign",
|
op: "JWT Sign",
|
||||||
args: [esKey, "ES384", "{}"],
|
args: [esKeyP384, "ES384", "{}"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "JWT Decode",
|
op: "JWT Decode",
|
||||||
@ -118,7 +176,24 @@ TestRegister.addTests([
|
|||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{
|
{
|
||||||
op: "JWT Sign",
|
op: "JWT Sign",
|
||||||
args: [esKey, "ES512", "{}"],
|
args: [esKeyP521, "ES512", "{}"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "JWT Decode",
|
||||||
|
args: []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "JWT Sign: RS256, weak key",
|
||||||
|
input: inputObject,
|
||||||
|
expectedOutput: `Error: Have you entered the key correctly? The key should be either the secret for HMAC algorithms or the PEM-encoded private key for RSA and ECDSA.
|
||||||
|
|
||||||
|
Error: secretOrPrivateKey has a minimum key size of 2048 bits for RS256`,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "JWT Sign",
|
||||||
|
args: [rsKey1024, "RS256", "{}"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "JWT Decode",
|
op: "JWT Decode",
|
||||||
@ -133,7 +208,7 @@ TestRegister.addTests([
|
|||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{
|
{
|
||||||
op: "JWT Sign",
|
op: "JWT Sign",
|
||||||
args: [rsKey, "RS256", "{}"],
|
args: [rsKey2048, "RS256", "{}"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "JWT Decode",
|
op: "JWT Decode",
|
||||||
@ -148,7 +223,7 @@ TestRegister.addTests([
|
|||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{
|
{
|
||||||
op: "JWT Sign",
|
op: "JWT Sign",
|
||||||
args: [rsKey, "RS384", "{}"],
|
args: [rsKey2048, "RS384", "{}"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "JWT Decode",
|
op: "JWT Decode",
|
||||||
@ -163,7 +238,7 @@ TestRegister.addTests([
|
|||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{
|
{
|
||||||
op: "JWT Sign",
|
op: "JWT Sign",
|
||||||
args: [esKey, "RS512", "{}"],
|
args: [rsKey2048, "RS512", "{}"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "JWT Decode",
|
op: "JWT Decode",
|
||||||
|
|||||||
487
tests/operations/tests/RC6.mjs
Normal file
487
tests/operations/tests/RC6.mjs
Normal file
@ -0,0 +1,487 @@
|
|||||||
|
/**
|
||||||
|
* RC6 cipher tests.
|
||||||
|
*
|
||||||
|
* Test vectors from the IETF draft:
|
||||||
|
* "Test Vectors for RC6 and RC5"
|
||||||
|
* https://datatracker.ietf.org/doc/html/draft-krovetz-rc6-rc5-vectors-00
|
||||||
|
*
|
||||||
|
* @author Medjedtxm
|
||||||
|
* @copyright Crown Copyright 2026
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import TestRegister from "../../lib/TestRegister.mjs";
|
||||||
|
|
||||||
|
TestRegister.addTests([
|
||||||
|
// ============================================================
|
||||||
|
// IETF TEST VECTORS - RC6-8/12/4
|
||||||
|
// ============================================================
|
||||||
|
{
|
||||||
|
name: "RC6-8/12/4: IETF vector encrypt",
|
||||||
|
input: "00010203",
|
||||||
|
expectedOutput: "aefc4612",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Encrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "00010203", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Hex", "Hex", "NO", 8, 12
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "RC6-8/12/4: IETF vector decrypt",
|
||||||
|
input: "aefc4612",
|
||||||
|
expectedOutput: "00010203",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Decrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "00010203", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Hex", "Hex", "NO", 8, 12
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// IETF TEST VECTORS - RC6-16/16/8
|
||||||
|
// ============================================================
|
||||||
|
{
|
||||||
|
name: "RC6-16/16/8: IETF vector encrypt",
|
||||||
|
input: "0001020304050607",
|
||||||
|
expectedOutput: "2ff0b68eaeffad5b",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Encrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "0001020304050607", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Hex", "Hex", "NO", 16, 16
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "RC6-16/16/8: IETF vector decrypt",
|
||||||
|
input: "2ff0b68eaeffad5b",
|
||||||
|
expectedOutput: "0001020304050607",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Decrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "0001020304050607", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Hex", "Hex", "NO", 16, 16
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// IETF TEST VECTORS - RC6-32/20/16 (AES standard)
|
||||||
|
// ============================================================
|
||||||
|
{
|
||||||
|
name: "RC6-32/20/16: IETF vector encrypt (AES standard)",
|
||||||
|
input: "000102030405060708090a0b0c0d0e0f",
|
||||||
|
expectedOutput: "3a96f9c7f6755cfe46f00e3dcd5d2a3c",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Encrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "000102030405060708090a0b0c0d0e0f", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Hex", "Hex", "NO", 32, 20
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "RC6-32/20/16: IETF vector decrypt (AES standard)",
|
||||||
|
input: "3a96f9c7f6755cfe46f00e3dcd5d2a3c",
|
||||||
|
expectedOutput: "000102030405060708090a0b0c0d0e0f",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Decrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "000102030405060708090a0b0c0d0e0f", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Hex", "Hex", "NO", 32, 20
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// IETF TEST VECTORS - RC6-64/24/24
|
||||||
|
// ============================================================
|
||||||
|
{
|
||||||
|
name: "RC6-64/24/24: IETF vector encrypt",
|
||||||
|
input: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
|
||||||
|
expectedOutput: "c002de050bd55e5d36864ab9853338e6dc4a1326c6bdaaeb1bc9e4fd67886617",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Encrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "000102030405060708090a0b0c0d0e0f1011121314151617", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Hex", "Hex", "NO", 64, 24
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "RC6-64/24/24: IETF vector decrypt",
|
||||||
|
input: "c002de050bd55e5d36864ab9853338e6dc4a1326c6bdaaeb1bc9e4fd67886617",
|
||||||
|
expectedOutput: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Decrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "000102030405060708090a0b0c0d0e0f1011121314151617", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Hex", "Hex", "NO", 64, 24
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// IETF TEST VECTORS - RC6-128/28/32
|
||||||
|
// ============================================================
|
||||||
|
{
|
||||||
|
name: "RC6-128/28/32: IETF vector encrypt",
|
||||||
|
input: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f",
|
||||||
|
expectedOutput: "4ed87c64baffecd4303ee6a79aafaef575b351c024272be70a70b4a392cfc157dba52d529a79e83845bf43d67545383aed3dbf4f0d23640e44cbf6cdaa034dcb",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Encrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Hex", "Hex", "NO", 128, 28
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "RC6-128/28/32: IETF vector decrypt",
|
||||||
|
input: "4ed87c64baffecd4303ee6a79aafaef575b351c024272be70a70b4a392cfc157dba52d529a79e83845bf43d67545383aed3dbf4f0d23640e44cbf6cdaa034dcb",
|
||||||
|
expectedOutput: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Decrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Hex", "Hex", "NO", 128, 28
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// IETF TEST VECTORS - RC6-24/4/0 (non-power-of-2)
|
||||||
|
// ============================================================
|
||||||
|
{
|
||||||
|
name: "RC6-24/4/0: IETF non-standard vector encrypt (w=24, empty key)",
|
||||||
|
input: "000102030405060708090a0b",
|
||||||
|
expectedOutput: "0177982579be2ee3303269b9",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Encrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Hex", "Hex", "NO", 24, 4
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "RC6-24/4/0: IETF non-standard vector decrypt (w=24, empty key)",
|
||||||
|
input: "0177982579be2ee3303269b9",
|
||||||
|
expectedOutput: "000102030405060708090a0b",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Decrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Hex", "Hex", "NO", 24, 4
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// IETF TEST VECTORS - RC6-80/4/12 (non-power-of-2)
|
||||||
|
// ============================================================
|
||||||
|
{
|
||||||
|
name: "RC6-80/4/12: IETF non-standard vector encrypt (w=80)",
|
||||||
|
input: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021222324252627",
|
||||||
|
expectedOutput: "26d9d6128601d06dec3817d401f1c0ff715473543875da417c2116d1e87c919a49311b00b4e17962",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Encrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "000102030405060708090a0b", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Hex", "Hex", "NO", 80, 4
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "RC6-80/4/12: IETF non-standard vector decrypt (w=80)",
|
||||||
|
input: "26d9d6128601d06dec3817d401f1c0ff715473543875da417c2116d1e87c919a49311b00b4e17962",
|
||||||
|
expectedOutput: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021222324252627",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Decrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "000102030405060708090a0b", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Hex", "Hex", "NO", 80, 4
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// ADDITIONAL KEY SIZE TESTS - RC6-32 (192-bit and 256-bit keys)
|
||||||
|
// ============================================================
|
||||||
|
{
|
||||||
|
name: "RC6-32/20/24: 192-bit key encrypt",
|
||||||
|
input: "000102030405060708090a0b0c0d0e0f",
|
||||||
|
expectedOutput: "a68a14ff1342262a2bbd21f7966615eb",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Encrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "000102030405060708090a0b0c0d0e0f1011121314151617", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Hex", "Hex", "NO", 32, 20
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "RC6-32/20/32: 256-bit key encrypt",
|
||||||
|
input: "000102030405060708090a0b0c0d0e0f",
|
||||||
|
expectedOutput: "921c3ecd43d9426a90089334d67aea2e",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Encrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Hex", "Hex", "NO", 32, 20
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// ROUND-TRIP TESTS - One per word size to verify encrypt/decrypt
|
||||||
|
// ============================================================
|
||||||
|
{
|
||||||
|
name: "RC6-8 Round-trip: CBC mode",
|
||||||
|
input: "Hello World!",
|
||||||
|
expectedOutput: "Hello World!",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Encrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "mysecret", option: "UTF8" },
|
||||||
|
{ string: "abcd", option: "UTF8" },
|
||||||
|
"CBC", "Raw", "Hex", "PKCS5", 8, 12
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "RC6 Decrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "mysecret", option: "UTF8" },
|
||||||
|
{ string: "abcd", option: "UTF8" },
|
||||||
|
"CBC", "Hex", "Raw", "PKCS5", 8, 12
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "RC6-16 Round-trip: CBC mode",
|
||||||
|
input: "The quick brown fox",
|
||||||
|
expectedOutput: "The quick brown fox",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Encrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "secretkey1234567", option: "UTF8" },
|
||||||
|
{ string: "initvec!", option: "UTF8" },
|
||||||
|
"CBC", "Raw", "Hex", "PKCS5", 16, 16
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "RC6 Decrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "secretkey1234567", option: "UTF8" },
|
||||||
|
{ string: "initvec!", option: "UTF8" },
|
||||||
|
"CBC", "Hex", "Raw", "PKCS5", 16, 16
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "RC6-32 Round-trip: CBC mode",
|
||||||
|
input: "The quick brown fox jumps over the lazy dog",
|
||||||
|
expectedOutput: "The quick brown fox jumps over the lazy dog",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Encrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "aabbccddeeff00112233445566778899", option: "Hex" },
|
||||||
|
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
|
||||||
|
"CBC", "Raw", "Hex", "PKCS5", 32, 20
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "RC6 Decrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "aabbccddeeff00112233445566778899", option: "Hex" },
|
||||||
|
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
|
||||||
|
"CBC", "Hex", "Raw", "PKCS5", 32, 20
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "RC6-64 Round-trip: CBC mode",
|
||||||
|
input: "RC6 with 64-bit words is powerful!",
|
||||||
|
expectedOutput: "RC6 with 64-bit words is powerful!",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Encrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", option: "Hex" },
|
||||||
|
{ string: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", option: "Hex" },
|
||||||
|
"CBC", "Raw", "Hex", "PKCS5", 64, 24
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "RC6 Decrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", option: "Hex" },
|
||||||
|
{ string: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", option: "Hex" },
|
||||||
|
"CBC", "Hex", "Raw", "PKCS5", 64, 24
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "RC6-128 Round-trip: ECB mode",
|
||||||
|
input: "RC6 with 128-bit words provides massive block size for testing purposes!",
|
||||||
|
expectedOutput: "RC6 with 128-bit words provides massive block size for testing purposes!",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Encrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Raw", "Hex", "PKCS5", 128, 28
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "RC6 Decrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Hex", "Raw", "PKCS5", 128, 28
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// STREAM MODES TEST - Verify CFB/OFB/CTR work correctly
|
||||||
|
// ============================================================
|
||||||
|
{
|
||||||
|
name: "RC6-32 Round-trip: CTR mode",
|
||||||
|
input: "CTR mode test message",
|
||||||
|
expectedOutput: "CTR mode test message",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Encrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
|
||||||
|
{ string: "00000000000000000000000000000001", option: "Hex" },
|
||||||
|
"CTR", "Raw", "Hex", "PKCS5", 32, 20
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "RC6 Decrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
|
||||||
|
{ string: "00000000000000000000000000000001", option: "Hex" },
|
||||||
|
"CTR", "Hex", "Raw", "PKCS5", 32, 20
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// CUSTOM ROUNDS TEST - Verify non-standard round count works
|
||||||
|
// ============================================================
|
||||||
|
{
|
||||||
|
name: "RC6-32 Round-trip: Custom 8 rounds",
|
||||||
|
input: "Testing custom rounds",
|
||||||
|
expectedOutput: "Testing custom rounds",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Encrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Raw", "Hex", "PKCS5", 32, 8
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "RC6 Decrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Hex", "Raw", "PKCS5", 32, 8
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// EDGE CASE TEST - Padding boundary
|
||||||
|
// ============================================================
|
||||||
|
{
|
||||||
|
name: "RC6-32 Round-trip: Exact block size input",
|
||||||
|
input: "1234567890123456",
|
||||||
|
expectedOutput: "1234567890123456",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "RC6 Encrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Raw", "Hex", "PKCS5", 32, 20
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "RC6 Decrypt",
|
||||||
|
args: [
|
||||||
|
{ string: "00112233445566778899aabbccddeeff", option: "Hex" },
|
||||||
|
{ string: "", option: "Hex" },
|
||||||
|
"ECB", "Hex", "Raw", "PKCS5", 32, 20
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]);
|
||||||
54
tests/operations/tests/SQLBeautify.mjs
Normal file
54
tests/operations/tests/SQLBeautify.mjs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/**
|
||||||
|
* SQLBeautify tests.
|
||||||
|
*
|
||||||
|
* @author GCHQDeveloper581
|
||||||
|
* @copyright Crown Copyright 2026
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
import TestRegister from "../../lib/TestRegister.mjs";
|
||||||
|
|
||||||
|
TestRegister.addTests([
|
||||||
|
{
|
||||||
|
name: "SQL Beautify - basic",
|
||||||
|
input: "SELECT MONTH, ID, RAIN_I, TEMP_F FROM STATS;",
|
||||||
|
expectedOutput:
|
||||||
|
`SELECT
|
||||||
|
MONTH,
|
||||||
|
ID,
|
||||||
|
RAIN_I,
|
||||||
|
TEMP_F
|
||||||
|
FROM
|
||||||
|
STATS;`,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "SQL Beautify",
|
||||||
|
args: [" "],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "SQL Beautify - upsert",
|
||||||
|
input: "INSERT INTO Table1 SELECT * FROM (SELECT :Bind1 as Field1, :Bind2 as Field2, :id as id) as new_data ON DUPLICATE KEY UPDATE Field1 = new_data.Field1, Field2 = new_data.Field2;",
|
||||||
|
expectedOutput:
|
||||||
|
`INSERT INTO
|
||||||
|
Table1
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
:Bind1 as Field1,
|
||||||
|
:Bind2 as Field2,
|
||||||
|
:id as id
|
||||||
|
) as new_data
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
Field1 = new_data.Field1,
|
||||||
|
Field2 = new_data.Field2;`,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "SQL Beautify",
|
||||||
|
args: [" "],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
199
tests/operations/tests/TextIntegerConverter.mjs
Normal file
199
tests/operations/tests/TextIntegerConverter.mjs
Normal file
@ -0,0 +1,199 @@
|
|||||||
|
/**
|
||||||
|
* Text-Integer Conversion tests.
|
||||||
|
*
|
||||||
|
* @author p-leriche [philip.leriche@cantab.net]
|
||||||
|
*
|
||||||
|
* @copyright Crown Copyright 2025
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
import TestRegister from "../../lib/TestRegister.mjs";
|
||||||
|
|
||||||
|
TestRegister.addTests([
|
||||||
|
{
|
||||||
|
name: "Text-Integer Conversion quoted string to decimal",
|
||||||
|
input: "\"ABC\"",
|
||||||
|
expectedOutput: "4276803",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Text-Integer Conversion",
|
||||||
|
args: ["Decimal"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Text-Integer Conversion quoted string to hexadecimal",
|
||||||
|
input: "\"ABC\"",
|
||||||
|
expectedOutput: "0x414243",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Text-Integer Conversion",
|
||||||
|
args: ["Hexadecimal"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Text-Integer Conversion single quoted string to decimal",
|
||||||
|
input: "'Hello'",
|
||||||
|
expectedOutput: "310939249775",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Text-Integer Conversion",
|
||||||
|
args: ["Decimal"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Text-Integer Conversion decimal to string",
|
||||||
|
input: "4276803",
|
||||||
|
expectedOutput: "ABC",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Text-Integer Conversion",
|
||||||
|
args: ["String"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Text-Integer Conversion hexadecimal to string",
|
||||||
|
input: "0x48656C6C6F",
|
||||||
|
expectedOutput: "Hello",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Text-Integer Conversion",
|
||||||
|
args: ["String"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Text-Integer Conversion round-trip string.decimal.string",
|
||||||
|
input: "\"Test\"",
|
||||||
|
expectedOutput: "Test",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Text-Integer Conversion",
|
||||||
|
args: ["Decimal"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "Text-Integer Conversion",
|
||||||
|
args: ["String"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Text-Integer Conversion round-trip string.hex.string",
|
||||||
|
input: "\"CyberChef\"",
|
||||||
|
expectedOutput: "CyberChef",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Text-Integer Conversion",
|
||||||
|
args: ["Hexadecimal"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "Text-Integer Conversion",
|
||||||
|
args: ["String"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Text-Integer Conversion implicit round trip string-string Latin-1",
|
||||||
|
input: "U+00FF",
|
||||||
|
expectedOutput: "U+00FF", // U+00FF (Latin small letter y with diaeresis)
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Unescape Unicode Characters",
|
||||||
|
args: ["U+"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "Text-Integer Conversion",
|
||||||
|
args: ["String"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "Escape Unicode Characters",
|
||||||
|
args: ["U+", false, 4, true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Text-Integer Conversion unquoted text to decimal",
|
||||||
|
input: "Hi",
|
||||||
|
expectedOutput: "18537",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Text-Integer Conversion",
|
||||||
|
args: ["Decimal"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Text-Integer Conversion single character",
|
||||||
|
input: "\"A\"",
|
||||||
|
expectedOutput: "65",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Text-Integer Conversion",
|
||||||
|
args: ["Decimal"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Text-Integer Conversion hex to decimal conversion",
|
||||||
|
input: "0xFF",
|
||||||
|
expectedOutput: "255",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Text-Integer Conversion",
|
||||||
|
args: ["Decimal"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Text-Integer Conversion decimal to hex conversion",
|
||||||
|
input: "255",
|
||||||
|
expectedOutput: "0xff",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Text-Integer Conversion",
|
||||||
|
args: ["Hexadecimal"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Text-Integer Conversion large number to string",
|
||||||
|
input: "113091951015816448506195587157728348242683688608116",
|
||||||
|
expectedOutput: "Mary had a little cat",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Text-Integer Conversion",
|
||||||
|
args: ["String"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Text-Integer Conversion whitespace handling (quoted)",
|
||||||
|
input: "\" test \"",
|
||||||
|
expectedOutput: "2314978187545944096",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Text-Integer Conversion",
|
||||||
|
args: ["Decimal"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Text-Integer Conversion non-Latin1 character in input",
|
||||||
|
input: "61 ce 93 61",
|
||||||
|
expectedOutput:
|
||||||
|
`Character at position 1 exceeds Latin-1 range (0-255).
|
||||||
|
Only ASCII and Latin-1 characters are supported.`,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "From Hex",
|
||||||
|
"args": ["Auto"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "Text-Integer Conversion",
|
||||||
|
args: ["Decimal"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
Loading…
x
Reference in New Issue
Block a user