cleanup to read as equation
This commit is contained in:
@@ -106,23 +106,6 @@ class DarcKey(BaseModel):
|
||||
|
||||
return True
|
||||
|
||||
def column_substitution(self, column: int, substitution: list[int]):
|
||||
assert len(substitution) == len(self.matrix)
|
||||
assert len(self.matrix[0]) > column >= 0
|
||||
output = []
|
||||
for i, el in enumerate(self.matrix):
|
||||
row = []
|
||||
for j, el2 in enumerate(el):
|
||||
if j == column:
|
||||
row.append(substitution[i])
|
||||
else:
|
||||
row.append(el2)
|
||||
output.append(row)
|
||||
return DarcKey(
|
||||
matrix=output,
|
||||
key_type=self.key_type
|
||||
)
|
||||
|
||||
|
||||
class OuterKey(DarcKey):
|
||||
key_type = DarcKeyTypes.outer_shuffle
|
||||
@@ -162,6 +145,25 @@ class AlphabetKey(DarcKey):
|
||||
)
|
||||
|
||||
|
||||
class Mask(DarcKey):
|
||||
key_type = DarcKeyTypes.alphabet
|
||||
max_value: int = 255
|
||||
|
||||
@classmethod
|
||||
def init_matrix(cls, width: int, height: int, col_mask: int):
|
||||
""" originally buildScramble """
|
||||
|
||||
mask = cls._random_mask(width, cls.max_value)
|
||||
matrix = [[0 for _ in range(width)] for _ in range(height)]
|
||||
if col_mask < height:
|
||||
matrix[col_mask] = mask
|
||||
|
||||
return Mask(
|
||||
matrix=matrix,
|
||||
max_value=cls.max_value
|
||||
)
|
||||
|
||||
|
||||
class ClientEphemeralDataKeys(BaseModel):
|
||||
outer_key_1: OuterKey
|
||||
outer_key_2: OuterKey
|
||||
|
||||
Reference in New Issue
Block a user