Created
January 13, 2016 16:39
-
-
Save cheeyeo/bcb2bc7040eedfd66481 to your computer and use it in GitHub Desktop.
Password entropy example
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
import re | |
from math import log,pow | |
class PasswordStrength: | |
def __init__(self): | |
self.numeric=re.compile('\d') | |
self.loweralpha=re.compile('[a-z]') | |
self.upperalpha=re.compile('[A-Z]') | |
self.symbols=re.compile('[-_.:,;<>?"#$%&/()!@~]') | |
self.num_of_symbols=20 # adjust accordingly... | |
def calculate_entropy(self,password=''): | |
charset = 0 | |
if self.numeric.search(password): | |
charset += 10 | |
if self.loweralpha.search(password): | |
charset += 26 | |
if self.upperalpha.search(password): | |
charset += 26 | |
if self.symbols.search(password): | |
charset += self.num_of_symbols | |
entropy = log(pow(charset,len(password)),2) | |
return entropy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment