def encrypt_ascii(text_to_encrypt): f = FeistelCipher() cipher = f.encrypt(text_to_encrypt, "sandvest") decrypted = f.decrypt(cipher.tobytes(), "sandvest") decrypted_text = decrypted.tobytes() decrypted_text = decrypted_text.replace("\x00", "") return decrypted_text
def test_binary_encryption(self): """ Verify that encryption/decryption works for binary input as well. """ des = FeistelCipher() text_to_encrypt = "1010010100101010100001" cipher = des.encrypt(text_to_encrypt, "sandvest") decrypted = des.decrypt(cipher.to01(), "sandvest") decrypted = parse_decrypted_cipher(len(bitarray(text_to_encrypt)), decrypted.to01()) self.assertEquals(text_to_encrypt, decrypted)