How to use the ciphey.iface.WordList 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
    @staticmethod
    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"
github brandonskerritt / Ciphey / ciphey / basemods / Decoders / morse.py View on Github external
def __init__(self, config: ciphey.iface.Config):
        super().__init__(config)
        self.MORSE_CODE_DICT = config.get_resource(
            self._params()["dict"], ciphey.iface.WordList
        )
        self.MORSE_CODE_DICT_INV = {v: k for k, v in self.MORSE_CODE_DICT.items()}
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
github brandonskerritt / Ciphey / ciphey / basemods / Resources / cipheydists.py View on Github external
from typing import Optional, Dict, Any, Set

from functools import lru_cache

import loguru

import ciphey
import cipheydists
from ciphey.iface import ParamSpec, Config, registry, WordList, Distribution


@registry.register_multi(WordList, Distribution)
class CipheyDists(ciphey.iface.ResourceLoader):
    # _wordlists: Set[str] = frozenset({"english", "english1000", "englishStopWords"})
    # _brandons: Set[str] = frozenset({"english"})
    # _dists: Set[str] = frozenset({"twist"})
    # _translates: Set[str] = frozenset({"morse"})
    _getters = {
        "list": cipheydists.get_list,
        "dist": cipheydists.get_dist,
        "brandon": cipheydists.get_brandon,
        "translate": cipheydists.get_translate,
    }

    def whatResources(self) -> Optional[Set[str]]:
        pass

    @lru_cache