Skip to content

Commit

Permalink
Merge branch 'caesarBoxCipher' of https://github.com/n1073645/CyberChef
Browse files Browse the repository at this point in the history
  • Loading branch information
n1474335 committed Jul 8, 2022
2 parents 94700da + 667dfd8 commit 99a0a05
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/config/Categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"Bacon Cipher Decode",
"Bifid Cipher Encode",
"Bifid Cipher Decode",
"Caesar Box Cipher",
"Affine Cipher Encode",
"Affine Cipher Decode",
"A1Z26 Cipher Encode",
Expand Down
61 changes: 61 additions & 0 deletions src/core/operations/CaesarBoxCipher.mjs
Original file line number Diff line number Diff line change
@@ -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 = "Caesar Box Encryption uses a box, a rectangle (or a square), or at least a size W caracterizing its width.";
this.infoURL = "https://www.dcode.fr/caesar-box-cipher";
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;
1 change: 1 addition & 0 deletions tests/operations/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ import "./tests/GetAllCasings.mjs";
import "./tests/SIGABA.mjs";
import "./tests/ELFInfo.mjs";
import "./tests/Subsection.mjs";
import "./tests/CaesarBoxCipher.mjs";


// Cannot test operations that use the File type yet
Expand Down
45 changes: 45 additions & 0 deletions tests/operations/tests/CaesarBoxCipher.mjs
Original file line number Diff line number Diff line change
@@ -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"],
},
],
}
]);

0 comments on commit 99a0a05

Please sign in to comment.