Refactor AlphabetKet to SubstitutionKey
This commit is contained in:
@@ -6,7 +6,7 @@ from pydantic import BaseModel
|
||||
class DarcKeyType(str, Enum):
|
||||
outer_shuffle = "outer_shuffle"
|
||||
inner_shuffle = "inner_shuffle"
|
||||
alphabet = "alphabet"
|
||||
substitution = "substitution"
|
||||
other = "other"
|
||||
|
||||
|
||||
@@ -61,8 +61,8 @@ class DarcKey(BaseModel):
|
||||
def __xor__(self, other):
|
||||
assert len(self.matrix) == len(other.matrix)
|
||||
assert len(self.matrix[0]) == len(other.matrix[0])
|
||||
assert self.key_type == DarcKeyType.alphabet
|
||||
assert other.key_type == DarcKeyType.alphabet
|
||||
assert self.key_type == DarcKeyType.substitution
|
||||
assert other.key_type == DarcKeyType.substitution
|
||||
output = []
|
||||
for i, el in enumerate(self.matrix):
|
||||
row = []
|
||||
@@ -129,21 +129,21 @@ class InnerKey(DarcKey):
|
||||
)
|
||||
|
||||
|
||||
class AlphabetKey(DarcKey):
|
||||
key_type: DarcKeyType = DarcKeyType.alphabet
|
||||
class SubstitutionKey(DarcKey):
|
||||
key_type: DarcKeyType = DarcKeyType.substitution
|
||||
|
||||
@classmethod
|
||||
def init_matrix(cls, width: int, height: int, max_value: int):
|
||||
def init_matrix(cls, width: int, height: int, max_value: int = 255):
|
||||
""" originally buildScramble """
|
||||
matrix = [cls._random_mask(width, max_value) for _ in range(height)]
|
||||
return AlphabetKey(
|
||||
return SubstitutionKey(
|
||||
matrix=matrix,
|
||||
max_value=max_value
|
||||
)
|
||||
|
||||
|
||||
class Mask(DarcKey):
|
||||
key_type: DarcKeyType = DarcKeyType.alphabet
|
||||
key_type: DarcKeyType = DarcKeyType.substitution
|
||||
|
||||
@classmethod
|
||||
def init_matrix(cls, width: int, height: int, col_mask: int):
|
||||
@@ -162,7 +162,7 @@ class Mask(DarcKey):
|
||||
class ClientEphemeralDataKeys(BaseModel):
|
||||
outer_key_1: OuterKey
|
||||
outer_key_2: OuterKey
|
||||
alpha_key: AlphabetKey
|
||||
alpha_key: SubstitutionKey
|
||||
inner_key_1: InnerKey
|
||||
|
||||
@classmethod
|
||||
@@ -170,7 +170,7 @@ class ClientEphemeralDataKeys(BaseModel):
|
||||
return ClientEphemeralDataKeys(
|
||||
outer_key_1=OuterKey.init_matrix(height),
|
||||
outer_key_2=OuterKey.init_matrix(height),
|
||||
alpha_key=AlphabetKey.init_matrix(width, height, 255),
|
||||
alpha_key=SubstitutionKey.init_matrix(width, height, 255),
|
||||
inner_key_1=InnerKey.init_matrix(width, height),
|
||||
)
|
||||
|
||||
@@ -179,7 +179,7 @@ class ClientEphemeralMediumKeys(BaseModel):
|
||||
outer_key_1: OuterKey
|
||||
outer_key_2: OuterKey
|
||||
inner_key_1: InnerKey
|
||||
alpha_key: AlphabetKey
|
||||
alpha_key: SubstitutionKey
|
||||
|
||||
@classmethod
|
||||
def random_init(cls, height: int, width: int):
|
||||
@@ -187,12 +187,12 @@ class ClientEphemeralMediumKeys(BaseModel):
|
||||
outer_key_1=OuterKey.init_matrix(height),
|
||||
outer_key_2=OuterKey.init_matrix(height),
|
||||
inner_key_1=InnerKey.init_matrix(width, height),
|
||||
alpha_key=AlphabetKey.init_matrix(width, height, 255)
|
||||
alpha_key=SubstitutionKey.init_matrix(width, height, 255)
|
||||
)
|
||||
|
||||
|
||||
class ClientPersistentDataKeys(BaseModel):
|
||||
alpha_key: AlphabetKey
|
||||
alpha_key: SubstitutionKey
|
||||
inner_key_1: InnerKey
|
||||
outer_key_1: OuterKey
|
||||
outer_key_2: OuterKey
|
||||
@@ -200,7 +200,7 @@ class ClientPersistentDataKeys(BaseModel):
|
||||
@classmethod
|
||||
def random_init(cls, height: int, width: int):
|
||||
return ClientPersistentDataKeys(
|
||||
alpha_key=AlphabetKey.init_matrix(width, height, 255),
|
||||
alpha_key=SubstitutionKey.init_matrix(width, height, 255),
|
||||
inner_key_1=InnerKey.init_matrix(width, height),
|
||||
outer_key_1=OuterKey.init_matrix(height),
|
||||
outer_key_2=OuterKey.init_matrix(height),
|
||||
@@ -211,7 +211,7 @@ class ClientPersistentMediumKeys(BaseModel):
|
||||
outer_key_1: OuterKey
|
||||
outer_key_2: OuterKey
|
||||
inner_key_1: InnerKey
|
||||
alpha_key: AlphabetKey
|
||||
alpha_key: SubstitutionKey
|
||||
|
||||
@classmethod
|
||||
def random_init(cls, height: int, width: int):
|
||||
@@ -219,60 +219,60 @@ class ClientPersistentMediumKeys(BaseModel):
|
||||
outer_key_1=OuterKey.init_matrix(height),
|
||||
outer_key_2=OuterKey.init_matrix(height),
|
||||
inner_key_1=InnerKey.init_matrix(width, height),
|
||||
alpha_key=AlphabetKey.init_matrix(width, height, 255)
|
||||
alpha_key=SubstitutionKey.init_matrix(width, height, 255)
|
||||
)
|
||||
|
||||
|
||||
class ServerEphemeralDataKeys(BaseModel):
|
||||
outer_key_1: OuterKey
|
||||
alpha_key: AlphabetKey
|
||||
alpha_key: SubstitutionKey
|
||||
inner_key_1: InnerKey
|
||||
|
||||
@classmethod
|
||||
def random_init(cls, height: int, width: int):
|
||||
return ServerEphemeralDataKeys(
|
||||
outer_key_1=OuterKey.init_matrix(height),
|
||||
alpha_key=AlphabetKey.init_matrix(width, height, 255),
|
||||
alpha_key=SubstitutionKey.init_matrix(width, height, 255),
|
||||
inner_key_1=InnerKey.init_matrix(width, height),
|
||||
)
|
||||
|
||||
|
||||
class ServerEphemeralMediumKeys(BaseModel):
|
||||
alpha_key: AlphabetKey
|
||||
alpha_key: SubstitutionKey
|
||||
|
||||
@classmethod
|
||||
def random_init(cls, height: int, width: int):
|
||||
return ServerEphemeralMediumKeys(
|
||||
alpha_key=AlphabetKey.init_matrix(width, height, 255)
|
||||
alpha_key=SubstitutionKey.init_matrix(width, height, 255)
|
||||
)
|
||||
|
||||
|
||||
class ServerPersistentDataKeys(BaseModel):
|
||||
outer_key_1: OuterKey
|
||||
alpha_key: AlphabetKey
|
||||
alpha_key: SubstitutionKey
|
||||
inner_key_1: InnerKey
|
||||
|
||||
@classmethod
|
||||
def random_init(cls, height: int, width: int):
|
||||
return ServerPersistentDataKeys(
|
||||
outer_key_1=OuterKey.init_matrix(height),
|
||||
alpha_key=AlphabetKey.init_matrix(width, height, 255),
|
||||
alpha_key=SubstitutionKey.init_matrix(width, height, 255),
|
||||
inner_key_1=InnerKey.init_matrix(width, height),
|
||||
)
|
||||
|
||||
|
||||
class ServerPersistentMediumKeys(BaseModel):
|
||||
alpha_key: AlphabetKey
|
||||
alpha_key: SubstitutionKey
|
||||
|
||||
@classmethod
|
||||
def random_init(cls, height: int, width: int):
|
||||
return ServerPersistentMediumKeys(
|
||||
alpha_key=AlphabetKey.init_matrix(width, height, 255)
|
||||
alpha_key=SubstitutionKey.init_matrix(width, height, 255)
|
||||
)
|
||||
|
||||
|
||||
class MutualEphemeralDataKeys(BaseModel):
|
||||
alpha_key: AlphabetKey
|
||||
alpha_key: SubstitutionKey
|
||||
inner_key_1: InnerKey
|
||||
outer_key_1: OuterKey
|
||||
outer_key_2: OuterKey
|
||||
@@ -281,7 +281,7 @@ class MutualEphemeralDataKeys(BaseModel):
|
||||
@classmethod
|
||||
def random_init(cls, height: int, width: int):
|
||||
return MutualEphemeralDataKeys(
|
||||
alpha_key=AlphabetKey.init_matrix(width, height, 255),
|
||||
alpha_key=SubstitutionKey.init_matrix(width, height, 255),
|
||||
inner_key_1=InnerKey.init_matrix(width, height),
|
||||
outer_key_1=OuterKey.init_matrix(height),
|
||||
outer_key_2=OuterKey.init_matrix(height),
|
||||
@@ -290,7 +290,7 @@ class MutualEphemeralDataKeys(BaseModel):
|
||||
|
||||
|
||||
class MutualEphemeralMediumKeys(BaseModel):
|
||||
alpha_key: AlphabetKey
|
||||
alpha_key: SubstitutionKey
|
||||
|
||||
outer_key_1: OuterKey
|
||||
outer_key_2: OuterKey
|
||||
@@ -306,7 +306,7 @@ class MutualEphemeralMediumKeys(BaseModel):
|
||||
@classmethod
|
||||
def random_init(cls, height: int, width: int):
|
||||
return MutualEphemeralMediumKeys(
|
||||
alpha_key=AlphabetKey.init_matrix(width, height, 255),
|
||||
alpha_key=SubstitutionKey.init_matrix(width, height, 255),
|
||||
outer_key_1=OuterKey.init_matrix(height),
|
||||
outer_key_2=OuterKey.init_matrix(height),
|
||||
outer_key_3=OuterKey.init_matrix(height),
|
||||
@@ -323,7 +323,7 @@ class MutualPersistentDataKeys(BaseModel):
|
||||
outer_key_1: OuterKey
|
||||
outer_key_2: OuterKey
|
||||
outer_key_3: OuterKey
|
||||
alpha_key: AlphabetKey
|
||||
alpha_key: SubstitutionKey
|
||||
inner_key_1: InnerKey
|
||||
inner_key_2: InnerKey
|
||||
|
||||
@@ -333,14 +333,14 @@ class MutualPersistentDataKeys(BaseModel):
|
||||
outer_key_1=OuterKey.init_matrix(height),
|
||||
outer_key_2=OuterKey.init_matrix(height),
|
||||
outer_key_3=OuterKey.init_matrix(height),
|
||||
alpha_key=AlphabetKey.init_matrix(width, height, 255),
|
||||
alpha_key=SubstitutionKey.init_matrix(width, height, 255),
|
||||
inner_key_1=InnerKey.init_matrix(width, height),
|
||||
inner_key_2=InnerKey.init_matrix(width, height),
|
||||
)
|
||||
|
||||
|
||||
class MutualPersistentMediumKeys(BaseModel):
|
||||
alpha_key: AlphabetKey
|
||||
alpha_key: SubstitutionKey
|
||||
|
||||
outer_key_1: OuterKey
|
||||
outer_key_2: OuterKey
|
||||
@@ -357,7 +357,7 @@ class MutualPersistentMediumKeys(BaseModel):
|
||||
@classmethod
|
||||
def random_init(cls, height: int, width: int):
|
||||
return MutualPersistentMediumKeys(
|
||||
alpha_key=AlphabetKey.init_matrix(width, height, 255),
|
||||
alpha_key=SubstitutionKey.init_matrix(width, height, 255),
|
||||
outer_key_1=OuterKey.init_matrix(height),
|
||||
outer_key_2=OuterKey.init_matrix(height),
|
||||
outer_key_3=OuterKey.init_matrix(height),
|
||||
|
||||
Reference in New Issue
Block a user