mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-09 15:55:01 -04:00
Merge ddd6055800
into 54fdc05e3a
This commit is contained in:
commit
79663d2c23
2 changed files with 66 additions and 2 deletions
|
@ -65,7 +65,8 @@
|
||||||
"JSON to CSV",
|
"JSON to CSV",
|
||||||
"Avro to JSON",
|
"Avro to JSON",
|
||||||
"CBOR Encode",
|
"CBOR Encode",
|
||||||
"CBOR Decode"
|
"CBOR Decode",
|
||||||
|
"Inverting characters case"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -221,7 +222,8 @@
|
||||||
"Unicode Text Format",
|
"Unicode Text Format",
|
||||||
"Remove Diacritics",
|
"Remove Diacritics",
|
||||||
"Unescape Unicode Characters",
|
"Unescape Unicode Characters",
|
||||||
"Convert to NATO alphabet"
|
"Convert to NATO alphabet",
|
||||||
|
"Inverting characters case"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
62
src/core/operations/InvertingCharactersCase.mjs
Normal file
62
src/core/operations/InvertingCharactersCase.mjs
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/**
|
||||||
|
* @author Sichej [edoardo.sichelli@gmail.com]
|
||||||
|
* @copyright Crown Copyright 2022
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Operation from "../Operation.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inverting characters case operation
|
||||||
|
*/
|
||||||
|
class InvertingCharactersCase extends Operation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* InvertingCharactersCase constructor
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.name = "Inverting characters case";
|
||||||
|
this.module = "Default";
|
||||||
|
this.description = "Inverting characters case <code>vgHPCYbcyxnLnJqGBwvHBNmGC29TzxrOAw5NlG==</code> becomes <code>VGhpcyBCYXNlNjQgbWVhbnMgc29tZXRoaW5nLg==</code>";
|
||||||
|
this.infoURL = "";
|
||||||
|
this.inputType = "string";
|
||||||
|
this.outputType = "string";
|
||||||
|
this.args = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
run(input, args) {
|
||||||
|
let result = "";
|
||||||
|
for (let i = 0; i < input.length; i++) {
|
||||||
|
result += this.checkAndChangeCase(input[i]);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a character is Uppercase or Lowercase
|
||||||
|
* and returns the opposite
|
||||||
|
*/
|
||||||
|
checkAndChangeCase(character) {
|
||||||
|
try {
|
||||||
|
if (character.charCodeAt(0) > 64 && character.charCodeAt(0) < 91)
|
||||||
|
return character.toLowerCase();
|
||||||
|
else if (character.charCodeAt(0) > 96 && character.charCodeAt(0) < 123)
|
||||||
|
return character.toUpperCase();
|
||||||
|
else
|
||||||
|
return character;
|
||||||
|
} catch (error) {
|
||||||
|
throw new OperationError("Error, something went wrong");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default InvertingCharactersCase;
|
Loading…
Add table
Add a link
Reference in a new issue