Created
June 19, 2011 23:33
-
-
Save tomoconnor/1034903 to your computer and use it in GitHub Desktop.
Password Analyser
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
#!/usr/bin/env python | |
# | |
# Fecking ugly thing I wrote to parse lulzsec's password releases | |
# and display some fairly anonymous data. | |
# Usage: password_analysis.py <filename to process> | |
# App expects Email | Password | |
# Easily modified to fit a file format. | |
import re | |
import operator | |
import sys,os | |
import string | |
import pprint | |
from math import sqrt | |
pp = pprint.PrettyPrinter() | |
passwords = {} | |
pass_counts = {} | |
onecharpass = [] | |
passfile = open(sys.argv[1],'r') | |
for line in passfile: | |
if line.count('|') == 2: | |
password, email, f = line.split('|') | |
email = email.rstrip().lstrip() | |
password = password.rstrip().lstrip() | |
if password in passwords: | |
passwords[password] += 1 | |
else: | |
passwords[password] = 1 | |
# Interesting Things | |
# Max / Min lengths | |
# Num passwords containing punctuation | |
# Avg length | |
# standard deviation of length | |
# number of occurrences | |
pass_count = sorted(passwords.iteritems(), key=operator.itemgetter(1)) | |
for pc in pass_count: | |
pass_counts[pc[0]]=pc[1] | |
print "Top 100 Passwords, and their frequency" | |
pp.pprint(pass_count[len(pass_count)-100:]) | |
print "Longest password: " | |
l = "" | |
for p in passwords: | |
if len(p) > len(l): | |
l = p | |
print l, len(l), "chars long" | |
for p in passwords: | |
if len(p) == 1 and p not in onecharpass: | |
onecharpass.append(p) | |
print "Shortest passwords, and their occurrences" | |
for o in onecharpass: | |
print o, "occurred ", pass_counts[o], "times" | |
t = 0.0 | |
for p in passwords: | |
t += len(p) | |
mean = t/len(passwords.keys()) | |
print "Average password length: ", mean | |
std = 0.0 | |
for p in passwords: | |
std = std + (len(p) - mean)**2 | |
std = sqrt(std/float(len(passwords.keys())-1)) | |
print "Standard Deviation: ", std | |
punpwds = [] | |
punc = list(string.punctuation) | |
for f in punc: | |
for p in passwords: | |
if f in p: | |
punpwds.append(p) | |
print len(punpwds), "Passwords contain punctuation" | |
print "Here's a selection:" | |
print punpwds[:10] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment