Skip to content

Commit 9733bf6

Browse files
committed
Merge branch 'nodejs16' of https://github.com/john19696/CyberChef into john19696-nodejs16
2 parents bc433f0 + c01ce90 commit 9733bf6

File tree

4 files changed

+99
-1
lines changed

4 files changed

+99
-1
lines changed

src/core/config/Categories.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@
230230
"From Case Insensitive Regex",
231231
"Add line numbers",
232232
"Remove line numbers",
233+
"Get All Casings",
233234
"To Table",
234235
"Reverse",
235236
"Sort",
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @author n1073645 [n1073645@gmail.com]
3+
* @copyright Crown Copyright 2020
4+
* @license Apache-2.0
5+
*/
6+
7+
import Operation from "../Operation.mjs";
8+
9+
/**
10+
* Permutate String operation
11+
*/
12+
class GetAllCasings extends Operation {
13+
14+
/**
15+
* GetAllCasings constructor
16+
*/
17+
constructor() {
18+
super();
19+
20+
this.name = "Get All Casings";
21+
this.module = "Default";
22+
this.description = "Outputs all possible casing variations of a string.";
23+
this.infoURL = "";
24+
this.inputType = "string";
25+
this.outputType = "string";
26+
this.args = [];
27+
}
28+
29+
/**
30+
* @param {string} input
31+
* @param {Object[]} args
32+
* @returns {string}
33+
*/
34+
run(input, args) {
35+
const length = input.length;
36+
const max = 1 << length;
37+
input = input.toLowerCase();
38+
let result = "";
39+
40+
for (let i = 0; i < max; i++) {
41+
const temp = input.split("");
42+
for (let j = 0; j < length; j++) {
43+
if (((i >> j) & 1) === 1) {
44+
temp[j] = temp[j].toUpperCase();
45+
}
46+
}
47+
result += temp.join("") + "\n";
48+
}
49+
return result;
50+
}
51+
}
52+
53+
export default GetAllCasings;

tests/operations/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ import "./tests/CBORDecode.mjs";
107107
import "./tests/JA3Fingerprint.mjs";
108108
import "./tests/JA3SFingerprint.mjs";
109109
import "./tests/HASSH.mjs";
110-
110+
import "./tests/GetAllCasings.mjs";
111111

112112
// Cannot test operations that use the File type yet
113113
// import "./tests/SplitColourChannels.mjs";
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* GetAllCasings tests.
3+
*
4+
* @author n1073645 [n1073645@gmail.com]
5+
* @copyright Crown Copyright 2020
6+
* @license Apache-2.0
7+
*/
8+
import TestRegister from "../../lib/TestRegister.mjs";
9+
10+
TestRegister.addTests([
11+
{
12+
name: "All casings of test",
13+
input: "test",
14+
expectedOutput: "test\nTest\ntEst\nTEst\nteSt\nTeSt\ntESt\nTESt\ntesT\nTesT\ntEsT\nTEsT\nteST\nTeST\ntEST\nTEST\n",
15+
recipeConfig: [
16+
{
17+
"op": "Get All Casings",
18+
"args": []
19+
}
20+
]
21+
},
22+
{
23+
name: "All casings of t",
24+
input: "t",
25+
expectedOutput: "t\nT\n",
26+
recipeConfig: [
27+
{
28+
"op": "Get All Casings",
29+
"args": []
30+
}
31+
]
32+
},
33+
{
34+
name: "All casings of null",
35+
input: "",
36+
expectedOutput: "\n",
37+
recipeConfig: [
38+
{
39+
"op": "Get All Casings",
40+
"args": []
41+
}
42+
]
43+
}
44+
]);

0 commit comments

Comments
 (0)