implement encipher
This commit is contained in:
@@ -10,6 +10,10 @@ class UserEncipherKeys(BaseModel):
|
||||
set_key: list[int]
|
||||
pass_key: list[int]
|
||||
mask_key: list[int]
|
||||
# TODO: add these
|
||||
# height
|
||||
# width
|
||||
# max_nkode_len
|
||||
|
||||
@staticmethod
|
||||
def new_user_encipher_keys(height: int, width: int, set_values: list[int]):
|
||||
@@ -32,13 +36,23 @@ class CustomerAttribute(BaseModel):
|
||||
|
||||
|
||||
class CustomerInterface(BaseModel):
|
||||
# base_interface: { set0: [attr0 ... attrN], ... setM: [(val0, setM) ... (valN, setM)]}
|
||||
# base_interface: { set0: [(attr0, set0) ... (attrN, set0)], ... setM: [(attr0, setM) ... (attrN, setM)]}
|
||||
base_interface: dict[int, CustomerAttribute]
|
||||
height: int
|
||||
width: int
|
||||
|
||||
def __init__(self, **data):
|
||||
super().__init__(**data)
|
||||
self._set_index_lookup: dict[int, int] = {}
|
||||
self._attr_index_lookup: dict[CustomerAttribute: (int, int)] = {}
|
||||
self._map_base_interface()
|
||||
|
||||
def _map_base_interface(self):
|
||||
for set_idx, set_val in enumerate(self.base_interface.keys()):
|
||||
attrs = self.base_interface[set_val]
|
||||
self._set_index_lookup[set_val] = set_idx
|
||||
for attr_idx, attr in enumerate(attrs):
|
||||
self._attr_index_lookup[attr] = attr_idx
|
||||
|
||||
@staticmethod
|
||||
def new_interface(height: int, width: int):
|
||||
@@ -58,12 +72,22 @@ class CustomerInterface(BaseModel):
|
||||
possible_set_vals.remove(cur_set)
|
||||
|
||||
return CustomerInterface(
|
||||
base_interface=base_interface
|
||||
base_interface=base_interface,
|
||||
height=height,
|
||||
width=width,
|
||||
)
|
||||
|
||||
def get_set_values(self) -> list[int]:
|
||||
return list(self.base_interface.keys())
|
||||
|
||||
def get_attr_index(self, attr: CustomerAttribute) -> int:
|
||||
assert(attr in self._attr_index_lookup.keys())
|
||||
return self._attr_index_lookup[attr]
|
||||
|
||||
def get_set_index(self, set_val: int) -> int:
|
||||
assert(set_val in self.get_set_values())
|
||||
return self._set_index_lookup[set_val]
|
||||
|
||||
|
||||
class EncipheredNKode(BaseModel):
|
||||
code: str
|
||||
|
||||
Reference in New Issue
Block a user