Skip to content

Instantly share code, notes, and snippets.

@chrisdl
Last active April 9, 2020 22:49
Show Gist options
  • Save chrisdl/656ac7f164196dc2ad0f7e09bc4fd002 to your computer and use it in GitHub Desktop.
Save chrisdl/656ac7f164196dc2ad0f7e09bc4fd002 to your computer and use it in GitHub Desktop.
hash functions playground.
const crypto = require("crypto");
const hashFunction = crypto.createHash("sha256");
const plaintext = "123456";
hashFunction.update(plaintext);
const hash = hashFunction.digest("hex");
console.log(hash);
// Things to try:
// - Make the plaintext longer and shorter. Does it affect the hashes output length?
// - Does running it twice with the same plaintext produce the same result? (aka is the result predictable?)
//
// Extra:
// - Refactor into a function that returns the hashed value.
// makeHash("123456") returns "<hashedvalue as hex>"
// (tip: the hashFunction is NOT reusable and must be instantiated
// inside the function).
// Extra 2:
// - Call it twice. makeHash(makeHash("123456")) is the output different from just calling it once?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment