determinist 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- determinist/__init__.py +1 -0
- determinist/algorithms/__init__.py +2 -0
- determinist/algorithms/v1.py +30 -0
- determinist/algorithms/v2.py +48 -0
- determinist/generator.py +75 -0
- determinist-0.2.0.dist-info/METADATA +8 -0
- determinist-0.2.0.dist-info/RECORD +10 -0
- determinist-0.2.0.dist-info/WHEEL +5 -0
- determinist-0.2.0.dist-info/entry_points.txt +2 -0
- determinist-0.2.0.dist-info/top_level.txt +1 -0
determinist/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .generator import generate_password, app
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from argon2.low_level import Type, hash_secret
|
|
2
|
+
from typing import Literal
|
|
3
|
+
|
|
4
|
+
def generate(master_pass: str, site_name: str, pass_length: int, spec_mode: Literal["replace", "insert"], char_map: dict[str, str], spec_chars: list, spec_freq: int) -> str:
|
|
5
|
+
hashed_str = hash_secret(secret=master_pass.encode('utf-8'),
|
|
6
|
+
salt=site_name.encode('utf-8'),
|
|
7
|
+
time_cost=2,
|
|
8
|
+
memory_cost=65536,
|
|
9
|
+
parallelism=4,
|
|
10
|
+
hash_len=32,
|
|
11
|
+
type=Type.ID
|
|
12
|
+
).decode('utf-8')
|
|
13
|
+
stripped = hashed_str.split('$')[-1]
|
|
14
|
+
|
|
15
|
+
chars_added = ""
|
|
16
|
+
if spec_mode == "insert":
|
|
17
|
+
for i, char in enumerate(stripped):
|
|
18
|
+
chars_added += char
|
|
19
|
+
if (i + 1) % spec_freq == 0:
|
|
20
|
+
chars_added += spec_chars[i % len(spec_chars)]
|
|
21
|
+
elif spec_mode == "replace":
|
|
22
|
+
for _, char in enumerate(stripped):
|
|
23
|
+
if char.lower() in char_map:
|
|
24
|
+
chars_added += char_map[char.lower()]
|
|
25
|
+
else:
|
|
26
|
+
chars_added += char
|
|
27
|
+
|
|
28
|
+
final_password = chars_added[-pass_length:]
|
|
29
|
+
|
|
30
|
+
return final_password
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from argon2.low_level import Type, hash_secret
|
|
2
|
+
from string import punctuation, ascii_lowercase, ascii_uppercase, digits
|
|
3
|
+
from random import Random
|
|
4
|
+
from io import BytesIO
|
|
5
|
+
|
|
6
|
+
def generate(master_pass: str, site_name: str, pass_length: int, char_map: dict[str,str], char_types: list) -> str:
|
|
7
|
+
types_set = set(char_types)
|
|
8
|
+
charset = ""
|
|
9
|
+
|
|
10
|
+
if "special" in types_set:
|
|
11
|
+
charset += punctuation
|
|
12
|
+
if "lowercase" in types_set:
|
|
13
|
+
charset += ascii_lowercase
|
|
14
|
+
if "uppercase" in types_set:
|
|
15
|
+
charset += ascii_uppercase
|
|
16
|
+
if "digits" in types_set:
|
|
17
|
+
charset += digits
|
|
18
|
+
|
|
19
|
+
charset_list = list(charset)
|
|
20
|
+
salt = master_pass + site_name + str(pass_length) + str(char_map) + charset
|
|
21
|
+
|
|
22
|
+
random = Random(salt)
|
|
23
|
+
random.shuffle(charset_list)
|
|
24
|
+
|
|
25
|
+
hashed_bytes = hash_secret(secret=master_pass.encode('utf-8'),
|
|
26
|
+
salt=salt.encode('utf-8'),
|
|
27
|
+
time_cost=2,
|
|
28
|
+
memory_cost=65536,
|
|
29
|
+
parallelism=4,
|
|
30
|
+
hash_len=32*pass_length,
|
|
31
|
+
type=Type.ID
|
|
32
|
+
)
|
|
33
|
+
stream = BytesIO(hashed_bytes)
|
|
34
|
+
password = ""
|
|
35
|
+
|
|
36
|
+
limit = 256 - (256 % len(charset_list))
|
|
37
|
+
for i, _ in enumerate(hashed_bytes):
|
|
38
|
+
byte = stream.getvalue()[i]
|
|
39
|
+
if i == pass_length:
|
|
40
|
+
break
|
|
41
|
+
elif byte < limit:
|
|
42
|
+
password += charset_list[byte % len(charset_list)]
|
|
43
|
+
|
|
44
|
+
password_to_shuffle = list(password)
|
|
45
|
+
random.shuffle(password_to_shuffle)
|
|
46
|
+
final = "".join(password_to_shuffle)
|
|
47
|
+
|
|
48
|
+
return final
|
determinist/generator.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
import json
|
|
3
|
+
from typing import Literal, Annotated
|
|
4
|
+
from string import punctuation
|
|
5
|
+
from .algorithms import v1, v2
|
|
6
|
+
from rich import print, box
|
|
7
|
+
from rich.table import Table
|
|
8
|
+
|
|
9
|
+
app = typer.Typer()
|
|
10
|
+
|
|
11
|
+
def generate_password(master_pass: str,
|
|
12
|
+
site_name: str,
|
|
13
|
+
char_map: dict[str, str] = {},
|
|
14
|
+
spec_chars: list = list(punctuation),
|
|
15
|
+
version: int = 2,
|
|
16
|
+
pass_length: int = 8,
|
|
17
|
+
spec_mode: Literal["replace", "insert"] = "insert",
|
|
18
|
+
spec_freq: int = 4,
|
|
19
|
+
char_types: list = ["special","lowercase","uppercase","digits"]
|
|
20
|
+
) -> str:
|
|
21
|
+
|
|
22
|
+
if version == 1:
|
|
23
|
+
return v1.generate(master_pass=master_pass, site_name=site_name, pass_length=pass_length, spec_mode=spec_mode, spec_chars=spec_chars, char_map=char_map, spec_freq=spec_freq)
|
|
24
|
+
elif version == 2:
|
|
25
|
+
return v2.generate(master_pass=master_pass, site_name=site_name, pass_length=pass_length, char_map=char_map, char_types=char_types)
|
|
26
|
+
else:
|
|
27
|
+
raise ValueError(f"Unsupported algorithm version: {version}")
|
|
28
|
+
|
|
29
|
+
@app.command(name="generate")
|
|
30
|
+
def generate_password_cli(master_pass: Annotated[str, typer.Argument()],
|
|
31
|
+
site_name: Annotated[str, typer.Argument()],
|
|
32
|
+
char_map: Annotated[str, typer.Option("--map", "-M")] = "{}",
|
|
33
|
+
spec_chars: Annotated[str, typer.Option("--special", "-s")] = punctuation,
|
|
34
|
+
version: Annotated[int, typer.Option("--version", "-v", min=1, max=2)] = 2,
|
|
35
|
+
pass_length: Annotated[int, typer.Option("--length", "-l", min=6, max=32)] = 8,
|
|
36
|
+
spec_mode: Annotated[Literal["replace", "insert"], typer.Option("--mode", "-m")] = "insert",
|
|
37
|
+
spec_freq: Annotated[int, typer.Option("--frequency", "-f")] = 4,
|
|
38
|
+
char_types: Annotated[str, typer.Option("--chars", "-c")] = "special,lowercase,uppercase,digits"
|
|
39
|
+
):
|
|
40
|
+
|
|
41
|
+
char_map_dict = json.loads(char_map)
|
|
42
|
+
spec_chars_list = list(spec_chars)
|
|
43
|
+
char_types_list = char_types.split(',')
|
|
44
|
+
|
|
45
|
+
password = generate_password(master_pass=master_pass, site_name=site_name, char_map=char_map_dict, char_types=char_types_list, pass_length=pass_length, version=version, spec_mode=spec_mode, spec_chars=spec_chars_list, spec_freq=spec_freq)
|
|
46
|
+
|
|
47
|
+
success_table = Table(box=box.SIMPLE_HEAD, show_edge=False)
|
|
48
|
+
success_table.add_column("Password Generation Successful!", justify="center")
|
|
49
|
+
success_table.add_row(f"Password: [bold cyan]{password}[/]")
|
|
50
|
+
|
|
51
|
+
print(success_table)
|
|
52
|
+
|
|
53
|
+
@app.command(name="prompt")
|
|
54
|
+
def generate_password_prompt(master_pass: Annotated[str, typer.Argument()],
|
|
55
|
+
site_name: Annotated[str, typer.Argument()],
|
|
56
|
+
char_map: Annotated[str, typer.Option("--map", "-M", prompt="Character map (dict, v1)")] = "{}",
|
|
57
|
+
spec_chars: Annotated[str, typer.Option("--special", "-s", prompt="Special characters (v1)")] = punctuation,
|
|
58
|
+
version: Annotated[int, typer.Option("--version", "-v", min=1, max=2, prompt="version (1/2)")] = 2,
|
|
59
|
+
pass_length: Annotated[int, typer.Option("--length", "-l", min=6, max=32, prompt="Password length (6-32)")] = 8,
|
|
60
|
+
spec_mode: Annotated[Literal["replace", "insert"], typer.Option("--mode", "-m", prompt="Special character mode (v1)")] = "insert",
|
|
61
|
+
spec_freq: Annotated[int, typer.Option("--frequency", "-f", prompt="Special character frequency (v1)")] = 4,
|
|
62
|
+
char_types: Annotated[str, typer.Option("--chars", "-c", prompt="Character types (v2)")] = "special,lowercase,uppercase,digits"
|
|
63
|
+
):
|
|
64
|
+
|
|
65
|
+
char_map_dict = json.loads(char_map)
|
|
66
|
+
spec_chars_list = list(spec_chars)
|
|
67
|
+
char_types_list = char_types.split(',')
|
|
68
|
+
|
|
69
|
+
password = generate_password(master_pass=master_pass, site_name=site_name, char_map=char_map_dict, char_types=char_types_list, pass_length=pass_length, version=version, spec_mode=spec_mode, spec_chars=spec_chars_list, spec_freq=spec_freq)
|
|
70
|
+
|
|
71
|
+
success_table = Table(box=box.SIMPLE_HEAD, show_edge=False)
|
|
72
|
+
success_table.add_column("\nPassword Generation Successful!", justify="center")
|
|
73
|
+
success_table.add_row(f"Password: [bold cyan]{password}[/]")
|
|
74
|
+
|
|
75
|
+
print(success_table)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
determinist/__init__.py,sha256=_RYWWAWxioTk1c-kUASQ070fz-hrWrcum1LVbO7zWxA,45
|
|
2
|
+
determinist/generator.py,sha256=1316YCnU2SzaFspqwoP6DFV6_p-EPdEE_wuCbv4hmq0,4435
|
|
3
|
+
determinist/algorithms/__init__.py,sha256=YsBa9mdNz5daW3B5SprrZdaE1MvZYKUW3xwGErMR424,49
|
|
4
|
+
determinist/algorithms/v1.py,sha256=rSyMxp5cy2W0oY5DFxeNFsTt8WOfgRwZvL-aLjCYnEA,1231
|
|
5
|
+
determinist/algorithms/v2.py,sha256=EJR7wzYAyxZWVKDrDLj-Fp-izEzN5x1hGoNHEnrfaM4,1618
|
|
6
|
+
determinist-0.2.0.dist-info/METADATA,sha256=FUoMamjUoULbfRPNs7ZM_6UZfJVhx2sl7UToN-Lq2o8,227
|
|
7
|
+
determinist-0.2.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
8
|
+
determinist-0.2.0.dist-info/entry_points.txt,sha256=0tFEiJkoD3cLrgW5zirmiUmJJJNXDBPWcMHuFCCWYcw,58
|
|
9
|
+
determinist-0.2.0.dist-info/top_level.txt,sha256=P7rE4nKDnaxjgilcph1GvZJtdxg8Q3YdO18NpMwIBVk,12
|
|
10
|
+
determinist-0.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
determinist
|