How to use the ciphey.iface.registry.register function in ciphey

To help you get started, weโ€™ve selected a few ciphey examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github brandonskerritt / Ciphey / ciphey / basemods / Decoders / octal.py View on Github external
from typing import Optional, Dict, Any

from loguru import logger

import ciphey
from ciphey.iface import registry


@registry.register
class Octal(ciphey.iface.Decoder[str, bytes]):
    @staticmethod
    def getTarget() -> str:
        return "octal"

    def decode(self, text: str) -> Optional[bytes]:
        """
        It takes an octal string and return a string
            :octal_str: octal str like "110 145 154"
        """
        str_converted = []
        octal_seq = text.split(" ")
        if len(octal_seq) == 1:
            # Concatted octal must be formed of octal triplets
            if len(text) % 3 != 0:
                return None
github brandonskerritt / Ciphey / ciphey / basemods / WordLists / __init__.py View on Github external
from typing import Optional, Dict, Any

import ciphey
import cipheydists

from ciphey.iface import T, id_lambda

for i in ["english", "english1000"]:
    t = type(i, (ciphey.iface.WordList,), {
        "get_wordlist": lambda self: cipheydists.get_list(i),
        "getArgs": id_lambda(None),
        "getName": id_lambda(f"cipheydists::{i}"),
        "__init__": lambda self, config: super(type(self), self).__init__(config)
    })

    ciphey.iface.registry.register(t, ciphey.iface.WordList[str])

class Json:
    @staticmethod
    def getName() -> str:
        return "json"

    @staticmethod
    def getArgs() -> Optional[Dict[str, Dict[str, Any]]]:
        return None

    def get_wordlist(self) -> T:
        return cipheydists.get_list(i)

    def __init__(self, config: Dict[str, object]):
        super().__init__(config)
github brandonskerritt / Ciphey / ciphey / basemods / Searchers / imperfection.py View on Github external
from .ausearch import Node, AuSearch
from ciphey.iface import (
    SearchLevel,
    Config,
    registry,
    CrackResult,
    Searcher,
    ParamSpec,
    Decoder,
    DecoderComparer,
)

import bisect


@registry.register
class Imperfection(AuSearch):
    """The default search module for Ciphey

    Called imperfection because ironically it is pretty perfect.

    """
    @staticmethod
    def getParams() -> Optional[Dict[str, ParamSpec]]:
        pass

    def findBestNode(self, nodes: Set[Node]) -> Node:
        return next(iter(nodes))

    def __init__(self, config: Config):
        super().__init__(config)
github brandonskerritt / Ciphey / ciphey / basemods / Decoders / bases.py View on Github external
def gen_class(name, decoder, priority, ns):
    ns["_get_func"] = ciphey.common.id_lambda(decoder)
    ns["decode"] = lambda self, ctext: _dispatch(self, ctext, self._get_func())
    ns["getParams"] = ciphey.common.id_lambda(None)
    ns["getTarget"] = ciphey.common.id_lambda(name)
    ns["priority"] = ciphey.common.id_lambda(priority)
    ns["__init__"] = lambda self, config: super(type(self), self).__init__(config)


for name, (decoder, priority) in _bases.items():
    t = types.new_class(name, (ciphey.iface.Decoder[str, bytes],),
                        exec_body=lambda x: gen_class(name, decoder, priority, x))

    ciphey.iface.registry.register(t)
github brandonskerritt / Ciphey / ciphey / basemods / Checkers / regex.py View on Github external
from typing import Optional, Dict

import ciphey
import re
from ciphey.iface import ParamSpec, T, Config, registry

from loguru import logger


@registry.register
class Regex(ciphey.iface.Checker[str]):
    def getExpectedRuntime(self, text: T) -> float:
        return 1e-5  # TODO: actually calculate this

    def __init__(self, config: Config):
        super().__init__(config)
        self.regexes = list(map(re.compile, self._params()["regex"]))
        logger.trace(f"There are {len(self.regexes)} regexes")

    def check(self, text: str) -> Optional[str]:
        for regex in self.regexes:
            logger.trace(f"Trying regex {regex} on {text}")
            res = regex.search(text)
            logger.trace(f"Results: {res}")
            if res:
                return f"passed with regex {regex}"
github brandonskerritt / Ciphey / ciphey / basemods / Searchers / perfection.py View on Github external
SearchLevel,
    Config,
    registry,
    CrackResult,
    Searcher,
    ParamSpec,
    Decoder,
    DecoderComparer,
)

import bisect

import cipheycore


@registry.register
class Perfection(AuSearch):
    @staticmethod
    def getParams() -> Optional[Dict[str, ParamSpec]]:
        pass

    def findBestNode(self, nodes: List[Node]) -> Node:
        trans_nodes = []
        for node in nodes:
            info = node.cracker.getInfo(node.parents[-1].result.value)
            trans_nodes.append(cipheycore.ausearch_node(info.success_likelihood,
                                                        info.success_runtime, info.failure_runtime))
        ret = nodes[cipheycore.ausearch_minimise(trans_nodes)]
        logger.debug(f"Selected {ret}")
        return ret

    def __init__(self, config: Config):
github brandonskerritt / Ciphey / ciphey / basemods / Decoders / unicode.py View on Github external
from typing import Optional, Dict, Any

from loguru import logger

import ciphey
from ciphey.iface import registry


@registry.register
class Utf8(ciphey.iface.Decoder[bytes, str]):
    @staticmethod
    def getTarget() -> str:
        return "utf8"

    def decode(self, text: bytes) -> Optional[str]:
        logger.trace("Attempting utf-8 decode")
        try:
            res = text.decode("utf8")
            logger.debug(f"utf-8 decode gave '{res}'")
            return res if len(res) != 0 else None
        except UnicodeDecodeError:
            logger.trace("utf-8 decode failed")
            return None

    @staticmethod
github brandonskerritt / Ciphey / ciphey / basemods / Decoders / morse.py View on Github external
from typing import Optional, Dict, Any, List
import re
from loguru import logger
import ciphey
from ciphey.iface import registry


@registry.register
class MorseCode(ciphey.iface.Decoder[str, str]):
    # A priority list for char/word boundaries
    BOUNDARIES = {" ": 1, "/": 2, "\n": 3, ".": -1, "-": -1}
    MAX_PRIORITY = 3
    ALLOWED = {".", "-", " ", "/", "\n"}
    MORSE_CODE_DICT: Dict[str, str]
    MORSE_CODE_DICT_INV: Dict[str, str]

    @staticmethod
    def getTarget() -> str:
        return "morse"

    def decode(self, text: str) -> Optional[str]:
        # Trim end
        while text[-1] in self.BOUNDARIES:
            text = text[:-1]