mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-23 16:26:16 -04:00
Rotate module converted to ESM
4 Ops: - ROT-13 - ROT-47 - Rotate left - Rotate right + module containing common functions
This commit is contained in:
parent
083d2d1cc4
commit
4988ead918
9 changed files with 578 additions and 11 deletions
80
src/core/operations/RotateLeft.mjs
Normal file
80
src/core/operations/RotateLeft.mjs
Normal file
|
@ -0,0 +1,80 @@
|
|||
/**
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2016
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import { rot, rotl, rotlCarry, ROTATE_AMOUNT, ROTATE_CARRY } from "../lib/Rotate";
|
||||
|
||||
/**
|
||||
* Rotate left operation.
|
||||
*/
|
||||
class RotateLeft extends Operation {
|
||||
|
||||
/**
|
||||
* RotateLeft constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Rotate left";
|
||||
this.module = "Default";
|
||||
this.description = "Rotates each byte to the left by the number of bits specified, optionally carrying the excess bits over to the next byte. Currently only supports 8-bit values.";
|
||||
this.inputType = "byteArray";
|
||||
this.outputType = "byteArray";
|
||||
this.args = [
|
||||
{
|
||||
name: "Amount",
|
||||
type: "number",
|
||||
value: ROTATE_AMOUNT
|
||||
},
|
||||
{
|
||||
name: "Carry through",
|
||||
type: "boolean",
|
||||
value: ROTATE_CARRY
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {byteArray}
|
||||
*/
|
||||
run(input, args) {
|
||||
if (args[1]) {
|
||||
return rotlCarry(input, args[0]);
|
||||
} else {
|
||||
return rot(input, args[0], rotl);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlight rotate left
|
||||
*
|
||||
* @param {Object[]} pos
|
||||
* @param {number} pos[].start
|
||||
* @param {number} pos[].end
|
||||
* @param {Object[]} args
|
||||
* @returns {Object[]} pos
|
||||
*/
|
||||
highlight(pos, args) {
|
||||
return pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlight rotate left in reverse
|
||||
*
|
||||
* @param {Object[]} pos
|
||||
* @param {number} pos[].start
|
||||
* @param {number} pos[].end
|
||||
* @param {Object[]} args
|
||||
* @returns {Object[]} pos
|
||||
*/
|
||||
highlightReverse(pos, args) {
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
|
||||
export default RotateLeft;
|
Loading…
Add table
Add a link
Reference in a new issue