Update XORChecksum.mjs
This commit is contained in:
parent
58fe6df54c
commit
28d7fbaca1
@ -13,54 +13,54 @@ import OperationError from "../errors/OperationError.mjs"; // 1. Added import fo
|
|||||||
* XOR Checksum operation
|
* XOR Checksum operation
|
||||||
*/
|
*/
|
||||||
class XORChecksum extends Operation {
|
class XORChecksum extends Operation {
|
||||||
/**
|
/**
|
||||||
* XORChecksum constructor
|
* XORChecksum constructor
|
||||||
*/
|
*/
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.name = "XOR Checksum";
|
this.name = "XOR Checksum";
|
||||||
this.module = "Crypto";
|
this.module = "Crypto";
|
||||||
this.description =
|
this.description =
|
||||||
"XOR Checksum splits the input into blocks of a configurable size and performs the XOR operation on these blocks.";
|
"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.infoURL = "https://wikipedia.org/wiki/XOR";
|
||||||
this.inputType = "ArrayBuffer";
|
this.inputType = "ArrayBuffer";
|
||||||
this.outputType = "string";
|
this.outputType = "string";
|
||||||
this.args = [
|
this.args = [
|
||||||
{
|
{
|
||||||
name: "Blocksize",
|
name: "Blocksize",
|
||||||
type: "number",
|
type: "number",
|
||||||
value: 4,
|
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.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
input = new Uint8Array(input);
|
/**
|
||||||
|
* @param {ArrayBuffer} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
run(input, args) {
|
||||||
|
const blocksize = args[0];
|
||||||
|
|
||||||
const res = Array(blocksize);
|
// 2. Added validation check
|
||||||
res.fill(0);
|
if (!Number.isInteger(blocksize) || blocksize <= 0) {
|
||||||
|
throw new OperationError("Blocksize must be a positive integer.");
|
||||||
|
}
|
||||||
|
|
||||||
for (const chunk of Utils.chunked(input, blocksize)) {
|
input = new Uint8Array(input);
|
||||||
for (let i = 0; i < blocksize; i++) {
|
|
||||||
res[i] ^= chunk[i];
|
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;
|
export default XORChecksum;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user