From 28d7fbaca1e0d9e98893718124088f6af3d77a36 Mon Sep 17 00:00:00 2001 From: Subhadeep Date: Wed, 10 Jun 2026 14:47:20 +0530 Subject: [PATCH] Update XORChecksum.mjs --- src/core/operations/XORChecksum.mjs | 84 ++++++++++++++--------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/src/core/operations/XORChecksum.mjs b/src/core/operations/XORChecksum.mjs index be154802..876717a1 100644 --- a/src/core/operations/XORChecksum.mjs +++ b/src/core/operations/XORChecksum.mjs @@ -13,54 +13,54 @@ import OperationError from "../errors/OperationError.mjs"; // 1. Added import fo * XOR Checksum operation */ class XORChecksum extends Operation { - /** - * XORChecksum constructor - */ - constructor() { - super(); + /** + * XORChecksum constructor + */ + constructor() { + super(); - this.name = "XOR Checksum"; - this.module = "Crypto"; - this.description = - "XOR Checksum splits the input into blocks of a configurable size and performs the XOR operation on these blocks."; - this.infoURL = "https://wikipedia.org/wiki/XOR"; - this.inputType = "ArrayBuffer"; - this.outputType = "string"; - this.args = [ - { - name: "Blocksize", - type: "number", - value: 4, - }, - ]; - } - - /** - * @param {ArrayBuffer} input - * @param {Object[]} args - * @returns {string} - */ - run(input, args) { - const blocksize = args[0]; - - // 2. Added validation check - if (!Number.isInteger(blocksize) || blocksize <= 0) { - throw new OperationError("Blocksize must be a positive integer."); + this.name = "XOR Checksum"; + this.module = "Crypto"; + this.description = + "XOR Checksum splits the input into blocks of a configurable size and performs the XOR operation on these blocks."; + this.infoURL = "https://wikipedia.org/wiki/XOR"; + this.inputType = "ArrayBuffer"; + this.outputType = "string"; + this.args = [ + { + name: "Blocksize", + type: "number", + value: 4, + }, + ]; } - input = new Uint8Array(input); + /** + * @param {ArrayBuffer} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + const blocksize = args[0]; - const res = Array(blocksize); - res.fill(0); + // 2. Added validation check + if (!Number.isInteger(blocksize) || blocksize <= 0) { + throw new OperationError("Blocksize must be a positive integer."); + } - for (const chunk of Utils.chunked(input, blocksize)) { - for (let i = 0; i < blocksize; i++) { - res[i] ^= chunk[i]; - } + input = new Uint8Array(input); + + const res = Array(blocksize); + res.fill(0); + + for (const chunk of Utils.chunked(input, blocksize)) { + for (let i = 0; i < blocksize; i++) { + res[i] ^= chunk[i]; + } + } + + return toHex(res, ""); } - - return toHex(res, ""); - } } export default XORChecksum;