def vigenere_decode(self, key: str): """Decode Vigenere ciper Args: key (str): Required. The secret key Returns: Chepy: The Chepy oject. Examples: >>> Chepy("KIEIIM").vigenere_decode("secret").o "SECRET" """ self.state = pycipher.Vigenere(key=key).decipher(self._convert_to_str()) return self
def vigenere_encode(self, key: str) -> EncryptionEncodingT: """Encode with Vigenere ciper Args: key (str): Required. The secret key Returns: Chepy: The Chepy oject. Examples: >>> Chepy("secret").vigenere_encode("secret").o "KIEIIM" """ self.state = pycipher.Vigenere(key=key).encipher( self._convert_to_str()) return self
def decryption(self, text): if cipher == 1: ciphertext = self.ids.dtext.text self.ids.dtext.t = pycipher.Caesar(cshift).decipher(ciphertext, keep_punct=bl) elif cipher == 2: ciphertext = self.ids.dtext.text self.ids.dtext.text = pycipher.Autokey(k).decipher(ciphertext) elif cipher == 3: ciphertext = self.ids.dtext.text self.ids.dtext.text = pycipher.Vigenere(k).decipher(ciphertext) elif cipher == 4: ciphertext = self.ids.dtext.text self.ids.dtext.text = pycipher.Playfair(k).decipher(ciphertext)
def encryption(self, text): if cipher == 1: plaintext = self.ids.ptext.text encryption = pycipher.Caesar(cshift).encipher(plaintext, keep_punct=bl) self.ids.ptext.text = str(salt) + str(encryption) elif cipher == 2: plaintext = self.ids.ptext.text self.ids.ptext.text = pycipher.Autokey(k).encipher(plaintext) elif cipher == 3: plaintext = self.ids.ptext.text self.ids.ptext.text = pycipher.Vigenere(k).encipher(plaintext) elif cipher == 4: plaintext = self.ids.ptext.text self.ids.ptext.text = pycipher.Playfair(k).encipher(plaintext)
import pycipher txt = input('Text: ') key = input('Key: ') plaintext = pycipher.Vigenere(key).decipher(txt) print(plaintext)
def test_vigenere_cipher(text, key, process): """Return None if the assert statement is true.""" if process == 'encrypt': assert vigenere_cipher(text, key, 'encrypt') == restore_original_format(text, pycipher.Vigenere(key).encipher(text)) elif process == 'decrypt': assert vigenere_cipher(text, key, 'decrypt') == restore_original_format(text, pycipher.Vigenere(key).decipher(text))
if __name__ == "__main__": iterable = "abcdefghijklmnopqrstuvwxyz" known_pt = "blais" ct = "uucbxsimbjyaqyvzbzfdatshktkbde" #product = itertools.combinations(iterable, 4) # WRONG product = itertools.product(iterable, repeat=4) # Add known pt to key, in form 'blais----' for i in product: key = known_pt # Append letters from tuple to key for letter in i: key += letter #print(i) #print(key) pt = pycipher.Vigenere(key).decipher(ct).lower() # Split plaintext into two to add the curly braces, then combine again pt_1 = pt[:5] pt_2 = pt[5:] pt = pt_1 + "{" + pt_2 + "}" #print(pt) # Append to file file = open("vinegar_pt.txt", "a") file.write(pt + "\n")