Created
November 8, 2018 02:03
-
-
Save kevinl95/557877440eeeaba849528f1cbd494958 to your computer and use it in GitHub Desktop.
The generator for my Bixby tutorial.
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
// Correct Horse Battery Staple | |
// An implementation of the XKCD password algorithm https://xkcd.com/936/ | |
// The idea behind this generator is that randomized passwords are easy to guess | |
// and difficult to remember, while a password composed of four english words is | |
// both easy to remember and difficult to guess. This capsule adds the ability | |
// to generate such passwords to Bixby. | |
// Main entry point | |
function generate(numWords) { | |
var Password = ""; | |
// Get our list of words | |
var wordfile = require("./lib/wordlist"); | |
var wordList = []; | |
wordfile.forEach(function(newWords){ | |
wordList = newWords.commonWords; | |
}) | |
// Loop through the number of words the user asked for | |
for (var i = 0; i < numWords; i++) { | |
var rand = wordList[Math.floor(Math.random() * wordList.length)]; | |
Password = Password + rand; | |
} | |
// Capture the length in words of the current password | |
var length = numWords; | |
// Calculate the approximate entropy of the password | |
var entropy = length * 11; | |
// Calculate the approximate number of years to guess the password | |
// at 1000 guesses/second | |
var years = Math.floor(Math.pow(2, entropy) / 31536000000); | |
// Password Result | |
return { | |
Password: Password, // required password | |
length: length, // Number of words used | |
entropy: entropy, // Approximate bits of entropy of the password | |
years: years // Approximate number of years to guess password | |
} | |
} | |
// Exports | |
module.exports = { | |
function: generate | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment