-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluator.py
51 lines (35 loc) · 1.15 KB
/
evaluator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
"""
Created on Thu May 24 20:17:44 2018
"""
__author__ = "Andrew I McClement"
from random import randint
CHARACTERS_PERMITTED = 26
MIN_PASSWORD_LENGTH = 5
MAX_PASSWORD_LENGTH = 100
def get_random_letter():
return get_letter_from_integer(randint(0, CHARACTERS_PERMITTED - 1))
def get_letter_from_integer(integer: int) -> str:
return chr(97 + integer)
class PasswordChecker:
def __init__(self, password=None):
self._length = randint(MIN_PASSWORD_LENGTH, MAX_PASSWORD_LENGTH)
if password is None:
self._password = self.create_password(self._length)
else:
self._password = password
self._attempts = 0
def check_guess(self, guess) -> (int, bool):
successes = sum((x[0] == x[1] for x in zip(self._password, guess)))
self._attempts += 1
return successes, guess == self._password
@property
def attempts(self):
return self._attempts
@staticmethod
def create_password(length):
return "".join((get_random_letter() for i in range(length)))
def reset(self):
self._attempts = 0
if __name__ == "__main__":
pass