How to use the ciphey.iface 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 / Resources / files.py View on Github external
def getName() -> str:
        return "json"

    @staticmethod
    def getParams() -> Optional[Dict[str, ciphey.iface.ParamSpec]]:
        return {"path": ParamSpec(req=True, desc="The path to a JSON file", list=True)}

    def __init__(self, config: ciphey.iface.Config):
        super().__init__(config)
        self._paths = self._params()["path"]
        self._names = set(range(1, len(self._paths)))


# We can use a generic resource loader here, as we can instantiate it later
@registry.register_multi(ciphey.iface.WordList, ciphey.iface.Distribution)
class Csv(Generic[T], ciphey.iface.ResourceLoader[T]):
    def whatResources(self) -> Set[str]:
        return self._names

    @lru_cache
    def getResource(self, name: str) -> T:
        prefix, name = name.split("::", 1)
        return {
            "wordlist": (lambda reader: {i[0] for i in reader}),
            "dist": (lambda reader: {i[0]: float(i[1]) for i in reader}),
        }[prefix](csv.reader(open(self._paths[int(name) - 1])))

    @staticmethod
    def getName() -> str:
        return "csv"

    @staticmethod
github brandonskerritt / Ciphey / ciphey / basemods / Checkers / quorum.py View on Github external
from math import ceil
from typing import Optional, Dict, Generic

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


class Quorum(Generic[T], ciphey.iface.Checker[T]):
    def check(self, text: T) -> Optional[str]:
        left = self._params().k
        results = []
        for checker in self.checkers:
            results.append(checker.check(text))
            if results[-1] is None:
                continue
            left -= 1
            # Early return check
            if left == 0:
                return str(results)

    def __init__(self, config: Config):
        super().__init__(config)

        if self._params().k is None:
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}"