Skip to content

Commit

Permalink
allowing support for large numbers in estimating attack times
Browse files Browse the repository at this point in the history
  • Loading branch information
dwolfhub committed Apr 2, 2018
1 parent 4b4e978 commit 7a7ac08
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ venv*
dist
build
zxcvbn_python.egg-info
.vscode
13 changes: 13 additions & 0 deletions tests/time_estimates_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from zxcvbn.time_estimates import estimate_attack_times
import sys

def test_long_ints_dont_overflow():
try:
long_guesses = sys.maxsize + 1
except expression as identifier:
long_guesses = sys.maxint + 1

attack_times = estimate_attack_times(long_guesses)
assert 'crack_times_seconds' in attack_times
assert 'crack_times_display' in attack_times
assert 'score' in attack_times
10 changes: 6 additions & 4 deletions zxcvbn/time_estimates.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from decimal import Decimal

def estimate_attack_times(guesses):
crack_times_seconds = {
'online_throttling_100_per_hour': float(guesses) / (100.0 / 3600.0),
'online_no_throttling_10_per_second': float(guesses) / 10.0,
'offline_slow_hashing_1e4_per_second': float(guesses) / float(1e4),
'offline_fast_hashing_1e10_per_second': float(guesses) / float(1e10),
'online_throttling_100_per_hour': Decimal(guesses) / Decimal(100.0 / 3600.0),
'online_no_throttling_10_per_second': Decimal(guesses) / Decimal(10.0),
'offline_slow_hashing_1e4_per_second': Decimal(guesses) / Decimal(1e4),
'offline_fast_hashing_1e10_per_second': Decimal(guesses) / Decimal(1e10),
}

crack_times_display = {}
Expand Down

0 comments on commit 7a7ac08

Please sign in to comment.