Skip to content

Instantly share code, notes, and snippets.

@achow101
Created January 18, 2019 05:07
Show Gist options
  • Save achow101/8a749a8050347d314030ded874c13383 to your computer and use it in GitHub Desktop.
Save achow101/8a749a8050347d314030ded874c13383 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python3
import json
import hashlib
with open('export.json') as f:
pws = json.load(f)
def build_radix_index(i, offset, lchar):
radix = {}
prev = 'G'
with open('pwnedpass.txt') as f:
f.seek(offset)
line = f.readline()
while line:
if line[i-1] != lchar:
break
if line[i] != prev:
radix[line[i]] = f.tell() - len(line) - 1
prev = line[i]
line = f.readline()
return radix
def search(q):
radix = {'F': 22784408344,
'1': 1520527589,
'8': 12155473713,
'4': 6079713021,
'3': 4559723085,
'C': 18232232950,
'B': 16713450045,
'E': 21266822897,
'0': 0,
'A': 15194199455,
'D': 19749931058,
'6': 9117928879,
'5': 7599021470,
'7': 10636498894,
'2': 3039974875,
'9': 13674776580
}
for i, char in enumerate(q):
if char not in radix:
return False
offset = radix[char]
radix = build_radix_index(i + 1, offset, char)
return True
pwned_hashes = []
for item in pws['items']:
if 'login' in item and item['login']['password'] is not None:
p_hash = hashlib.sha1(item['login']['password'].encode()).hexdigest().upper()
print('Checking {}, hash: {} ... '.format(item['name'], p_hash), end='', flush=True)
if search(p_hash):
pwned_hashes.append(p_hash)
print('PWNED')
else:
print('SAFE')
print('\n\n')
with open('pwnedpass.txt') as f:
for line in f:
split_line = line.split(':')
line_hash = split_line[0]
if line_hash in pwned_hashes:
print('{} pwned {} times'.format(line_hash, split_line[1].rstrip()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment