2012-01-07 16:35:11 +00:00
|
|
|
// Draws inspiration from pwgen and http://tools.arantius.com/password
|
|
|
|
var PhoneticKeyGenerator = function(options) {
|
|
|
|
// No options
|
|
|
|
};
|
|
|
|
|
|
|
|
// Generate a phonetic key
|
|
|
|
PhoneticKeyGenerator.prototype.createKey = function(keyLength) {
|
|
|
|
var text = '';
|
2014-03-25 01:23:31 +00:00
|
|
|
var start = Math.round(Math.random());
|
2012-01-07 16:35:11 +00:00
|
|
|
for (var i = 0; i < keyLength; i++) {
|
2014-03-25 01:20:05 +00:00
|
|
|
text += (i % 2 == start) ? this.randConsonant() : this.randVowel();
|
2012-01-07 16:35:11 +00:00
|
|
|
}
|
|
|
|
return text;
|
|
|
|
};
|
|
|
|
|
2014-03-25 01:20:05 +00:00
|
|
|
PhoneticKeyGenerator.consonants = 'bcdfghjklmnpqrstvwxyz';
|
2012-01-07 16:35:11 +00:00
|
|
|
PhoneticKeyGenerator.vowels = 'aeiou';
|
|
|
|
|
|
|
|
// Get an random vowel
|
|
|
|
PhoneticKeyGenerator.prototype.randVowel = function() {
|
|
|
|
return PhoneticKeyGenerator.vowels[
|
|
|
|
Math.floor(Math.random() * PhoneticKeyGenerator.vowels.length)
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
// Get an random consonant
|
|
|
|
PhoneticKeyGenerator.prototype.randConsonant = function() {
|
|
|
|
return PhoneticKeyGenerator.consonants[
|
|
|
|
Math.floor(Math.random() * PhoneticKeyGenerator.consonants.length)
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = PhoneticKeyGenerator;
|