Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, config: Config):
self._config_obj = config
if self.getParams() is not None:
self._params_obj = config.params.setdefault(type(self).__name__.lower(), {})
self._checkParams()
class Targeted(ABC):
@staticmethod
@abstractmethod
def getTarget() -> str:
"""Should return the target that this object attacks/decodes"""
pass
class Checker(Generic[T], ConfigurableModule):
@abstractmethod
def check(self, text: T) -> Optional[str]:
"""Should return some description (or an empty string) on success, otherwise return None"""
pass
@abstractmethod
def getExpectedRuntime(self, text: T) -> float:
pass
def __call__(self, *args):
return self.check(*args)
@abstractmethod
def __init__(self, config: Config):
super().__init__(config)
@abstractmethod
def __init__(self, config: Config):
super().__init__(config)
class SearchLevel(NamedTuple):
name: str
result: CrackResult
class SearchResult(NamedTuple):
path: List[SearchLevel]
check_res: str
class Searcher(ConfigurableModule):
"""A very basic interface for code that plans out how to crack the ciphertext"""
@abstractmethod
def search(self, ctext: Any) -> SearchResult:
"""Returns the path to the correct ciphertext"""
pass
@abstractmethod
def __init__(self, config: Config):
super().__init__(config)
def pretty_search_results(res: SearchResult, display_intermediate: bool = False):
ret: str = ""
if len(res.check_res) != 0:
ret += f"Checker: {res.check_res}\n"
return f""
class CrackResult(NamedTuple, Generic[T]):
value: T
key_info: Optional[str] = None
misc_info: Optional[str] = None
class CrackInfo(NamedTuple):
success_likelihood: float
success_runtime: float
failure_runtime: float
class Cracker(Generic[T], ConfigurableModule, Targeted):
@abstractmethod
def getInfo(self, ctext: T) -> CrackInfo:
"""Should return some informed guesses on resource consumption when run on `ctext`"""
pass
@abstractmethod
def attemptCrack(self, ctext: T) -> List[CrackResult]:
"""
This should attempt to crack the cipher `target`, and return a list of candidate solutions
"""
# FIXME: Actually CrackResult[T], but python complains
pass
def __call__(self, *args):
return self.attemptCrack(*args)
def attemptCrack(self, ctext: T) -> List[CrackResult]:
"""
This should attempt to crack the cipher `target`, and return a list of candidate solutions
"""
# FIXME: Actually CrackResult[T], but python complains
pass
def __call__(self, *args):
return self.attemptCrack(*args)
@abstractmethod
def __init__(self, config: Config):
super().__init__(config)
class ResourceLoader(Generic[T], ConfigurableModule):
@abstractmethod
def whatResources(self) -> Optional[Set[str]]:
"""
Return a set of the names of instances T you can provide.
The names SHOULD be unique amongst ResourceLoaders of the same type
These names will be exposed as f"{self.__name__}::{name}", use split_resource_name to recover this
If you cannot reasonably determine what resources you provide, return None instead
"""
pass
@abstractmethod
def getResource(self, name: str) -> T:
"""
Returns the requested distribution
super().__init__(config)
# class Detector(Generic[T], ConfigurableModule, KnownUtility, Targeted):
# @abstractmethod
# def scoreLikelihood(self, ctext: T) -> Dict[str, float]:
# """Should return a dictionary of (cipher_name: score)"""
# pass
#
# def __call__(self, *args): return self.scoreLikelihood(*args)
#
# @abstractmethod
# def __init__(self, config: Config): super().__init__(config)
class Decoder(Generic[T, U], ConfigurableModule, Targeted):
"""Represents the undoing of some encoding into a different (or the same) type"""
@abstractmethod
def decode(self, ctext: T) -> Optional[U]:
pass
@staticmethod
@abstractmethod
def priority() -> float:
"""What proportion of decodings are this?"""
pass
def __call__(self, *args):
return self.decode(*args)
@abstractmethod