Created
January 5, 2012 20:13
-
-
Save haggaie/1567012 to your computer and use it in GitHub Desktop.
Generate random passwords from dictionary
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
#!/usr/bin/env python | |
# random-dict-password.py - Generate random passwords from a dictionary | |
# Copyright (c) 2012 Haggai Eran | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
import random | |
from math import log | |
def filter_word(word): | |
return not word.endswith("'s\n") | |
def load_dictionary(): | |
with file('/usr/share/dict/words') as f: | |
return set(line.strip().lower() for line in f.readlines() if filter_word(line)) | |
if __name__ == '__main__': | |
dictionary = load_dictionary() | |
length = len(dictionary) | |
print "Dictionary length: %d. Password entropy: %f" % (length,4*log(length)/log(2)) | |
words = random.sample(dictionary, 4) | |
print ' '.join(words) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment