Build a program hat takes the given three arguments:
- a URL
- a file name
- a bandwidth for throttling (optional)
And fetches the file given the URL, then computes its hash using the IMT hash function and stores the value in file under file name encoded as hex string.
The IMT hash function is as follows:
Length: 8 bytes
const coefficients:number[] = [2, 3, 5, 7, 11, 13, 17, 19 ] for each incoming byte, ib: for each byte of the hash, h h[i] = ((h[i-1] + ib) * coefficient[i]) % 255 // in the case where i-1 == -1, h[i-1] should be 0.For example, hashing the data:
const data:number[] = [12]
Should result in a hash of:
[24, 108, 90, 204, 81, 189, 102, 126]
Then, when converted to hexadecimal for writing to the output file, it should be:
186c5acc51bd667e
Do not put the file in memory or disk, assume it may be bigger than available resources.
$ npm test
$ npm install
$ npm start -- <url> <file> [bandwidth]