fix pydantic error
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
import secrets
|
import secrets
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
class DarcKeyTypes(str, Enum):
|
class DarcKeyType(str, Enum):
|
||||||
outer_shuffle = "outer_shuffle"
|
outer_shuffle = "outer_shuffle"
|
||||||
inner_shuffle = "inner_shuffle"
|
inner_shuffle = "inner_shuffle"
|
||||||
alphabet = "alphabet"
|
alphabet = "alphabet"
|
||||||
@@ -13,7 +12,7 @@ class DarcKeyTypes(str, Enum):
|
|||||||
|
|
||||||
class DarcKey(BaseModel):
|
class DarcKey(BaseModel):
|
||||||
matrix: list[list[int]]
|
matrix: list[list[int]]
|
||||||
key_type: DarcKeyTypes
|
key_type: DarcKeyType
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _random_shuffle(cls, array: list[int]) -> list[int]:
|
def _random_shuffle(cls, array: list[int]) -> list[int]:
|
||||||
@@ -34,7 +33,7 @@ class DarcKey(BaseModel):
|
|||||||
def __lshift__(self, other):
|
def __lshift__(self, other):
|
||||||
assert len(self.matrix) == len(other.matrix)
|
assert len(self.matrix) == len(other.matrix)
|
||||||
assert len(self.matrix[0]) == len(other.matrix[0])
|
assert len(self.matrix[0]) == len(other.matrix[0])
|
||||||
assert other.key_type == DarcKeyTypes.inner_shuffle or other.key_type == DarcKeyTypes.outer_shuffle
|
assert other.key_type == DarcKeyType.inner_shuffle or other.key_type == DarcKeyType.outer_shuffle
|
||||||
output = []
|
output = []
|
||||||
for i, el in enumerate(self.matrix):
|
for i, el in enumerate(self.matrix):
|
||||||
row = []
|
row = []
|
||||||
@@ -50,7 +49,7 @@ class DarcKey(BaseModel):
|
|||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
assert len(other.matrix) == 1
|
assert len(other.matrix) == 1
|
||||||
assert len(self.matrix) == len(other.matrix[0])
|
assert len(self.matrix) == len(other.matrix[0])
|
||||||
assert other.key_type == DarcKeyTypes.outer_shuffle
|
assert other.key_type == DarcKeyType.outer_shuffle
|
||||||
output = []
|
output = []
|
||||||
for i, _ in enumerate(self.matrix):
|
for i, _ in enumerate(self.matrix):
|
||||||
output.append(self.matrix[other.matrix[0][i]])
|
output.append(self.matrix[other.matrix[0][i]])
|
||||||
@@ -62,8 +61,8 @@ class DarcKey(BaseModel):
|
|||||||
def __xor__(self, other):
|
def __xor__(self, other):
|
||||||
assert len(self.matrix) == len(other.matrix)
|
assert len(self.matrix) == len(other.matrix)
|
||||||
assert len(self.matrix[0]) == len(other.matrix[0])
|
assert len(self.matrix[0]) == len(other.matrix[0])
|
||||||
assert self.key_type == DarcKeyTypes.alphabet
|
assert self.key_type == DarcKeyType.alphabet
|
||||||
assert other.key_type == DarcKeyTypes.alphabet
|
assert other.key_type == DarcKeyType.alphabet
|
||||||
output = []
|
output = []
|
||||||
for i, el in enumerate(self.matrix):
|
for i, el in enumerate(self.matrix):
|
||||||
row = []
|
row = []
|
||||||
@@ -76,7 +75,7 @@ class DarcKey(BaseModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def __invert__(self):
|
def __invert__(self):
|
||||||
assert self.key_type == DarcKeyTypes.inner_shuffle or self.key_type == DarcKeyTypes.outer_shuffle
|
assert self.key_type == DarcKeyType.inner_shuffle or self.key_type == DarcKeyType.outer_shuffle
|
||||||
|
|
||||||
output = []
|
output = []
|
||||||
for i, el in enumerate(self.matrix):
|
for i, el in enumerate(self.matrix):
|
||||||
@@ -103,12 +102,11 @@ class DarcKey(BaseModel):
|
|||||||
for j in range(len(self.matrix[0])):
|
for j in range(len(self.matrix[0])):
|
||||||
if self.matrix[i][j] != other.matrix[i][j]:
|
if self.matrix[i][j] != other.matrix[i][j]:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class OuterKey(DarcKey):
|
class OuterKey(DarcKey):
|
||||||
key_type = DarcKeyTypes.outer_shuffle
|
key_type: DarcKeyType = DarcKeyType.outer_shuffle
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def init_matrix(cls, height: int):
|
def init_matrix(cls, height: int):
|
||||||
@@ -120,7 +118,7 @@ class OuterKey(DarcKey):
|
|||||||
|
|
||||||
|
|
||||||
class InnerKey(DarcKey):
|
class InnerKey(DarcKey):
|
||||||
key_type = DarcKeyTypes.inner_shuffle
|
key_type: DarcKeyType = DarcKeyType.inner_shuffle
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def init_matrix(cls, width: int, height: int):
|
def init_matrix(cls, width: int, height: int):
|
||||||
@@ -132,7 +130,7 @@ class InnerKey(DarcKey):
|
|||||||
|
|
||||||
|
|
||||||
class AlphabetKey(DarcKey):
|
class AlphabetKey(DarcKey):
|
||||||
key_type = DarcKeyTypes.alphabet
|
key_type: DarcKeyType = DarcKeyType.alphabet
|
||||||
max_value: int = 255
|
max_value: int = 255
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -146,7 +144,7 @@ class AlphabetKey(DarcKey):
|
|||||||
|
|
||||||
|
|
||||||
class Mask(DarcKey):
|
class Mask(DarcKey):
|
||||||
key_type = DarcKeyTypes.alphabet
|
key_type: DarcKeyType = DarcKeyType.alphabet
|
||||||
max_value: int = 255
|
max_value: int = 255
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user