Last active
September 24, 2021 14:59
-
-
Save atoponce/560a7c54ba70fc64ecd43a81a0f5fe5d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
> generateZalgo() | |
b̖k͔X̍h̪l͂eͦz̋Uͪs̐o͓L̐ | |
> generateZalgo() | |
p̘H͑q̈z̊B͕T̾D͂g̢o͖q͚5ͦ | |
> generateZalgo() | |
șA̷9̣n̩5̞y̘J̸N̬hͩf̴Jͮ |
This file contains hidden or 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
const SECURITY = 128 // minimum security requirement in bits | |
function secRand (count) { | |
const min = 2 ** 16 % count | |
const rand = new Uint16Array(1) | |
let num = min | |
do num = crypto.getRandomValues(rand)[0] | |
while (num < min) | |
return num % count | |
} | |
function generateZalgo () { | |
const alnum = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' | |
const diacritics = [ | |
'\u0300','\u0301','\u0302','\u0303','\u0304','\u0305','\u0306','\u0307','\u0308','\u0309','\u030a','\u030b','\u030c','\u030d','\u030e','\u030f', | |
'\u0310','\u0311','\u0312','\u0313','\u0314','\u0315','\u0316','\u0317','\u0318','\u0319','\u031a','\u031b','\u031c','\u031d','\u031e','\u031f', | |
'\u0320','\u0321','\u0322','\u0323','\u0324','\u0325','\u0326','\u0327','\u0328','\u0329','\u032a','\u032b','\u032c','\u032d','\u032e','\u032f', | |
'\u0330','\u0331','\u0332','\u0333','\u0334','\u0335','\u0336','\u0337','\u0338','\u0339','\u033a','\u033b','\u033c','\u033d','\u033e','\u033f', | |
'\u0340','\u0341','\u0342','\u0343','\u0344','\u0345','\u0346','\u0347','\u0348','\u0349','\u034a','\u034b','\u034c','\u034d','\u034e', | |
'\u0350','\u0351','\u0352','\u0353','\u0354','\u0355','\u0356','\u0357','\u0358','\u0359','\u035a','\u035b','\u035c','\u035d','\u035e','\u035f', | |
'\u0360','\u0361','\u0362','\u0363','\u0364','\u0365','\u0366','\u0367','\u0368','\u0369','\u036a','\u036b','\u036c','\u036d','\u036e','\u036f' | |
].join('') | |
const len = Math.ceil(SECURITY / Math.log2(alnum.length * diacritics.length)) | |
let pass = '' | |
for (let i = 0; i < len; i++) pass += alnum[secRand(alnum.length)] + diacritics[secRand(diacritics.length)] | |
console.log(pass) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment