mirror of
https://github.com/gchq/CyberChef
synced 2025-01-16 22:43:54 +00:00
Caesar Box Cipher Added
This commit is contained in:
parent
4c3324aea1
commit
3e3c526a62
4 changed files with 108 additions and 0 deletions
|
@ -91,6 +91,7 @@
|
|||
"Bacon Cipher Decode",
|
||||
"Bifid Cipher Encode",
|
||||
"Bifid Cipher Decode",
|
||||
"Caesar Box Cipher",
|
||||
"Affine Cipher Encode",
|
||||
"Affine Cipher Decode",
|
||||
"A1Z26 Cipher Encode",
|
||||
|
|
61
src/core/operations/CaesarBoxCipher.mjs
Normal file
61
src/core/operations/CaesarBoxCipher.mjs
Normal 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 = "";
|
||||
this.infoURL = "";
|
||||
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;
|
|
@ -101,6 +101,7 @@ import "./tests/LuhnChecksum.mjs";
|
|||
import "./tests/CipherSaber2.mjs";
|
||||
import "./tests/Colossus.mjs";
|
||||
import "./tests/ParseObjectIDTimestamp.mjs";
|
||||
import "./tests/CaesarBoxCipher.mjs";
|
||||
|
||||
|
||||
// Cannot test operations that use the File type yet
|
||||
|
|
45
tests/operations/tests/CaesarBoxCipher.mjs
Normal file
45
tests/operations/tests/CaesarBoxCipher.mjs
Normal file
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* Base58 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"],
|
||||
},
|
||||
],
|
||||
}
|
||||
]);
|
Loading…
Reference in a new issue