Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_salt(salt: int) -> bytes:
if not salt:
raise PasswordCrackError('Must enter SALT value as integer')
if not isinstance(salt, int):
raise PasswordCrackError('Salt must be an integer')
return (
f'{salt:x}'.encode()
if salt > 0
else binascii.hexlify(struct.pack(">q", salt))
)
def get_salt(salt: int) -> bytes:
if not salt:
raise PasswordCrackError('Must enter SALT value as integer')
if not isinstance(salt, int):
raise PasswordCrackError('Salt must be an integer')
return (
f'{salt:x}'.encode()
if salt > 0
else binascii.hexlify(struct.pack(">q", salt))
)
def _get_feed(self):
if not self.alpha:
return self._feed_pins()
elif self.dict_file:
return self._feed_dict()
elif self.alpha_range:
return self._feed_alpha()
else:
raise PasswordCrackError('Attack method was not chosen.')
def _feed_alpha(self):
if not self.alpha_range:
raise PasswordCrackError('Range of characters not specified')
for i in range(self.min_len, self.max_len + 1):
for prod in itertools.product(self.alpha_range, repeat=i):
yield ''.join(prod).encode()
def get_hash(key: str) -> bytes:
if not key or not utils.is_hex(key) or not (len(key) in [40, 72]):
raise PasswordCrackError('Must enter HASH value.')
return binascii.unhexlify(key[:40])