Exemplo n.º 1
0
 def __init__(self):  # pragma: no cover
     self.methods = [
         self.Base64,
         self.Ascii,
         self.Base16,
         self.Base32,
         self.Binary,
         self.Hex,
         self.MorseCode,
         self.Reverse,
         self.Vigenere,
     ]
     self.morse_dict = dict(cipheydists.get_charset("morse"))
     self.letters = string.ascii_lowercase
     self.group = cipheydists.get_charset("english")["lcase"]
Exemplo n.º 2
0
 def __init__(
     self,
     text: str,
     flip: bool = bool(random.randint(0, 1)),
     randomize: bool = True,
     key: list = None,
 ):
     self.ASCII = cipheydists.get_charset("asciiTable")
     self.text = text.lower()
     self.ctext = ""
     self.flip = flip
     self.randomize = randomize
     self.key = key
Exemplo n.º 3
0
    def decrypt(self, message):
        logger.debug("Trying caesar Cipher")
        # Convert it to lower case
        #
        # TODO: handle different alphabets
        message = message.lower()

        # Hand it off to the core
        group = cipheydists.get_charset("english")["lcase"]
        expected = cipheydists.get_dist("lcase")
        analysis = cipheycore.analyse_string(message)
        possible_keys = cipheycore.caesar_crack(analysis, expected, group)
        n_candidates = len(possible_keys)
        logger.debug(f"Caesar cipher core heuristic returned {n_candidates} candidates")

        for candidate in possible_keys:
            translated = cipheycore.caesar_decrypt(message, candidate.key, group)
            result = self.lc.checkLanguage(translated)
            if result:
                logger.debug(f"Caesar cipher returns true {result}")
                return {
                    "lc": self.lc,
                    "IsPlaintext?": True,
                    "Plaintext": translated,
                    "Cipher": "Caesar",
                    "Extra Information": f"The rotation used is {candidate.key}",
                }

        # if none of them match English, return false!
        logger.debug(f"Caesar cipher returns false")
        return {
            "lc": self.lc,
            "IsPlaintext?": False,
            "Plaintext": None,
            "Cipher": "Caesar",
            "Extra Information": None,
        }
Exemplo n.º 4
0
 def __init__(self, lc):
     self.lc = lc
     self.ALLOWED = [".", "-", " ", "/", "\n"]
     self.MORSE_CODE_DICT = dict(cipheydists.get_charset("morse"))
     self.MORSE_CODE_DICT_INV = {v: k for k, v in self.MORSE_CODE_DICT.items()}