mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
ESM: Ported Base58, Base and BCD operations
This commit is contained in:
parent
84df055888
commit
f26d175cad
8 changed files with 620 additions and 0 deletions
53
src/core/operations/ToBase.mjs
Normal file
53
src/core/operations/ToBase.mjs
Normal file
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2016
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import OperationError from "../errors/OperationError";
|
||||
|
||||
/**
|
||||
* To Base operation
|
||||
*/
|
||||
class ToBase extends Operation {
|
||||
|
||||
/**
|
||||
* ToBase constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "To Base";
|
||||
this.module = "Default";
|
||||
this.description = "Converts a decimal number to a given numerical base.";
|
||||
this.inputType = "BigNumber";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
"name": "Radix",
|
||||
"type": "number",
|
||||
"value": 36
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {BigNumber} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
if (!input) {
|
||||
throw new OperationError("Error: Input must be a number");
|
||||
}
|
||||
const radix = args[0];
|
||||
if (radix < 2 || radix > 36) {
|
||||
throw new OperationError("Error: Radix argument must be between 2 and 36");
|
||||
}
|
||||
return input.toString(radix);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default ToBase;
|
Loading…
Add table
Add a link
Reference in a new issue