Last active
November 20, 2022 03:13
-
-
Save hachibu/089f59b13868b42af3ca030653b34ec0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { randomBytes, createHash } from 'node:crypto' | |
const ZERO_WIDTH_SPACE = '' | |
const ZERO_WIDTH_JOINER = '' | |
const randomZeroWidthHash = () => | |
randomBytes(32) | |
.reduce((a, b) => [...a, b.toString(2)], []) | |
.reduce((a, c) => a + (+c ? ZERO_WIDTH_SPACE : ZERO_WIDTH_JOINER), '') | |
.padEnd(256, ZERO_WIDTH_SPACE) | |
const createSha256Hash = (data) => | |
createHash('sha256') | |
.update(data) | |
.digest('hex') | |
function main() { | |
const zwhash = randomZeroWidthHash() | |
const test = `Hello ${zwhash}World!` | |
console.log(createSha256Hash(zwhash)) | |
console.log(createSha256Hash(test.slice(6, 6 + zwhash.length))) | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment