diff --git a/lib/key_generators/dictionary.js b/lib/key_generators/dictionary.js index ad40b9a..69ebc48 100644 --- a/lib/key_generators/dictionary.js +++ b/lib/key_generators/dictionary.js @@ -11,20 +11,18 @@ var DictionaryGenerator = function(options) { //Load dictionary fs.readFile(options.path, 'utf8', (err,data) => { if(err) throw err; - this.dictionary = data.split(','); - - //Remove any non alpha-numeric characters - for(var i = 0; i < this.dictionary.length; i++) - this.dictionary[i] = this.dictionary[i].replace(/\W/g,''); - - }); + this.dictionary = data.split(/[\n\r]+/); + }); }; //Generates a dictionary-based key, of keyLength words DictionaryGenerator.prototype.createKey = function(keyLength) { var text = ''; - for(var i = 0; i < keyLength; i++) - text += this.dictionary[Math.floor(Math.random()*this.dictionary.length)]; + for(var i = 0; i < keyLength; i++) { + var index =Math.floor(Math.random()*this.dictionary.length); + text += this.dictionary[index]; + } + return text; };