/** * @author n1474335 [n1474335@gmail.com] * @copyright Crown Copyright 2016 * @license Apache-2.0 */ import Operation from "../Operation.mjs"; import Utils from "../Utils.mjs"; import { bitOp, xor, BITWISE_OP_DELIMS } from "../lib/BitwiseOp.mjs"; /** * XOR operation */ class XOR extends Operation { /** * XOR constructor */ constructor() { super(); this.name = "XOR"; this.module = "Default"; this.description = "XOR the input with the given key.
e.g. fe023da5

Options
Null preserving: If the current byte is 0x00 or the same as the key, skip it.

Scheme:"; this.infoURL = "https://wikipedia.org/wiki/XOR"; this.inputType = "ArrayBuffer"; this.outputType = "byteArray"; this.args = [ { "name": "Key", "type": "toggleString", "value": "", "toggleValues": BITWISE_OP_DELIMS }, { "name": "Scheme", "type": "option", "value": ["Standard", "Input differential", "Output differential", "Cascade"] }, { "name": "Null preserving", "type": "boolean", "value": false } ]; } /** * @param {ArrayBuffer} input * @param {Object[]} args * @returns {byteArray} */ run(input, args) { input = new Uint8Array(input); const key = Utils.convertToByteArray(args[0].string || "", args[0].option), [, scheme, nullPreserving] = args; return bitOp(input, key, xor, nullPreserving, scheme); } /** * Highlight XOR * * @param {Object[]} pos * @param {number} pos[].start * @param {number} pos[].end * @param {Object[]} args * @returns {Object[]} pos */ highlight(pos, args) { return pos; } /** * Highlight XOR 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 XOR;