implement customer interface

This commit is contained in:
2024-07-09 13:11:42 -05:00
parent 08bfd08b4a
commit 11ae1ea759
2 changed files with 37 additions and 12 deletions

14
encipher_nkode.py Normal file
View File

@@ -0,0 +1,14 @@
from src.models import (
CustomerInterface,
UserEncipherKeys,
EncipheredNKode
)
def encipher_nkode(
user_nkode_attributes: list[int],
user_nkode_sets: list[int],
user_keys: UserEncipherKeys,
customer_interface: CustomerInterface
) -> EncipheredNKode:
pass

View File

@@ -1,10 +1,8 @@
import secrets import secrets
from pydantic import BaseModel
from src.utils import ( from src.utils import (
generate_random_list, generate_random_matrix, xor_lists, generate_random_list, generate_random_matrix, xor_lists,
random_number_in_range
) )
from pydantic import BaseModel
class UserEncipherKeys(BaseModel): class UserEncipherKeys(BaseModel):
@@ -14,11 +12,11 @@ class UserEncipherKeys(BaseModel):
mask_key: list[int] mask_key: list[int]
@staticmethod @staticmethod
def new_user_encipher_keys(height: int, width: int, nkode_set_values: list[int]): def new_user_encipher_keys(height: int, width: int, set_values: list[int]):
assert len(nkode_set_values) == width assert len(set_values) == width
set_key = generate_random_list(width) set_key = generate_random_list(width)
set_key = xor_lists(set_key, nkode_set_values) set_key = xor_lists(set_key, set_values)
return UserEncipherKeys( return UserEncipherKeys(
alpha_key=generate_random_matrix(width, height), alpha_key=generate_random_matrix(width, height),
@@ -33,14 +31,19 @@ class CustomerAttribute(BaseModel):
set_val: int set_val: int
class Customer(BaseModel): class CustomerInterface(BaseModel):
base_interface: dict[ # base_interface: { set0: [attr0 ... attrN], ... setM: [(val0, setM) ... (valN, setM)]}
list[CustomerAttribute]] # { set0: [(val0, set0) ... (valN, set0)], ... setM: [(val0, setM) ... (valN, setM)]} base_interface: dict[int, CustomerAttribute]
def __init__(self, **data):
super().__init__(**data)
self._set_index_lookup: dict[int, int] = {}
self._attr_index_lookup: dict[CustomerAttribute: (int, int)] = {}
@staticmethod @staticmethod
def new_interface(height: int, width: int): def new_interface(height: int, width: int):
assert(height <= 256) assert (height <= 256)
assert(width <= 256) assert (width <= 256)
base_interface = {} base_interface = {}
possible_set_vals = list(range(256)) possible_set_vals = list(range(256))
@@ -54,6 +57,14 @@ class Customer(BaseModel):
possible_attr_values.remove(cur_attr) possible_attr_values.remove(cur_attr)
possible_set_vals.remove(cur_set) possible_set_vals.remove(cur_set)
return Customer( return CustomerInterface(
base_interface=base_interface base_interface=base_interface
) )
def get_set_values(self) -> list[int]:
return list(self.base_interface.keys())
class EncipheredNKode(BaseModel):
code: str
mask: str