mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 15:26:16 -04:00
Added bit reversal
This commit is contained in:
parent
550ab403f6
commit
4c9a61f5a7
1 changed files with 40 additions and 14 deletions
|
@ -5,7 +5,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CRC-8 Checksum operation
|
* CRC-8 Checksum operation
|
||||||
|
@ -25,19 +24,36 @@ class CRC8Checksum extends Operation {
|
||||||
this.inputType = "ArrayBuffer";
|
this.inputType = "ArrayBuffer";
|
||||||
this.outputType = "string";
|
this.outputType = "string";
|
||||||
this.args = [
|
this.args = [
|
||||||
/* Example arguments. See the project wiki for full details.
|
|
||||||
{
|
{
|
||||||
name: "First arg",
|
"name": "Algorithm",
|
||||||
type: "string",
|
"type": "option",
|
||||||
value: "Don't Panic"
|
"value": [
|
||||||
},
|
"CRC-8"
|
||||||
{
|
]
|
||||||
name: "Second arg",
|
|
||||||
type: "number",
|
|
||||||
value: 42
|
|
||||||
}
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
calculateCRC8(algorithmName, polynomial, initializationValue, refIn, refOut, xorOut, check) {
|
||||||
|
let initializationValue = this.reverseBits();
|
||||||
|
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For an 8 bit initialization value reverse the bits.
|
||||||
|
*
|
||||||
|
* @param input
|
||||||
*/
|
*/
|
||||||
];
|
reverseBits(input) {
|
||||||
|
let reflectedBits = input.toString(2).split('');
|
||||||
|
for (let i = 0; i < hashSize / 2; i++) {
|
||||||
|
let x = reflectedBits[i];
|
||||||
|
reflectedBits[i] = reflectedBits[hashSize - i - 1];
|
||||||
|
reflectedBits[hashSize - i - 1] = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseInt(reflectedBits.join(''));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,11 +62,21 @@ class CRC8Checksum extends Operation {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
// const [firstArg, secondArg] = args;
|
const algorithm = args[0];
|
||||||
|
|
||||||
throw new OperationError("Test");
|
if (algorithm === "CRC-8") {
|
||||||
|
return this.calculateCRC8(algorithm, 0x7, 0x0, false, false, 0x0, 0xF4)
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hashSize = 8;
|
||||||
|
|
||||||
|
// const CRC8AlgoParameters = {
|
||||||
|
// 'CRC8'
|
||||||
|
// }
|
||||||
|
|
||||||
export default CRC8Checksum;
|
export default CRC8Checksum;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue