mirror of
https://github.com/gchq/CyberChef.git
synced 2025-06-18 20:26:24 -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
52
src/core/operations/Adler32Checksum.mjs
Normal file
52
src/core/operations/Adler32Checksum.mjs
Normal file
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2016
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import Utils from "../Utils";
|
||||
|
||||
/**
|
||||
* Adler-32 Checksum operation
|
||||
*/
|
||||
class Adler32Checksum extends Operation {
|
||||
|
||||
/**
|
||||
* Adler32Checksum constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Adler-32 Checksum";
|
||||
this.module = "Hashing";
|
||||
this.description = "Adler-32 is a checksum algorithm which was invented by Mark Adler in 1995, and is a modification of the Fletcher checksum. Compared to a cyclic redundancy check of the same length, it trades reliability for speed (preferring the latter).<br><br>Adler-32 is more reliable than Fletcher-16, and slightly less reliable than Fletcher-32.";
|
||||
this.inputType = "byteArray";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {byteArray} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const MOD_ADLER = 65521;
|
||||
let a = 1,
|
||||
b = 0;
|
||||
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
a += input[i];
|
||||
b += a;
|
||||
}
|
||||
|
||||
a %= MOD_ADLER;
|
||||
b %= MOD_ADLER;
|
||||
|
||||
return Utils.hex(((b << 16) | a) >>> 0, 8);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Adler32Checksum;
|
Loading…
Add table
Add a link
Reference in a new issue