mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Added alternating caps functionality
This commit is contained in:
parent
d635cca210
commit
95f6c4c5d5
4 changed files with 68 additions and 0 deletions
|
@ -280,6 +280,7 @@
|
||||||
"To Upper case",
|
"To Upper case",
|
||||||
"To Lower case",
|
"To Lower case",
|
||||||
"Swap case",
|
"Swap case",
|
||||||
|
"Alternating Caps",
|
||||||
"To Case Insensitive Regex",
|
"To Case Insensitive Regex",
|
||||||
"From Case Insensitive Regex",
|
"From Case Insensitive Regex",
|
||||||
"Add line numbers",
|
"Add line numbers",
|
||||||
|
|
47
src/core/operations/AlternatingCaps.mjs
Normal file
47
src/core/operations/AlternatingCaps.mjs
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/**
|
||||||
|
* @author sw5678
|
||||||
|
* @copyright Crown Copyright 2023
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Operation from "../Operation.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alternating caps operation
|
||||||
|
*/
|
||||||
|
class AlternatingCaps extends Operation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AlternatingCaps constructor
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.name = "Alternating Caps";
|
||||||
|
this.module = "Default";
|
||||||
|
this.description = "Alternating caps, also known as studly caps, sticky caps, or spongecase is a form of text notation in which the capitalization of letters varies by some pattern, or arbitrarily. An example of this would be spelling 'alternative caps' as 'aLtErNaTiNg CaPs'.";
|
||||||
|
this.infoURL = "https://en.wikipedia.org/wiki/Alternating_caps";
|
||||||
|
this.inputType = "string";
|
||||||
|
this.outputType = "string";
|
||||||
|
this.args= [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
run(input, args) {
|
||||||
|
let output = "";
|
||||||
|
for (let i = 0; i < input.length; i++) {
|
||||||
|
if (i % 2 === 0) {
|
||||||
|
output += input[i].toLowerCase();
|
||||||
|
} else {
|
||||||
|
output += input[i].toUpperCase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AlternatingCaps;
|
|
@ -18,6 +18,7 @@ import {
|
||||||
|
|
||||||
import TestRegister from "../lib/TestRegister.mjs";
|
import TestRegister from "../lib/TestRegister.mjs";
|
||||||
import "./tests/AESKeyWrap.mjs";
|
import "./tests/AESKeyWrap.mjs";
|
||||||
|
import "./tests/AlternatingCaps.mjs";
|
||||||
import "./tests/AvroToJSON.mjs";
|
import "./tests/AvroToJSON.mjs";
|
||||||
import "./tests/BaconCipher.mjs";
|
import "./tests/BaconCipher.mjs";
|
||||||
import "./tests/Base45.mjs";
|
import "./tests/Base45.mjs";
|
||||||
|
|
19
tests/operations/tests/AlternatingCaps.mjs
Normal file
19
tests/operations/tests/AlternatingCaps.mjs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/* @author sw5678
|
||||||
|
* @copyright Crown Copyright 2024
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
import TestRegister from "../../lib/TestRegister.mjs";
|
||||||
|
|
||||||
|
TestRegister.addTests([
|
||||||
|
{
|
||||||
|
"name": "AlternatingCaps: Basic Example",
|
||||||
|
"input": "Hello, world!",
|
||||||
|
"expectedOutput": "hElLo, WoRlD!",
|
||||||
|
"recipeConfig": [
|
||||||
|
{
|
||||||
|
"op": "Alternating Caps",
|
||||||
|
"args": []
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
]);
|
Loading…
Add table
Add a link
Reference in a new issue