Merge branch 'master' into io-overhaul

This commit is contained in:
n1474335 2022-07-10 19:06:48 +01:00
commit 2785459257
38 changed files with 1703 additions and 29 deletions

View file

@ -13,6 +13,27 @@ All major and minor version changes will be documented in this file. Details of
## Details
### [9.46.0] - 2022-07-08
- Added 'Cetacean Cipher Encode' and 'Cetacean Cipher Decode' operations [@valdelaseras] | [#1308]
### [9.45.0] - 2022-07-08
- Added 'ROT8000' operation [@thomasleplus] | [#1250]
### [9.44.0] - 2022-07-08
- Added 'LZString Compress' and 'LZString Decompress' operations [@crespyl] | [#1266]
### [9.43.0] - 2022-07-08
- Added 'ROT13 Brute Force' and 'ROT47 Brute Force' operations [@mikecat] | [#1264]
### [9.42.0] - 2022-07-08
- Added 'LS47 Encrypt' and 'LS47 Decrypt' operations [@n1073645] | [#951]
### [9.41.0] - 2022-07-08
- Added 'Caesar Box Cipher' operation [@n1073645] | [#1066]
### [9.40.0] - 2022-07-08
- Added 'P-list Viewer' operation [@n1073645] | [#906]
### [9.39.0] - 2022-06-09
- Added 'ELF Info' operation [@n1073645] | [#1364]
@ -294,6 +315,13 @@ All major and minor version changes will be documented in this file. Details of
[9.46.0]: https://github.com/gchq/CyberChef/releases/tag/v9.46.0
[9.45.0]: https://github.com/gchq/CyberChef/releases/tag/v9.45.0
[9.44.0]: https://github.com/gchq/CyberChef/releases/tag/v9.44.0
[9.43.0]: https://github.com/gchq/CyberChef/releases/tag/v9.43.0
[9.42.0]: https://github.com/gchq/CyberChef/releases/tag/v9.42.0
[9.41.0]: https://github.com/gchq/CyberChef/releases/tag/v9.41.0
[9.40.0]: https://github.com/gchq/CyberChef/releases/tag/v9.40.0
[9.39.0]: https://github.com/gchq/CyberChef/releases/tag/v9.39.0
[9.38.0]: https://github.com/gchq/CyberChef/releases/tag/v9.38.0
[9.37.0]: https://github.com/gchq/CyberChef/releases/tag/v9.37.0
@ -418,6 +446,10 @@ All major and minor version changes will be documented in this file. Details of
[@t-8ch]: https://github.com/t-8ch
[@hettysymes]: https://github.com/hettysymes
[@swesven]: https://github.com/swesven
[@mikecat]: https://github.com/mikecat
[@crespyl]: https://github.com/crespyl
[@thomasleplus]: https://github.com/thomasleplus
[@valdelaseras]: https://github.com/valdelaseras
[8ad18b]: https://github.com/gchq/CyberChef/commit/8ad18bc7db6d9ff184ba3518686293a7685bf7b7
[9a33498]: https://github.com/gchq/CyberChef/commit/9a33498fed26a8df9c9f35f39a78a174bf50a513
@ -491,10 +523,12 @@ All major and minor version changes will be documented in this file. Details of
[#674]: https://github.com/gchq/CyberChef/pull/674
[#683]: https://github.com/gchq/CyberChef/pull/683
[#865]: https://github.com/gchq/CyberChef/pull/865
[#906]: https://github.com/gchq/CyberChef/pull/906
[#912]: https://github.com/gchq/CyberChef/pull/912
[#917]: https://github.com/gchq/CyberChef/pull/917
[#934]: https://github.com/gchq/CyberChef/pull/934
[#948]: https://github.com/gchq/CyberChef/pull/948
[#951]: https://github.com/gchq/CyberChef/pull/951
[#952]: https://github.com/gchq/CyberChef/pull/952
[#965]: https://github.com/gchq/CyberChef/pull/965
[#966]: https://github.com/gchq/CyberChef/pull/966
@ -506,6 +540,7 @@ All major and minor version changes will be documented in this file. Details of
[#1045]: https://github.com/gchq/CyberChef/pull/1045
[#1049]: https://github.com/gchq/CyberChef/pull/1049
[#1065]: https://github.com/gchq/CyberChef/pull/1065
[#1066]: https://github.com/gchq/CyberChef/pull/1066
[#1083]: https://github.com/gchq/CyberChef/pull/1083
[#1189]: https://github.com/gchq/CyberChef/pull/1189
[#1242]: https://github.com/gchq/CyberChef/pull/1242
@ -513,3 +548,8 @@ All major and minor version changes will be documented in this file. Details of
[#1313]: https://github.com/gchq/CyberChef/pull/1313
[#1326]: https://github.com/gchq/CyberChef/pull/1326
[#1364]: https://github.com/gchq/CyberChef/pull/1364
[#1264]: https://github.com/gchq/CyberChef/pull/1264
[#1266]: https://github.com/gchq/CyberChef/pull/1266
[#1250]: https://github.com/gchq/CyberChef/pull/1250
[#1308]: https://github.com/gchq/CyberChef/pull/1308

18
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "cyberchef",
"version": "9.39.1",
"version": "9.46.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "cyberchef",
"version": "9.39.1",
"version": "9.46.0",
"hasInstallScript": true,
"license": "Apache-2.0",
"dependencies": {
@ -56,6 +56,7 @@
"lodash": "^4.17.21",
"loglevel": "^1.8.0",
"loglevel-message-prefix": "^3.0.0",
"lz-string": "^1.4.4",
"markdown-it": "^13.0.1",
"moment": "^2.29.3",
"moment-timezone": "^0.5.34",
@ -10209,6 +10210,14 @@
"node": ">=10"
}
},
"node_modules/lz-string": {
"version": "1.4.4",
"resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.4.4.tgz",
"integrity": "sha512-0ckx7ZHRPqb0oUm8zNr+90mtf9DQB60H1wMCjBtfi62Kl3a7JbHob6gA2bC+xRvZoOL+1hzUK8jeuEIQE8svEQ==",
"bin": {
"lz-string": "bin/bin.js"
}
},
"node_modules/make-dir": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz",
@ -23746,6 +23755,11 @@
"yallist": "^4.0.0"
}
},
"lz-string": {
"version": "1.4.4",
"resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.4.4.tgz",
"integrity": "sha512-0ckx7ZHRPqb0oUm8zNr+90mtf9DQB60H1wMCjBtfi62Kl3a7JbHob6gA2bC+xRvZoOL+1hzUK8jeuEIQE8svEQ=="
},
"make-dir": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz",

View file

@ -1,6 +1,6 @@
{
"name": "cyberchef",
"version": "9.39.1",
"version": "9.46.0",
"description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.",
"author": "n1474335 <n1474335@gmail.com>",
"homepage": "https://gchq.github.io/CyberChef",
@ -138,6 +138,7 @@
"lodash": "^4.17.21",
"loglevel": "^1.8.0",
"loglevel-message-prefix": "^3.0.0",
"lz-string": "^1.4.4",
"markdown-it": "^13.0.1",
"moment": "^2.29.3",
"moment-timezone": "^0.5.34",

View file

@ -79,6 +79,8 @@
"DES Decrypt",
"Triple DES Encrypt",
"Triple DES Decrypt",
"LS47 Encrypt",
"LS47 Decrypt",
"RC2 Encrypt",
"RC2 Decrypt",
"RC4",
@ -86,7 +88,10 @@
"SM4 Encrypt",
"SM4 Decrypt",
"ROT13",
"ROT13 Brute Force",
"ROT47",
"ROT47 Brute Force",
"ROT8000",
"XOR",
"XOR Brute Force",
"Vigenère Encode",
@ -97,6 +102,7 @@
"Bacon Cipher Decode",
"Bifid Cipher Encode",
"Bifid Cipher Decode",
"Caesar Box Cipher",
"Affine Cipher Encode",
"Affine Cipher Decode",
"A1Z26 Cipher Encode",
@ -106,6 +112,8 @@
"Atbash Cipher",
"CipherSaber2 Encrypt",
"CipherSaber2 Decrypt",
"Cetacean Cipher Encode",
"Cetacean Cipher Decode",
"Substitute",
"Derive PBKDF2 key",
"Derive EVP key",
@ -176,7 +184,8 @@
"Bit shift right",
"Rotate left",
"Rotate right",
"ROT13"
"ROT13",
"ROT8000"
]
},
{
@ -320,7 +329,9 @@
"Bzip2 Decompress",
"Bzip2 Compress",
"Tar",
"Untar"
"Untar",
"LZString Compress",
"LZString Decompress"
]
},
{
@ -457,6 +468,7 @@
"Frequency distribution",
"Index of Coincidence",
"Chi Square",
"P-list Viewer",
"Disassemble x86",
"Pseudo-Random Number Generator",
"Generate UUID",

View file

@ -1,3 +1,5 @@
import Utils from "../Utils.mjs";
/**
* Base85 resources.
*
@ -32,13 +34,12 @@ export const ALPHABET_OPTIONS = [
* @returns {string}
*/
export function alphabetName(alphabet) {
alphabet = alphabet.replace(/'/g, "&apos;");
alphabet = alphabet.replace(/"/g, "&quot;");
alphabet = alphabet.replace(/\\/g, "&bsol;");
alphabet = escape(alphabet);
let name;
ALPHABET_OPTIONS.forEach(function(a) {
if (escape(alphabet) === escape(a.value)) name = a.name;
const expanded = Utils.expandAlphRange(a.value).join("");
if (alphabet === escape(expanded)) name = a.name;
});
return name;

View file

@ -70,7 +70,7 @@ export const FILE_SIGNATURES = {
10: 0x42,
11: 0x50
},
extractor: null
extractor: extractWEBP
},
{
name: "Camera Image File Format",
@ -3032,6 +3032,30 @@ export function extractPNG(bytes, offset) {
}
/**
* WEBP extractor.
*
* @param {Uint8Array} bytes
* @param {number} offset
* @returns {Uint8Array}
*/
export function extractWEBP(bytes, offset) {
const stream = new Stream(bytes.slice(offset));
// Move to file size offset.
stream.moveForwardsBy(4);
// Read file size field.
const fileSize = stream.readInt(4, "le");
// Move to end of file.
// There is no need to minus 8 from the size as the size factors in the offset.
stream.moveForwardsBy(fileSize);
return stream.carve();
}
/**
* BMP extractor.
*

244
src/core/lib/LS47.mjs Normal file
View file

@ -0,0 +1,244 @@
/**
* @author n1073645 [n1073645@gmail.com]
* @copyright Crown Copyright 2020
* @license Apache-2.0
*/
import OperationError from "../errors/OperationError.mjs";
const letters = "_abcdefghijklmnopqrstuvwxyz.0123456789,-+*/:?!'()";
const tiles = [];
/**
* Initialises the tiles with values and positions.
*/
export function initTiles() {
for (let i = 0; i < 49; i++)
tiles.push([letters.charAt(i), [Math.floor(i/7), i % 7]]);
}
/**
* Rotates the key "down".
*
* @param {string} key
* @param {number} col
* @param {number} n
* @returns {string}
*/
function rotateDown(key, col, n) {
const lines = [];
for (let i = 0; i < 7; i++)
lines.push(key.slice(i*7, (i + 1) * 7));
const lefts = [];
let mids = [];
const rights = [];
lines.forEach((element) => {
lefts.push(element.slice(0, col));
mids.push(element.charAt(col));
rights.push(element.slice(col+1));
});
n = (7 - n % 7) % 7;
mids = mids.slice(n).concat(mids.slice(0, n));
let result = "";
for (let i = 0; i < 7; i++)
result += lefts[i] + mids[i] + rights[i];
return result;
}
/**
* Rotates the key "right".
*
* @param {string} key
* @param {number} row
* @param {number} n
* @returns {string}
*/
function rotateRight(key, row, n) {
const mid = key.slice(row * 7, (row + 1) * 7);
n = (7 - n % 7) % 7;
return key.slice(0, 7 * row) + mid.slice(n) + mid.slice(0, n) + key.slice(7 * (row + 1));
}
/**
* Finds the position of a letter in the tiles.
*
* @param {string} letter
* @returns {string}
*/
function findIx(letter) {
for (let i = 0; i < tiles.length; i++)
if (tiles[i][0] === letter)
return tiles[i][1];
throw new OperationError("Letter " + letter + " is not included in LS47");
}
/**
* Derives key from the input password.
*
* @param {string} password
* @returns {string}
*/
export function deriveKey(password) {
let i = 0;
let k = letters;
for (const c of password) {
const [row, col] = findIx(c);
k = rotateDown(rotateRight(k, i, col), i, row);
i = (i + 1) % 7;
}
return k;
}
/**
* Checks the key is a valid key.
*
* @param {string} key
*/
function checkKey(key) {
if (key.length !== letters.length)
throw new OperationError("Wrong key size");
const counts = new Array();
for (let i = 0; i < letters.length; i++)
counts[letters.charAt(i)] = 0;
for (const elem of letters) {
if (letters.indexOf(elem) === -1)
throw new OperationError("Letter " + elem + " not in LS47");
counts[elem]++;
if (counts[elem] > 1)
throw new OperationError("Letter duplicated in the key");
}
}
/**
* Finds the position of a letter in they key.
*
* @param {letter} key
* @param {string} letter
* @returns {object}
*/
function findPos (key, letter) {
const index = key.indexOf(letter);
if (index >= 0 && index < 49)
return [Math.floor(index/7), index%7];
throw new OperationError("Letter " + letter + " is not in the key");
}
/**
* Returns the character at the position on the tiles.
*
* @param {string} key
* @param {object} coord
* @returns {string}
*/
function findAtPos(key, coord) {
return key.charAt(coord[1] + (coord[0] * 7));
}
/**
* Returns new position by adding two positions.
*
* @param {object} a
* @param {object} b
* @returns {object}
*/
function addPos(a, b) {
return [(a[0] + b[0]) % 7, (a[1] + b[1]) % 7];
}
/**
* Returns new position by subtracting two positions.
* Note: We have to manually do the remainder division, since JS does not
* operate correctly on negative numbers (e.g. -3 % 4 = -3 when it should be 1).
*
* @param {object} a
* @param {object} b
* @returns {object}
*/
function subPos(a, b) {
const asub = a[0] - b[0];
const bsub = a[1] - b[1];
return [asub - (Math.floor(asub/7) * 7), bsub - (Math.floor(bsub/7) * 7)];
}
/**
* Encrypts the plaintext string.
*
* @param {string} key
* @param {string} plaintext
* @returns {string}
*/
function encrypt(key, plaintext) {
checkKey(key);
let mp = [0, 0];
let ciphertext = "";
for (const p of plaintext) {
const pp = findPos(key, p);
const mix = findIx(findAtPos(key, mp));
let cp = addPos(pp, mix);
const c = findAtPos(key, cp);
ciphertext += c;
key = rotateRight(key, pp[0], 1);
cp = findPos(key, c);
key = rotateDown(key, cp[1], 1);
mp = addPos(mp, findIx(c));
}
return ciphertext;
}
/**
* Decrypts the ciphertext string.
*
* @param {string} key
* @param {string} ciphertext
* @returns {string}
*/
function decrypt(key, ciphertext) {
checkKey(key);
let mp = [0, 0];
let plaintext = "";
for (const c of ciphertext) {
let cp = findPos(key, c);
const mix = findIx(findAtPos(key, mp));
const pp = subPos(cp, mix);
const p = findAtPos(key, pp);
plaintext += p;
key = rotateRight(key, pp[0], 1);
cp = findPos(key, c);
key = rotateDown(key, cp[1], 1);
mp = addPos(mp, findIx(c));
}
return plaintext;
}
/**
* Adds padding to the input.
*
* @param {string} key
* @param {string} plaintext
* @param {string} signature
* @param {number} paddingSize
* @returns {string}
*/
export function encryptPad(key, plaintext, signature, paddingSize) {
initTiles();
checkKey(key);
let padding = "";
for (let i = 0; i < paddingSize; i++) {
padding += letters.charAt(Math.floor(Math.random() * letters.length));
}
return encrypt(key, padding+plaintext+"---"+signature);
}
/**
* Removes padding from the ouput.
*
* @param {string} key
* @param {string} ciphertext
* @param {number} paddingSize
* @returns {string}
*/
export function decryptPad(key, ciphertext, paddingSize) {
initTiles();
checkKey(key);
return decrypt(key, ciphertext).slice(paddingSize);
}

21
src/core/lib/LZString.mjs Normal file
View file

@ -0,0 +1,21 @@
/**
* lz-string exports.
*
* @author crespyl [peter@crespyl.net]
* @copyright Peter Jacobs 2021
* @license Apache-2.0
*/
import LZString from "lz-string";
export const COMPRESSION_OUTPUT_FORMATS = ["default", "UTF16", "Base64"];
export const COMPRESSION_FUNCTIONS = {
"default": LZString.compress,
"UTF16": LZString.compressToUTF16,
"Base64": LZString.compressToBase64,
};
export const DECOMPRESSION_FUNCTIONS = {
"default": LZString.decompress,
"UTF16": LZString.decompressFromUTF16,
"Base64": LZString.decompressFromBase64,
};

View file

@ -0,0 +1,61 @@
/**
* @author n1073645 [n1073645@gmail.com]
* @copyright Crown Copyright 2020
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
/**
* Caesar Box Cipher operation
*/
class CaesarBoxCipher extends Operation {
/**
* CaesarBoxCipher constructor
*/
constructor() {
super();
this.name = "Caesar Box Cipher";
this.module = "Ciphers";
this.description = "Caesar Box is a transposition cipher used in the Roman Empire, in which letters of the message are written in rows in a square (or a rectangle) and then, read by column.";
this.infoURL = "https://www.dcode.fr/caesar-box-cipher";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
name: "Box Height",
type: "number",
value: 1
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const tableHeight = args[0];
const tableWidth = Math.ceil(input.length / tableHeight);
while (input.indexOf(" ") !== -1)
input = input.replace(" ", "");
for (let i = 0; i < (tableHeight * tableWidth) - input.length; i++) {
input += "\x00";
}
let result = "";
for (let i = 0; i < tableHeight; i++) {
for (let j = i; j < input.length; j += tableHeight) {
if (input.charAt(j) !== "\x00") {
result += input.charAt(j);
}
}
}
return result;
}
}
export default CaesarBoxCipher;

View file

@ -0,0 +1,63 @@
/**
* @author dolphinOnKeys [robin@weird.io]
* @copyright Crown Copyright 2022
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
/**
* Cetacean Cipher Decode operation
*/
class CetaceanCipherDecode extends Operation {
/**
* CetaceanCipherDecode constructor
*/
constructor() {
super();
this.name = "Cetacean Cipher Decode";
this.module = "Ciphers";
this.description = "Decode Cetacean Cipher input. <br/><br/>e.g. <code>EEEEEEEEEeeEeEEEEEEEEEEEEeeEeEEe</code> becomes <code>hi</code>";
this.infoURL = "https://hitchhikers.fandom.com/wiki/Dolphins";
this.inputType = "string";
this.outputType = "string";
this.checks = [
{
pattern: "^(?:[eE]{16,})(?: [eE]{16,})*$",
flags: "",
args: []
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const binaryArray = [];
for (const char of input) {
if (char === " ") {
binaryArray.push(...[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]);
} else {
binaryArray.push(char === "e" ? 1 : 0);
}
}
const byteArray = [];
for (let i = 0; i < binaryArray.length; i += 16) {
byteArray.push(binaryArray.slice(i, i + 16).join(""));
}
return byteArray.map(byte =>
String.fromCharCode(parseInt(byte, 2))
).join("");
}
}
export default CetaceanCipherDecode;

View file

@ -0,0 +1,51 @@
/**
* @author dolphinOnKeys [robin@weird.io]
* @copyright Crown Copyright 2022
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import {toBinary} from "../lib/Binary.mjs";
/**
* Cetacean Cipher Encode operation
*/
class CetaceanCipherEncode extends Operation {
/**
* CetaceanCipherEncode constructor
*/
constructor() {
super();
this.name = "Cetacean Cipher Encode";
this.module = "Ciphers";
this.description = "Converts any input into Cetacean Cipher. <br/><br/>e.g. <code>hi</code> becomes <code>EEEEEEEEEeeEeEEEEEEEEEEEEeeEeEEe</code>";
this.infoURL = "https://hitchhikers.fandom.com/wiki/Dolphins";
this.inputType = "string";
this.outputType = "string";
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const result = [];
const charArray = input.split("");
charArray.map(character => {
if (character === " ") {
result.push(character);
} else {
const binaryArray = toBinary(character.charCodeAt(0), "None", 16).split("");
result.push(binaryArray.map(str => str === "1" ? "e" : "E").join(""));
}
});
return result.join("");
}
}
export default CetaceanCipherEncode;

View file

@ -38,7 +38,7 @@ class ExtractFiles extends Operation {
<li>
${supportedExts.join("</li><li>")}
</li>
</ul>`;
</ul>Minimum File Size can be used to prune small false positives.`;
this.infoURL = "https://forensicswiki.xyz/wiki/index.php?title=File_Carving";
this.inputType = "ArrayBuffer";
this.outputType = "List<File>";
@ -54,6 +54,11 @@ class ExtractFiles extends Operation {
name: "Ignore failed extractions",
type: "boolean",
value: true
},
{
name: "Minimum File Size",
type: "number",
value: 100
}
]);
}
@ -66,6 +71,7 @@ class ExtractFiles extends Operation {
run(input, args) {
const bytes = new Uint8Array(input),
categories = [],
minSize = args.pop(1),
ignoreFailedExtractions = args.pop(1);
args.forEach((cat, i) => {
@ -80,7 +86,9 @@ class ExtractFiles extends Operation {
const errors = [];
detectedFiles.forEach(detectedFile => {
try {
files.push(extractFile(bytes, detectedFile.fileDetails, detectedFile.offset));
const file = extractFile(bytes, detectedFile.fileDetails, detectedFile.offset);
if (file.size >= minSize)
files.push(file);
} catch (err) {
if (!ignoreFailedExtractions && err.message.indexOf("No extraction algorithm available") < 0) {
errors.push(

View file

@ -65,12 +65,21 @@ class Fork extends Operation {
if (input)
inputs = input.split(splitDelim);
// Set to 1 as if we are here, then there is one, the current one.
let numOp = 1;
// Create subOpList for each tranche to operate on
// (all remaining operations unless we encounter a Merge)
// all remaining operations unless we encounter a Merge
for (i = state.progress + 1; i < opList.length; i++) {
if (opList[i].name === "Merge" && !opList[i].disabled) {
numOp--;
if (numOp === 0 || opList[i].ingValues[0])
break;
else
// Not this Fork's Merge.
subOpList.push(opList[i]);
} else {
if (opList[i].name === "Fork" || opList[i].name === "Subsection")
numOp++;
subOpList.push(opList[i]);
}
}

View file

@ -32,7 +32,12 @@ class FromBase45 extends Operation {
name: "Alphabet",
type: "string",
value: ALPHABET
}
},
{
name: "Remove non-alphabet chars",
type: "boolean",
value: true
},
];
this.highlight = highlightFromBase45;
@ -46,10 +51,17 @@ class FromBase45 extends Operation {
*/
run(input, args) {
if (!input) return [];
const alphabet = Utils.expandAlphRange(args[0]);
const alphabet = Utils.expandAlphRange(args[0]).join("");
const removeNonAlphChars = args[1];
const res = [];
// Remove non-alphabet characters
if (removeNonAlphChars) {
const re = new RegExp("[^" + alphabet.replace(/[[\]\\\-^$]/g, "\\$&") + "]", "g");
input = input.replace(re, "");
}
for (const triple of Utils.chunked(input, 3)) {
triple.reverse();
let b = 0;

View file

@ -32,6 +32,40 @@ class FromBase85 extends Operation {
type: "editableOption",
value: ALPHABET_OPTIONS
},
{
name: "Remove non-alphabet chars",
type: "boolean",
value: true
},
];
this.checks = [
{
pattern:
"^\\s*(?:<~)?" + // Optional whitespace and starting marker
"[\\s!-uz]*" + // Any amount of base85 characters and whitespace
"[!-uz]{15}" + // At least 15 continoues base85 characters without whitespace
"[\\s!-uz]*" + // Any amount of base85 characters and whitespace
"(?:~>)?\\s*$", // Optional ending marker and whitespace
args: ["!-u"],
},
{
pattern:
"^" +
"[\\s0-9a-zA-Z.\\-:+=^!/*?&<>()[\\]{}@%$#]*" +
"[0-9a-zA-Z.\\-:+=^!/*?&<>()[\\]{}@%$#]{15}" + // At least 15 continoues base85 characters without whitespace
"[\\s0-9a-zA-Z.\\-:+=^!/*?&<>()[\\]{}@%$#]*" +
"$",
args: ["0-9a-zA-Z.\\-:+=^!/*?&<>()[]{}@%$#"],
},
{
pattern:
"^" +
"[\\s0-9A-Za-z!#$%&()*+\\-;<=>?@^_`{|}~]*" +
"[0-9A-Za-z!#$%&()*+\\-;<=>?@^_`{|}~]{15}" + // At least 15 continoues base85 characters without whitespace
"[\\s0-9A-Za-z!#$%&()*+\\-;<=>?@^_`{|}~]*" +
"$",
args: ["0-9A-Za-z!#$%&()*+\\-;<=>?@^_`{|}~"],
},
];
}
@ -43,6 +77,7 @@ class FromBase85 extends Operation {
run(input, args) {
const alphabet = Utils.expandAlphRange(args[0]).join(""),
encoding = alphabetName(alphabet),
removeNonAlphChars = args[1],
result = [];
if (alphabet.length !== 85 ||
@ -50,11 +85,18 @@ class FromBase85 extends Operation {
throw new OperationError("Alphabet must be of length 85");
}
if (input.length === 0) return [];
const matches = input.match(/<~(.+?)~>/);
// Remove delimiters if present
const matches = input.match(/^<~(.+?)~>$/);
if (matches !== null) input = matches[1];
// Remove non-alphabet characters
if (removeNonAlphChars) {
const re = new RegExp("[^" + alphabet.replace(/[[\]\\\-^$]/g, "\\$&") + "]", "g");
input = input.replace(re, "");
}
if (input.length === 0) return [];
let i = 0;
let block, blockBytes;
while (i < input.length) {
@ -69,7 +111,7 @@ class FromBase85 extends Operation {
.map((chr, idx) => {
const digit = alphabet.indexOf(chr);
if (digit < 0 || digit > 84) {
throw `Invalid character '${chr}' at index ${idx}`;
throw `Invalid character '${chr}' at index ${i + idx}`;
}
return digit;
});

View file

@ -0,0 +1,57 @@
/**
* @author n1073645 [n1073645@gmail.com]
* @copyright Crown Copyright 2020
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import * as LS47 from "../lib/LS47.mjs";
/**
* LS47 Decrypt operation
*/
class LS47Decrypt extends Operation {
/**
* LS47Decrypt constructor
*/
constructor() {
super();
this.name = "LS47 Decrypt";
this.module = "Crypto";
this.description = "This is a slight improvement of the ElsieFour cipher as described by Alan Kaminsky. We use 7x7 characters instead of original (barely fitting) 6x6, to be able to encrypt some structured information. We also describe a simple key-expansion algorithm, because remembering passwords is popular. Similar security considerations as with ElsieFour hold.<br>The LS47 alphabet consists of following characters: <code>_abcdefghijklmnopqrstuvwxyz.0123456789,-+*/:?!'()</code><br>An LS47 key is a permutation of the alphabet that is then represented in a 7x7 grid used for the encryption or decryption.";
this.infoURL = "https://github.com/exaexa/ls47";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
name: "Password",
type: "string",
value: ""
},
{
name: "Padding",
type: "number",
value: 10
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
this.paddingSize = parseInt(args[1], 10);
LS47.initTiles();
const key = LS47.deriveKey(args[0]);
return LS47.decryptPad(key, input, this.paddingSize);
}
}
export default LS47Decrypt;

View file

@ -0,0 +1,62 @@
/**
* @author n1073645 [n1073645@gmail.com]
* @copyright Crown Copyright 2020
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import * as LS47 from "../lib/LS47.mjs";
/**
* LS47 Encrypt operation
*/
class LS47Encrypt extends Operation {
/**
* LS47Encrypt constructor
*/
constructor() {
super();
this.name = "LS47 Encrypt";
this.module = "Crypto";
this.description = "This is a slight improvement of the ElsieFour cipher as described by Alan Kaminsky. We use 7x7 characters instead of original (barely fitting) 6x6, to be able to encrypt some structured information. We also describe a simple key-expansion algorithm, because remembering passwords is popular. Similar security considerations as with ElsieFour hold.<br>The LS47 alphabet consists of following characters: <code>_abcdefghijklmnopqrstuvwxyz.0123456789,-+*/:?!'()</code><br>A LS47 key is a permutation of the alphabet that is then represented in a 7x7 grid used for the encryption or decryption.";
this.infoURL = "https://github.com/exaexa/ls47";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
name: "Password",
type: "string",
value: ""
},
{
name: "Padding",
type: "number",
value: 10
},
{
name: "Signature",
type: "string",
value: ""
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
this.paddingSize = parseInt(args[1], 10);
LS47.initTiles();
const key = LS47.deriveKey(args[0]);
return LS47.encryptPad(key, input, args[2], this.paddingSize);
}
}
export default LS47Encrypt;

View file

@ -0,0 +1,55 @@
/**
* @author crespyl [peter@crespyl.net]
* @copyright Peter Jacobs 2021
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import {COMPRESSION_OUTPUT_FORMATS, COMPRESSION_FUNCTIONS} from "../lib/LZString.mjs";
/**
* LZString Compress operation
*/
class LZStringCompress extends Operation {
/**
* LZStringCompress constructor
*/
constructor() {
super();
this.name = "LZString Compress";
this.module = "Compression";
this.description = "Compress the input with lz-string.";
this.infoURL = "https://pieroxy.net/blog/pages/lz-string/index.html";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
name: "Compression Format",
type: "option",
defaultIndex: 0,
value: COMPRESSION_OUTPUT_FORMATS
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const compress = COMPRESSION_FUNCTIONS[args[0]];
if (compress) {
return compress(input);
} else {
throw new OperationError("Unable to find compression function");
}
}
}
export default LZStringCompress;

View file

@ -0,0 +1,56 @@
/**
* @author crespyl [peter@crespyl.net]
* @copyright Peter Jacobs 2021
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import {COMPRESSION_OUTPUT_FORMATS, DECOMPRESSION_FUNCTIONS} from "../lib/LZString.mjs";
/**
* LZString Decompress operation
*/
class LZStringDecompress extends Operation {
/**
* LZStringDecompress constructor
*/
constructor() {
super();
this.name = "LZString Decompress";
this.module = "Compression";
this.description = "Decompresses data that was compressed with lz-string.";
this.infoURL = "https://pieroxy.net/blog/pages/lz-string/index.html";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
name: "Compression Format",
type: "option",
defaultIndex: 0,
value: COMPRESSION_OUTPUT_FORMATS
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const decompress = DECOMPRESSION_FUNCTIONS[args[0]];
if (decompress) {
return decompress(input);
} else {
throw new OperationError("Unable to find decompression function");
}
}
}
export default LZStringDecompress;

View file

@ -20,10 +20,16 @@ class Merge extends Operation {
this.name = "Merge";
this.flowControl = true;
this.module = "Default";
this.description = "Consolidate all branches back into a single trunk. The opposite of Fork.";
this.description = "Consolidate all branches back into a single trunk. The opposite of Fork. Unticking the Merge All checkbox will only consolidate all branches up to the nearest Fork/Subsection.";
this.inputType = "string";
this.outputType = "string";
this.args = [];
this.args = [
{
name: "Merge All",
type: "boolean",
value: true,
}
];
}
/**

View file

@ -0,0 +1,133 @@
/**
* @author n1073645 [n1073645@gmail.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
/**
* P-list Viewer operation
*/
class PlistViewer extends Operation {
/**
* PlistViewer constructor
*/
constructor() {
super();
this.name = "P-list Viewer";
this.module = "Default";
this.description = "In the macOS, iOS, NeXTSTEP, and GNUstep programming frameworks, property list files are files that store serialized objects. Property list files use the filename extension .plist, and thus are often referred to as p-list files.<br><br>This operation displays plist files in a human readable format.";
this.infoURL = "https://wikipedia.org/wiki/Property_list";
this.inputType = "string";
this.outputType = "string";
this.args = [];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
// Regexes are designed to transform the xml format into a more readable string format.
input = input.slice(input.indexOf("<plist"))
.replace(/<plist.+>/g, "plist => ")
.replace(/<dict>/g, "{")
.replace(/<\/dict>/g, "}")
.replace(/<array>/g, "[")
.replace(/<\/array>/g, "]")
.replace(/<key>.+<\/key>/g, m => `${m.slice(5, m.indexOf(/<\/key>/g)-5)}\t=> `)
.replace(/<real>.+<\/real>/g, m => `${m.slice(6, m.indexOf(/<\/real>/g)-6)}\n`)
.replace(/<string>.+<\/string>/g, m => `"${m.slice(8, m.indexOf(/<\/string>/g)-8)}"\n`)
.replace(/<integer>.+<\/integer>/g, m => `${m.slice(9, m.indexOf(/<\/integer>/g)-9)}\n`)
.replace(/<false\/>/g, m => "false")
.replace(/<true\/>/g, m => "true")
.replace(/<\/plist>/g, "/plist")
.replace(/<date>.+<\/date>/g, m => `${m.slice(6, m.indexOf(/<\/integer>/g)-6)}`)
.replace(/<data>(\s|.)+?<\/data>/g, m => `${m.slice(6, m.indexOf(/<\/data>/g)-6)}`)
.replace(/[ \t\r\f\v]/g, "");
/**
* Depending on the type of brace, it will increment the depth and amount of arrays accordingly.
*
* @param {string} elem
* @param {array} vals
* @param {number} offset
*/
function braces(elem, vals, offset) {
const temp = vals.indexOf(elem);
if (temp !== -1) {
depthCount += offset;
if (temp === 1)
arrCount += offset;
}
}
let result = "";
let arrCount = 0;
let depthCount = 0;
/**
* Formats the input after the regex has replaced all of the relevant parts.
*
* @param {array} input
* @param {number} index
*/
function printIt(input, index) {
if (!(input.length))
return;
let temp = "";
const origArr = arrCount;
let currElem = input[0];
// If the current position points at a larger dynamic structure.
if (currElem.indexOf("=>") !== -1) {
// If the LHS also points at a larger structure (nested plists in a dictionary).
if (input[1].indexOf("=>") !== -1)
temp = currElem.slice(0, -2) + " => " + input[1].slice(0, -2) + " =>\n";
else
temp = currElem.slice(0, -2) + " => " + input[1] + "\n";
input = input.slice(1);
} else {
// Controls the tab depth for how many closing braces there have been.
braces(currElem, ["}", "]"], -1);
// Has to be here since the formatting breaks otherwise.
temp = currElem + "\n";
}
currElem = input[0];
// Tab out to the correct distance.
result += ("\t".repeat(depthCount));
// If it is enclosed in an array show index.
if (arrCount > 0 && currElem !== "]")
result += index.toString() + " => ";
result += temp;
// Controls the tab depth for how many opening braces there have been.
braces(currElem, ["{", "["], 1);
// If there has been a new array then reset index.
if (arrCount > origArr)
return printIt(input.slice(1), 0);
return printIt(input.slice(1), ++index);
}
input = input.split("\n").filter(e => e !== "");
printIt(input, 0);
return result;
}
}
export default PlistViewer;

View file

@ -0,0 +1,102 @@
/**
* @author MikeCAT
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs";
/**
* ROT13 Brute Force operation.
*/
class ROT13BruteForce extends Operation {
/**
* ROT13BruteForce constructor
*/
constructor() {
super();
this.name = "ROT13 Brute Force";
this.module = "Default";
this.description = "Try all meaningful amounts for ROT13.<br><br>Optionally you can enter your known plaintext (crib) to filter the result.";
this.infoURL = "https://wikipedia.org/wiki/ROT13";
this.inputType = "byteArray";
this.outputType = "string";
this.args = [
{
name: "Rotate lower case chars",
type: "boolean",
value: true
},
{
name: "Rotate upper case chars",
type: "boolean",
value: true
},
{
name: "Rotate numbers",
type: "boolean",
value: false
},
{
name: "Sample length",
type: "number",
value: 100
},
{
name: "Sample offset",
type: "number",
value: 0
},
{
name: "Print amount",
type: "boolean",
value: true
},
{
name: "Crib (known plaintext string)",
type: "string",
value: ""
}
];
}
/**
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const [rotateLower, rotateUpper, rotateNum, sampleLength, sampleOffset, printAmount, crib] = args;
const sample = input.slice(sampleOffset, sampleOffset + sampleLength);
const cribLower = crib.toLowerCase();
const lowerStart = "a".charCodeAt(0), upperStart = "A".charCodeAt(0), numStart = "0".charCodeAt(0);
const result = [];
for (let amount = 1; amount < 26; amount++) {
const rotated = sample.slice();
for (let i = 0; i < rotated.length; i++) {
if (rotateLower && lowerStart <= rotated[i] && rotated[i] < lowerStart + 26) {
rotated[i] = (rotated[i] - lowerStart + amount) % 26 + lowerStart;
} else if (rotateUpper && upperStart <= rotated[i] && rotated[i] < upperStart + 26) {
rotated[i] = (rotated[i] - upperStart + amount) % 26 + upperStart;
} else if (rotateNum && numStart <= rotated[i] && rotated[i] < numStart + 10) {
rotated[i] = (rotated[i] - numStart + amount) % 10 + numStart;
}
}
const rotatedString = Utils.byteArrayToUtf8(rotated);
if (rotatedString.toLowerCase().indexOf(cribLower) >= 0) {
const rotatedStringPrintable = Utils.printable(rotatedString, false);
if (printAmount) {
const amountStr = "Amount = " + (" " + amount).slice(-2) + ": ";
result.push(amountStr + rotatedStringPrintable);
} else {
result.push(rotatedStringPrintable);
}
}
}
return result.join("\n");
}
}
export default ROT13BruteForce;

View file

@ -0,0 +1,82 @@
/**
* @author MikeCAT
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs";
/**
* ROT47 Brute Force operation.
*/
class ROT47BruteForce extends Operation {
/**
* ROT47BruteForce constructor
*/
constructor() {
super();
this.name = "ROT47 Brute Force";
this.module = "Default";
this.description = "Try all meaningful amounts for ROT47.<br><br>Optionally you can enter your known plaintext (crib) to filter the result.";
this.infoURL = "https://wikipedia.org/wiki/ROT13#Variants";
this.inputType = "byteArray";
this.outputType = "string";
this.args = [
{
name: "Sample length",
type: "number",
value: 100
},
{
name: "Sample offset",
type: "number",
value: 0
},
{
name: "Print amount",
type: "boolean",
value: true
},
{
name: "Crib (known plaintext string)",
type: "string",
value: ""
}
];
}
/**
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const [sampleLength, sampleOffset, printAmount, crib] = args;
const sample = input.slice(sampleOffset, sampleOffset + sampleLength);
const cribLower = crib.toLowerCase();
const result = [];
for (let amount = 1; amount < 94; amount++) {
const rotated = sample.slice();
for (let i = 0; i < rotated.length; i++) {
if (33 <= rotated[i] && rotated[i] <= 126) {
rotated[i] = (rotated[i] - 33 + amount) % 94 + 33;
}
}
const rotatedString = Utils.byteArrayToUtf8(rotated);
if (rotatedString.toLowerCase().indexOf(cribLower) >= 0) {
const rotatedStringPrintable = Utils.printable(rotatedString, false);
if (printAmount) {
const amountStr = "Amount = " + (" " + amount).slice(-2) + ": ";
result.push(amountStr + rotatedStringPrintable);
} else {
result.push(rotatedStringPrintable);
}
}
}
return result.join("\n");
}
}
export default ROT47BruteForce;

View file

@ -0,0 +1,123 @@
/**
* @author Daniel Temkin [http://danieltemkin.com]
* @author Thomas Leplus [https://www.leplus.org]
* @copyright Crown Copyright 2021
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
/**
* ROT8000 operation.
*/
class ROT8000 extends Operation {
/**
* ROT8000 constructor
*/
constructor() {
super();
this.name = "ROT8000";
this.module = "Default";
this.description = "The simple Caesar-cypher encryption that replaces each Unicode character with the one 0x8000 places forward or back along the alphabet.";
this.infoURL = "https://rot8000.com/info";
this.inputType = "string";
this.outputType = "string";
this.args = [];
}
/**
* @param {byteArray} input
* @param {Object[]} args
* @returns {byteArray}
*/
run(input, args) {
// Inspired from https://github.com/rottytooth/rot8000/blob/main/rot8000.js
// these come from the valid-code-point-transitions.json file generated from the c# proj
// this is done bc: 1) don't trust JS's understanging of surrogate pairs and 2) consistency with original rot8000
const validCodePoints = {
"33": true,
"127": false,
"161": true,
"5760": false,
"5761": true,
"8192": false,
"8203": true,
"8232": false,
"8234": true,
"8239": false,
"8240": true,
"8287": false,
"8288": true,
"12288": false,
"12289": true,
"55296": false,
"57344": true
};
const bmpSize = 0x10000;
const rotList = {}; // the mapping of char to rotated char
const hiddenBlocks = [];
let startBlock = 0;
for (const key in validCodePoints) {
if (Object.prototype.hasOwnProperty.call(validCodePoints, key)) {
if (validCodePoints[key] === true)
hiddenBlocks.push({ start: startBlock, end: parseInt(key, 10) - 1 });
else
startBlock = parseInt(key, 10);
}
}
const validIntList = []; // list of all valid chars
let currValid = false;
for (let i = 0; i < bmpSize; i++) {
if (validCodePoints[i] !== undefined) {
currValid = validCodePoints[i];
}
if (currValid) validIntList.push(i);
}
const rotateNum = Object.keys(validIntList).length / 2;
// go through every valid char and find its match
for (let i = 0; i < validIntList.length; i++) {
rotList[String.fromCharCode(validIntList[i])] =
String.fromCharCode(validIntList[(i + rotateNum) % (rotateNum * 2)]);
}
let output = "";
for (let count = 0; count < input.length; count++) {
// if it is not in the mappings list, just add it directly (no rotation)
if (rotList[input[count]] === undefined) {
output += input[count];
continue;
}
// otherwise, rotate it and add it to the string
output += rotList[input[count]];
}
return output;
}
/**
* Highlight ROT8000
*
* @param {Object[]} pos
* @param {number} pos[].start
* @param {number} pos[].end
* @param {Object[]} args
* @returns {Object[]} pos
*/
highlight(pos, args) {
return pos;
}
/**
* Highlight ROT8000 in reverse
*
* @param {Object[]} pos
* @param {number} pos[].start
* @param {number} pos[].end
* @param {Object[]} args
* @returns {Object[]} pos
*/
highlightReverse(pos, args) {
return pos;
}
}
export default ROT8000;

View file

@ -22,7 +22,7 @@ class Subsection extends Operation {
this.name = "Subsection";
this.flowControl = true;
this.module = "Default";
this.description = "Select a part of the input data using a regular expression (regex), and run all subsequent operations on each match separately.<br><br>You can use up to one capture group, where the recipe will only be run on the data in the capture group. If there's more than one capture group, only the first one will be operated on.";
this.description = "Select a part of the input data using a regular expression (regex), and run all subsequent operations on each match separately.<br><br>You can use up to one capture group, where the recipe will only be run on the data in the capture group. If there's more than one capture group, only the first one will be operated on.<br><br>Use the Merge operation to reset the effects of subsection.";
this.infoURL = "";
this.inputType = "string";
this.outputType = "string";
@ -67,12 +67,21 @@ class Subsection extends Operation {
subOpList = [];
if (input && section !== "") {
// Set to 1 as if we are here, then there is one, the current one.
let numOp = 1;
// Create subOpList for each tranche to operate on
// all remaining operations unless we encounter a Merge
for (let i = state.progress + 1; i < opList.length; i++) {
if (opList[i].name === "Merge" && !opList[i].disabled) {
numOp--;
if (numOp === 0 || opList[i].ingValues[0])
break;
else
// Not this subsection's Merge.
subOpList.push(opList[i]);
} else {
if (opList[i].name === "Fork" || opList[i].name === "Subsection")
numOp++;
subOpList.push(opList[i]);
}
}

View file

@ -186,7 +186,7 @@ div.toggle-string {
}
.ingredients .dropdown-toggle-split {
height: 41px !important;
height: 40px !important;
}
.boolean-arg {

View file

@ -249,6 +249,7 @@ module.exports = {
// testOp(browser, "RIPEMD", "test input", "test_output");
// testOp(browser, "ROT13", "test input", "test_output");
// testOp(browser, "ROT47", "test input", "test_output");
// testOp(browser, "ROT8000", "test input", "test_output");
// testOp(browser, "Rail Fence Cipher Decode", "test input", "test_output");
// testOp(browser, "Rail Fence Cipher Encode", "test input", "test_output");
// testOp(browser, "Randomize Colour Palette", "test input", "test_output");

View file

@ -12,6 +12,7 @@
import Chef from "../../src/core/Chef.mjs";
import Utils from "../../src/core/Utils.mjs";
import cliProgress from "cli-progress";
import log from "loglevel";
/**
* Object to store and run the list of tests.
@ -50,6 +51,9 @@ class TestRegister {
* Runs all the tests in the register.
*/
async runTests () {
// Turn off logging to avoid messy errors
log.setLevel("silent", false);
const progBar = new cliProgress.SingleBar({
format: formatter,
stopOnComplete: true
@ -84,7 +88,17 @@ class TestRegister {
if (result.error) {
if (test.expectedError) {
if (result.error.displayStr === test.expectedOutput) {
ret.status = "passing";
} else {
ret.status = "failing";
ret.output = [
"Expected",
"\t" + test.expectedOutput.replace(/\n/g, "\n\t"),
"Received",
"\t" + result.error.displayStr.replace(/\n/g, "\n\t"),
].join("\n");
}
} else {
ret.status = "erroring";
ret.output = result.error.displayStr;
@ -118,6 +132,9 @@ class TestRegister {
progBar.increment();
}
// Turn logging back on
log.setLevel("info", false);
return testResults;
}

View file

@ -24,9 +24,12 @@ import "./tests/Base45.mjs";
import "./tests/Base58.mjs";
import "./tests/Base64.mjs";
import "./tests/Base62.mjs";
import "./tests/Base85.mjs";
import "./tests/BitwiseOp.mjs";
import "./tests/ByteRepr.mjs";
import "./tests/CartesianProduct.mjs";
import "./tests/CetaceanCipherEncode.mjs";
import "./tests/CetaceanCipherDecode.mjs";
import "./tests/CharEnc.mjs";
import "./tests/ChangeIPFormat.mjs";
import "./tests/Charts.mjs";
@ -114,6 +117,10 @@ import "./tests/HASSH.mjs";
import "./tests/GetAllCasings.mjs";
import "./tests/SIGABA.mjs";
import "./tests/ELFInfo.mjs";
import "./tests/Subsection.mjs";
import "./tests/CaesarBoxCipher.mjs";
import "./tests/LS47.mjs";
import "./tests/LZString.mjs";
// Cannot test operations that use the File type yet

View file

@ -0,0 +1,48 @@
/**
* Base85 tests
*
* @author john19696
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
// Example from Wikipedia
const wpExample = "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.";
// Escape newline, quote & backslash
const wpOutput = "9jqo^BlbD-BleB1DJ+*+F(f,q/0JhKF<GL>Cj@.4Gp$d7F!,L7@<6@)/0JDEF<G%<+EV:2F!,O<\
DJ+*.@<*K0@<6L(Df-\\0Ec5e;DffZ(EZee.Bl.9pF\"AGXBPCsi+DGm>@3BB/F*&OCAfu2/AKYi(\
DIb:@FD,*)+C]U=@3BN#EcYf8ATD3s@q?d$AftVqCh[NqF<G:8+EV:.+Cf>-FD5W8ARlolDIal(\
DId<j@<?3r@:F%a+D58'ATD4$Bl@l3De:,-DJs`8ARoFb/0JMK@qB4^F!,R<AKZ&-DfTqBG%G>u\
D.RTpAKYo'+CT/5+Cei#DII?(E,9)oF*2M7/c";
TestRegister.addTests([
{
name: "To Base85",
input: wpExample,
expectedOutput: wpOutput,
recipeConfig: [
{ "op": "To Base85",
"args": ["!-u"] }
]
},
{
name: "From Base85",
input: wpOutput + "\n",
expectedOutput: wpExample,
recipeConfig: [
{ "op": "From Base85",
"args": ["!-u", true] }
]
},
{
name: "From Base85",
input: wpOutput + "v",
expectedError: true,
expectedOutput: "From Base85 - Invalid character 'v' at index 337",
recipeConfig: [
{ "op": "From Base85",
"args": ["!-u", false] }
]
},
]);

View file

@ -0,0 +1,45 @@
/**
* Caesar Box Cipher tests.
*
* @author n1073645 [n1073645@gmail.com]
*
* @copyright Crown Copyright 2020
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "Caesar Box Cipher: nothing",
input: "",
expectedOutput: "",
recipeConfig: [
{
op: "Caesar Box Cipher",
args: ["1"],
},
],
},
{
name: "Caesar Box Cipher: Hello World!",
input: "Hello World!",
expectedOutput: "Hlodeor!lWl",
recipeConfig: [
{
op: "Caesar Box Cipher",
args: ["3"],
},
],
},
{
name: "Caesar Box Cipher: Hello World!",
input: "Hlodeor!lWl",
expectedOutput: "HelloWorld!",
recipeConfig: [
{
op: "Caesar Box Cipher",
args: ["4"],
},
],
}
]);

View file

@ -0,0 +1,22 @@
/**
* CetaceanCipher Encode tests
*
* @author dolphinOnKeys
* @copyright Crown Copyright 2022
* @licence Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "Cetacean Cipher Decode",
input: "EEEEEEEEEeeEEEEe EEEEEEEEEeeEEEeE EEEEEEEEEeeEEEee EEeeEEEEEeeEEeee",
expectedOutput: "a b c で",
recipeConfig: [
{
op: "Cetacean Cipher Decode",
args: []
},
],
}
]);

View file

@ -0,0 +1,22 @@
/**
* CetaceanCipher Encode tests
*
* @author dolphinOnKeys
* @copyright Crown Copyright 2022
* @licence Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "Cetacean Cipher Encode",
input: "a b c で",
expectedOutput: "EEEEEEEEEeeEEEEe EEEEEEEEEeeEEEeE EEEEEEEEEeeEEEee EEeeEEEEEeeEEeee",
recipeConfig: [
{
op: "Cetacean Cipher Encode",
args: []
},
],
}
]);

View file

@ -31,7 +31,7 @@ TestRegister.addTests([
},
{
op: "Merge",
args: [],
args: [true],
},
],
},
@ -50,7 +50,7 @@ TestRegister.addTests([
},
{
op: "Merge",
args: [],
args: [true],
},
],
},
@ -66,5 +66,16 @@ TestRegister.addTests([
{"op": "Label", "args": ["skipReturn"]},
{"op": "To Base64", "args": ["A-Za-z0-9+/="]}
]
}
},
{
name: "Fork, Partial Merge",
input: "Hello World",
expectedOutput: "48656c6c6f 576f726c64",
recipeConfig: [
{ "op": "Fork", "args": [" ", " ", false] },
{ "op": "Fork", "args": ["l", "l", false] },
{ "op": "Merge", "args": [false] },
{ "op": "To Hex", "args": ["None", 0] },
]
},
]);

View file

@ -0,0 +1,45 @@
/**
* LS47 tests.
*
* @author n1073645 [n1073645@gmail.com]
*
* @copyright Crown Copyright 2020
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "LS47 Encrypt",
input: "thequickbrownfoxjumped",
expectedOutput: "(,t74ci78cp/8trx*yesu:alp1wqy",
recipeConfig: [
{
op: "LS47 Encrypt",
args: ["helloworld", 0, "test"],
},
],
},
{
name: "LS47 Decrypt",
input: "(,t74ci78cp/8trx*yesu:alp1wqy",
expectedOutput: "thequickbrownfoxjumped---test",
recipeConfig: [
{
op: "LS47 Decrypt",
args: ["helloworld", 0],
},
],
},
{
name: "LS47 Encrypt",
input: "thequickbrownfoxjumped",
expectedOutput: "Letter H is not included in LS47",
recipeConfig: [
{
op: "LS47 Encrypt",
args: ["Helloworld", 0, "test"],
},
],
}
]);

View file

@ -0,0 +1,33 @@
/**
* LZString tests.
*
* @author crespyl [peter@crespyl.net]
* @copyright Peter Jacobs 2021
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "LZString Compress To Base64",
input: "hello world",
expectedOutput: "BYUwNmD2AEDukCcwBMg=",
recipeConfig: [
{
"op": "LZString Compress",
"args": ["Base64"]
}
],
},
{
name: "LZString Decompress From Base64",
input: "BYUwNmD2AEDukCcwBMg=",
expectedOutput: "hello world",
recipeConfig: [
{
"op": "LZString Decompress",
"args": ["Base64"]
}
],
}
]);

View file

@ -212,4 +212,37 @@ TestRegister.addTests([
},
],
},
{
name: "ROT8000: nothing",
input: "",
expectedOutput: "",
recipeConfig: [
{
op: "ROT8000",
args: []
},
],
},
{
name: "ROT8000: normal",
input: "The Quick Brown Fox Jumped Over The Lazy Dog.",
expectedOutput: "籝籱籮 籚籾籲籬籴 籋类籸粀籷 籏籸粁 籓籾籶籹籮籭 籘籿籮类 籝籱籮 籕籪粃粂 籍籸籰簷",
recipeConfig: [
{
op: "ROT8000",
args: []
},
],
},
{
name: "ROT8000: backward",
input: "籝籱籮 籚籾籲籬籴 籋类籸粀籷 籏籸粁 籓籾籶籹籮籭 籘籿籮类 籝籱籮 籕籪粃粂 籍籸籰簷",
expectedOutput: "The Quick Brown Fox Jumped Over The Lazy Dog.",
recipeConfig: [
{
op: "ROT8000",
args: []
},
],
},
]);

View file

@ -0,0 +1,102 @@
/**
* Subsection Tests.
*
* @author n1073645 [n1073645@gmail.com]
* @copyright Crown Copyright 2022
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "Subsection: nothing",
input: "",
expectedOutput: "",
recipeConfig: [
{
"op": "Subsection",
"args": ["", true, true, false],
},
],
},
{
name: "Subsection, Full Merge: nothing",
input: "",
expectedOutput: "",
recipeConfig: [
{
"op": "Subsection",
"args": ["", true, true, false],
},
{
"op": "Merge",
"args": [true],
},
],
},
{
name: "Subsection, Partial Merge: nothing",
input: "",
expectedOutput: "",
recipeConfig: [
{
"op": "Subsection",
"args": ["", true, true, false],
},
{
"op": "Merge",
"args": [false],
},
],
},
{
name: "Subsection, Full Merge: Base64 with Hex",
input: "SGVsbG38675629ybGQ=",
expectedOutput: "Hello World",
recipeConfig: [
{
"op": "Subsection",
"args": ["386756", true, true, false],
},
{
"op": "From Hex",
"args": ["Auto"],
},
{
"op": "Merge",
"args": [true],
},
{
"op": "From Base64",
"args": ["A-Za-z0-9+/=", true, false],
},
],
},
{
name: "Subsection, Partial Merge: Base64 with Hex surrounded by binary data.",
input: "000000000SGVsbG38675629ybGQ=0000000000",
expectedOutput: "000000000Hello World0000000000",
recipeConfig: [
{
"op": "Subsection",
"args": ["SGVsbG38675629ybGQ=", true, true, false],
},
{
"op": "Subsection",
"args": ["386756", true, true, false],
},
{
"op": "From Hex",
"args": ["Auto"],
},
{
"op": "Merge",
"args": [false],
},
{
"op": "From Base64",
"args": ["A-Za-z0-9+/=", true, false],
},
],
},
]);