Git Product home page Git Product logo

imt_challenge_ts's Introduction

CODE CHALLENGE: Computing hash Function (Node + Typescript version)

The Use Case

Build a program hat takes the given three arguments:

  1. a URL
  2. a file name
  3. 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.

Requirements

  • Node v14.x:

    If you are using nvm; you can enable it by issuing nvm use (see .nvmrc file)

How to test

$ npm test

How to run the application

$ npm install
$ npm start -- <url> <file> [bandwidth]

Known Issues

imt_challenge_ts's People

Contributors

elfrucool avatar

Watchers

James Cloos avatar  avatar  avatar

imt_challenge_ts's Issues

Inconsistent fetching

Different calls to the same location produce different results, both in size and content

Possible cause: different reads of the body happen at different time, and we get the end of the file reading before other reads

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.