mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 23:36:16 -04:00
ESM: Ported all Hash and Checksum operations
This commit is contained in:
parent
5362508a99
commit
3fd1f4e6d9
43 changed files with 1971 additions and 9 deletions
48
src/core/operations/Fletcher32Checksum.mjs
Normal file
48
src/core/operations/Fletcher32Checksum.mjs
Normal file
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2016
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import Utils from "../Utils";
|
||||
|
||||
/**
|
||||
* Fletcher-32 Checksum operation
|
||||
*/
|
||||
class Fletcher32Checksum extends Operation {
|
||||
|
||||
/**
|
||||
* Fletcher32Checksum constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Fletcher-32 Checksum";
|
||||
this.module = "Hashing";
|
||||
this.description = "The Fletcher checksum is an algorithm for computing a position-dependent checksum devised by John Gould Fletcher at Lawrence Livermore Labs in the late 1970s.<br><br>The objective of the Fletcher checksum was to provide error-detection properties approaching those of a cyclic redundancy check but with the lower computational effort associated with summation techniques.";
|
||||
this.inputType = "byteArray";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {byteArray} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
let a = 0,
|
||||
b = 0;
|
||||
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
a = (a + input[i]) % 0xffff;
|
||||
b = (b + a) % 0xffff;
|
||||
}
|
||||
|
||||
return Utils.hex(((b << 16) | a) >>> 0, 8);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Fletcher32Checksum;
|
Loading…
Add table
Add a link
Reference in a new issue