def test_duration_of_ascii_encryption(self): """ Ensure that the encryption time is kept fairly low. """ f = FeistelCipher() key = "sandvest" start = time.time() f.encrypt(self.long_string, key) end = time.time() print("Long string single encryption: %fms" % ((end - start) * 1000)) self.assertLess((end - start), 0.2)
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)