コード例 #1
0
    def decode(self, text: str):
        """
        Decipher an input ROT-13 ciphertext.

        :param text: input ciphertext
        """
        return shift_mono(parse_text(text), 13)
コード例 #2
0
    def encode(self, text: str):
        """
        Encipher an input plaintext using ROT-13.

        :param text: input plaintext
        """
        return shift_mono(parse_text(text), 13)
コード例 #3
0
def get_ngrams(text: str, n: int):
    """
    Returns a list of n-grams from an input text
        text (str): input text
        n (int): number of characters for each item
    """
    return [text[i:i + n] for i in range(len(parse_text(text)) - n + 1)]
コード例 #4
0
    def decode(self, text: str):
        """
        Decipher an input Atbash ciphertext.

        :param text: input ciphertext
        """
        text = parse_text(text)
        out = [chr(122 - ord(text[i]) + 97) for i in range(len(text))]
        return ''.join(str(x) for x in out)
コード例 #5
0
 def encode(self, text: str):
     """
     Encipher an input plaintext using Atbash.
     
     :param text: input plaintext
     """
     text = parse_text(text)
     out = [chr(122 - ord(text[i]) + 97) for i in range(len(text))]
     return ''.join(str(x) for x in out)
コード例 #6
0
def find_ngram_equivalents(text: str, ngrams: list, n: int):
    """
    Converts a text into a set of n-grams, and returns the common
    n-grams between the n-grams of the text and an input n-gram list.
    """
    return list(set(get_ngrams(parse_text(text), n)).intersection(ngrams))