implement customer models
This commit is contained in:
59
src/models.py
Normal file
59
src/models.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import secrets
|
||||
|
||||
from src.utils import (
|
||||
generate_random_list, generate_random_matrix, xor_lists,
|
||||
random_number_in_range
|
||||
)
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class UserEncipherKeys(BaseModel):
|
||||
alpha_key: list[list[int]]
|
||||
set_key: list[int]
|
||||
pass_key: list[int]
|
||||
mask_key: list[int]
|
||||
|
||||
@staticmethod
|
||||
def new_user_encipher_keys(height: int, width: int, nkode_set_values: list[int]):
|
||||
assert len(nkode_set_values) == width
|
||||
|
||||
set_key = generate_random_list(width)
|
||||
set_key = xor_lists(set_key, nkode_set_values)
|
||||
|
||||
return UserEncipherKeys(
|
||||
alpha_key=generate_random_matrix(width, height),
|
||||
pass_key=generate_random_list(height),
|
||||
mask_key=generate_random_list(height),
|
||||
set_key=set_key,
|
||||
)
|
||||
|
||||
|
||||
class CustomerAttribute(BaseModel):
|
||||
attr_val: int
|
||||
set_val: int
|
||||
|
||||
|
||||
class Customer(BaseModel):
|
||||
base_interface: dict[
|
||||
list[CustomerAttribute]] # { set0: [(val0, set0) ... (valN, set0)], ... setM: [(val0, setM) ... (valN, setM)]}
|
||||
|
||||
@staticmethod
|
||||
def new_interface(height: int, width: int):
|
||||
assert(height <= 256)
|
||||
assert(width <= 256)
|
||||
|
||||
base_interface = {}
|
||||
possible_set_vals = list(range(256))
|
||||
for w in range(width):
|
||||
cur_set = secrets.choice(possible_set_vals)
|
||||
possible_attr_values = list(range(256))
|
||||
base_interface[cur_set] = []
|
||||
for h in range(height):
|
||||
cur_attr = secrets.choice(possible_attr_values)
|
||||
base_interface[cur_set].append(CustomerAttribute(attr_val=cur_attr, set_val=cur_set))
|
||||
possible_attr_values.remove(cur_attr)
|
||||
possible_set_vals.remove(cur_set)
|
||||
|
||||
return Customer(
|
||||
base_interface=base_interface
|
||||
)
|
||||
Reference in New Issue
Block a user