Пример #1
0
 def __init__(self, key='phqgmeaylnofdxkrcvszwbuti', period=5):
     self.key = [k.upper() for k in key]
     self.pb = PolybiusSquare(self.key, size=5)
     self.period = period
     assert len(
         key
     ) == 25, 'invalid key in init: must have length 25, has length ' + str(
         len(key))
     assert period >= 1, 'invalid period in init: period should be >= 1'
Пример #2
0
    def decipher(self, string):
        """Decipher string using ADFGX cipher according to initialised key information. Punctuation and whitespace
        are removed from the input.       

        Example::

            plaintext = ADFGX('phqgmeaylnofdxkrcvszwbuti','HELLO').decipher(ciphertext)     

        :param string: The string to decipher.
        :returns: The enciphered string.
        """
        step2 = ColTrans(self.keyword).decipher(string)
        step1 = PolybiusSquare(self.key, size=5, chars='ADFGX').decipher(step2)
        return step1
Пример #3
0
    def encipher(self, string):
        """Encipher string using ADFGVX cipher according to initialised key information. Punctuation and whitespace
        are removed from the input.       

        Example::

            ciphertext = ADFGVX('ph0qg64mea1yl2nofdxkr3cvs5zw7bj9uti8','HELLO').encipher(plaintext)     

        :param string: The string to encipher.
        :returns: The enciphered string.
        """
        step1 = PolybiusSquare(self.key, size=6,
                               chars='ADFGVX').encipher(string)
        step2 = ColTrans(self.keyword).encipher(step1)
        return step2