mirror of
https://github.com/gchq/CyberChef.git
synced 2024-09-06 11:41:35 +02:00
77 lines
2.0 KiB
JavaScript
77 lines
2.0 KiB
JavaScript
/**
|
|
* @author n1474335 [n1474335@gmail.com]
|
|
* @copyright Crown Copyright 2016
|
|
* @license Apache-2.0
|
|
*/
|
|
|
|
import Operation from "../Operation";
|
|
import {toBase64, ALPHABET_OPTIONS} from "../lib/Base64";
|
|
|
|
/**
|
|
* To Base64 operation
|
|
*/
|
|
class ToBase64 extends Operation {
|
|
|
|
/**
|
|
* ToBase64 constructor
|
|
*/
|
|
constructor() {
|
|
super();
|
|
|
|
this.name = "To Base64";
|
|
this.module = "Default";
|
|
this.description = "Base64 is a notation for encoding arbitrary byte data using a restricted set of symbols that can be conveniently used by humans and processed by computers.<br><br>This operation decodes data from an ASCII Base64 string back into its raw format.<br><br>e.g. <code>aGVsbG8=</code> becomes <code>hello</code>";
|
|
this.inputType = "ArrayBuffer";
|
|
this.outputType = "string";
|
|
this.args = [
|
|
{
|
|
name: "Alphabet",
|
|
type: "editableOption",
|
|
value: ALPHABET_OPTIONS
|
|
}
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param {ArrayBuffer} input
|
|
* @param {Object[]} args
|
|
* @returns {string}
|
|
*/
|
|
run(input, args) {
|
|
const alphabet = args[0];
|
|
return toBase64(new Uint8Array(input), alphabet);
|
|
}
|
|
|
|
/**
|
|
* Highlight to Base64
|
|
*
|
|
* @param {Object[]} pos
|
|
* @param {number} pos[].start
|
|
* @param {number} pos[].end
|
|
* @param {Object[]} args
|
|
* @returns {Object[]} pos
|
|
*/
|
|
highlight(pos, args) {
|
|
pos[0].start = Math.floor(pos[0].start / 3 * 4);
|
|
pos[0].end = Math.ceil(pos[0].end / 3 * 4);
|
|
return pos;
|
|
}
|
|
|
|
/**
|
|
* Highlight from Base64
|
|
*
|
|
* @param {Object[]} pos
|
|
* @param {number} pos[].start
|
|
* @param {number} pos[].end
|
|
* @param {Object[]} args
|
|
* @returns {Object[]} pos
|
|
*/
|
|
highlightReverse(pos, args) {
|
|
pos[0].start = Math.ceil(pos[0].start / 4 * 3);
|
|
pos[0].end = Math.floor(pos[0].end / 4 * 3);
|
|
return pos;
|
|
}
|
|
}
|
|
|
|
export default ToBase64;
|