-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMurmur.mjs
70 lines (59 loc) · 1.61 KB
/
Murmur.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* @author Sajid Nawaz Khan [ssnkhan]
* @copyright Crown Copyright 2021
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import * as mmh from "../vendor/murmurhash.js";
/**
* Murmur operation
*/
class Murmur extends Operation {
/**
* Murmur constructor
*/
constructor() {
super();
this.name = "Murmur";
this.module = "Default";
this.description = "Generates a Murmur hash for a given input (seed optional) and generates a signed, non-cryptographic 32-bit hash. Ideally suited for Shodan http.html_hash searches.";
this.infoURL = "https://github.com/perezd/node-murmurhash";
this.inputType = "string";
this.outputType = "number";
this.args = [
{
"name": "Version",
"type": "option",
"value": ["3", "2"]
},
{
"name": "Seed",
"type": "number",
"value": 0
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {number}
*/
run(input, args) {
let version = "2";
let seed;
if (args && args.length > 0) {
version = args[0];
}
if (args && args.length > 1) {
seed = args[1];
}
if (version === "2") {
return mmh.v2(input, seed);
}
if (version === "3") {
return mmh.v3(input, seed);
}
}
}
export default Murmur;