mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Add "XOR Checksum" operation
This commit is contained in:
parent
2efd075803
commit
3e8c5d945c
3 changed files with 150 additions and 2 deletions
|
@ -390,7 +390,8 @@
|
||||||
"CRC-8 Checksum",
|
"CRC-8 Checksum",
|
||||||
"CRC-16 Checksum",
|
"CRC-16 Checksum",
|
||||||
"CRC-32 Checksum",
|
"CRC-32 Checksum",
|
||||||
"TCP/IP Checksum"
|
"TCP/IP Checksum",
|
||||||
|
"XOR Checksum"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
59
src/core/operations/XORChecksum.mjs
Normal file
59
src/core/operations/XORChecksum.mjs
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
/**
|
||||||
|
* @author Thomas Weißschuh [thomas@t-8ch.de]
|
||||||
|
* @copyright Crown Copyright 2023
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Operation from "../Operation.mjs";
|
||||||
|
import Utils from "../Utils.mjs";
|
||||||
|
import { toHex } from "../lib/Hex.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XOR Checksum operation
|
||||||
|
*/
|
||||||
|
class XORChecksum extends Operation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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];
|
||||||
|
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, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default XORChecksum;
|
|
@ -237,5 +237,93 @@ TestRegister.addTests([
|
||||||
"args": []
|
"args": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "XOR Checksum (1): nothing",
|
||||||
|
input: "",
|
||||||
|
expectedOutput: "00",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "XOR Checksum",
|
||||||
|
"args": [1]
|
||||||
}
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "XOR Checksum (1): basic string",
|
||||||
|
input: BASIC_STRING,
|
||||||
|
expectedOutput: "08",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "XOR Checksum",
|
||||||
|
"args": [1]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "XOR Checksum (1): UTF-8",
|
||||||
|
input: UTF8_STR,
|
||||||
|
expectedOutput: "df",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "XOR Checksum",
|
||||||
|
"args": [1]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "XOR Checksum (1): all bytes",
|
||||||
|
input: ALL_BYTES,
|
||||||
|
expectedOutput: "00",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "XOR Checksum",
|
||||||
|
"args": [1]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "XOR Checksum (4): nothing",
|
||||||
|
input: "",
|
||||||
|
expectedOutput: "00000000",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "XOR Checksum",
|
||||||
|
"args": [4]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "XOR Checksum (4): basic string",
|
||||||
|
input: BASIC_STRING,
|
||||||
|
expectedOutput: "4918421b",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "XOR Checksum",
|
||||||
|
"args": [4]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "XOR Checksum (4): UTF-8",
|
||||||
|
input: UTF8_STR,
|
||||||
|
expectedOutput: "83a424dc",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "XOR Checksum",
|
||||||
|
"args": [4]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "XOR Checksum (4): all bytes",
|
||||||
|
input: ALL_BYTES,
|
||||||
|
expectedOutput: "00000000",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "XOR Checksum",
|
||||||
|
"args": [4]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue