-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'nodejs16' of https://github.com/john19696/CyberChef int…
…o john19696-nodejs16
- Loading branch information
Showing
4 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* @author n1073645 [n1073645@gmail.com] | ||
* @copyright Crown Copyright 2020 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import Operation from "../Operation.mjs"; | ||
|
||
/** | ||
* Permutate String operation | ||
*/ | ||
class GetAllCasings extends Operation { | ||
|
||
/** | ||
* GetAllCasings constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.name = "Get All Casings"; | ||
this.module = "Default"; | ||
this.description = "Outputs all possible casing variations of a string."; | ||
this.infoURL = ""; | ||
this.inputType = "string"; | ||
this.outputType = "string"; | ||
this.args = []; | ||
} | ||
|
||
/** | ||
* @param {string} input | ||
* @param {Object[]} args | ||
* @returns {string} | ||
*/ | ||
run(input, args) { | ||
const length = input.length; | ||
const max = 1 << length; | ||
input = input.toLowerCase(); | ||
let result = ""; | ||
|
||
for (let i = 0; i < max; i++) { | ||
const temp = input.split(""); | ||
for (let j = 0; j < length; j++) { | ||
if (((i >> j) & 1) === 1) { | ||
temp[j] = temp[j].toUpperCase(); | ||
} | ||
} | ||
result += temp.join("") + "\n"; | ||
} | ||
return result; | ||
} | ||
} | ||
|
||
export default GetAllCasings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* GetAllCasings tests. | ||
* | ||
* @author n1073645 [n1073645@gmail.com] | ||
* @copyright Crown Copyright 2020 | ||
* @license Apache-2.0 | ||
*/ | ||
import TestRegister from "../../lib/TestRegister.mjs"; | ||
|
||
TestRegister.addTests([ | ||
{ | ||
name: "All casings of test", | ||
input: "test", | ||
expectedOutput: "test\nTest\ntEst\nTEst\nteSt\nTeSt\ntESt\nTESt\ntesT\nTesT\ntEsT\nTEsT\nteST\nTeST\ntEST\nTEST\n", | ||
recipeConfig: [ | ||
{ | ||
"op": "Get All Casings", | ||
"args": [] | ||
} | ||
] | ||
}, | ||
{ | ||
name: "All casings of t", | ||
input: "t", | ||
expectedOutput: "t\nT\n", | ||
recipeConfig: [ | ||
{ | ||
"op": "Get All Casings", | ||
"args": [] | ||
} | ||
] | ||
}, | ||
{ | ||
name: "All casings of null", | ||
input: "", | ||
expectedOutput: "\n", | ||
recipeConfig: [ | ||
{ | ||
"op": "Get All Casings", | ||
"args": [] | ||
} | ||
] | ||
} | ||
]); |