<s> from __future__ import unicode_literals , division , absolute_import , print_function <EOL> import unittest <EOL> import sys <EOL> from oscrypto import symmetric , util <EOL> from . _unittest_compat import patch <EOL> patch ( ) <EOL> if sys . version_info < ( <NUM_LIT:3> , ) : <EOL> byte_cls = str <EOL> else : <EOL> byte_cls = bytes <EOL> class SymmetricTests ( unittest . TestCase ) : <EOL> def test_aes_128_encrypt_decrypt ( self ) : <EOL> key = util . rand_bytes ( <NUM_LIT:16> ) <EOL> data = b'<STR_LIT>' <EOL> iv , ciphertext = symmetric . aes_cbc_pkcs7_encrypt ( key , data , None ) <EOL> self . assertNotEqual ( data , ciphertext ) <EOL> self . assertEqual ( byte_cls , type ( ciphertext ) ) <EOL> plaintext = symmetric . aes_cbc_pkcs7_decrypt ( key , ciphertext , iv ) <EOL> self . assertEqual ( data , plaintext ) <EOL> def test_aes_256_encrypt_decrypt ( self ) : <EOL> key = util . rand_bytes ( <NUM_LIT:32> ) <EOL> data = b'<STR_LIT>' <EOL> iv , ciphertext = symmetric . aes_cbc_pkcs7_encrypt ( key , data , None ) <EOL> self . assertNotEqual ( data , ciphertext ) <EOL> self . assertEqual ( byte_cls , type ( ciphertext ) ) <EOL> plaintext = symmetric . aes_cbc_pkcs7_decrypt ( key , ciphertext , iv ) <EOL> self . assertEqual ( data , plaintext ) <EOL> def test_rc4_40_encrypt_decrypt ( self ) : <EOL> key = util . rand_bytes ( <NUM_LIT:5> ) <EOL> data = b'<STR_LIT>' <EOL> ciphertext = symmetric . rc4_encrypt ( key , data ) <EOL> self . assertNotEqual ( data , ciphertext ) <EOL> self . assertEqual ( byte_cls , type ( ciphertext ) ) <EOL> plaintext = symmetric . rc4_decrypt ( key , ciphertext ) <EOL> self . assertEqual ( data , plaintext ) <EOL> def test_rc4_128_encrypt_decrypt ( self ) : <EOL> key = util . rand_bytes ( <NUM_LIT:16> ) <EOL> data = b'<STR_LIT>' <EOL> ciphertext = symmetric . rc4_encrypt ( key , data ) <EOL> self . assertNotEqual ( data , ciphertext ) <EOL> self . assertEqual ( byte_cls , type ( ciphertext ) ) <EOL> plaintext = symmetric . rc4_decrypt ( key , ciphertext ) <EOL> self . assertEqual ( data , plaintext ) <EOL> def test_rc2_64_encrypt_decrypt ( self ) : <EOL> key = util . rand_bytes ( <NUM_LIT:8> ) <EOL> data = b'<STR_LIT>' <EOL> iv , ciphertext = symmetric . rc2_cbc_pkcs5_encrypt ( key , data , None ) <EOL> self . assertNotEqual ( data , ciphertext ) <EOL> self . assertEqual ( byte_cls , type ( ciphertext ) ) <EOL> plaintext = symmetric . rc2_cbc_pkcs5_decrypt ( key , ciphertext , iv ) <EOL> self . assertEqual ( data , plaintext ) <EOL> def test_rc2_40_encrypt_decrypt ( self ) : <EOL> key = util . rand_bytes ( <NUM_LIT:5> ) <EOL> data = b'<STR_LIT>' <EOL> iv , ciphertext = symmetric . rc2_cbc_pkcs5_encrypt ( key , data , None ) <EOL> self . assertNotEqual ( data , ciphertext ) <EOL> self . assertEqual ( byte_cls , type ( ciphertext ) ) <EOL> plaintext = symmetric . rc2_cbc_pkcs5_decrypt ( key , ciphertext , iv ) <EOL> self . assertEqual ( data , plaintext ) <EOL> def test_des_encrypt_decrypt ( self ) : <EOL> key = util . rand_bytes ( <NUM_LIT:8> ) <EOL> data = b'<STR_LIT>' <EOL> iv , ciphertext = symmetric . des_cbc_pkcs5_encrypt ( key , data , None ) <EOL> self . assertNotEqual ( data , ciphertext ) <EOL> self . assertEqual ( byte_cls , type ( ciphertext ) ) <EOL> plaintext = symmetric . des_cbc_pkcs5_decrypt ( key , ciphertext , iv ) <EOL> self . assertEqual ( data , plaintext ) <EOL> def test_3des_2k_encrypt_decrypt ( self ) : <EOL> key = util . rand_bytes ( <NUM_LIT:16> ) <EOL> data = b'<STR_LIT>' <EOL> iv , ciphertext = symmetric . tripledes_cbc_pkcs5_encrypt ( key , data , None ) <EOL> self . assertNotEqual ( data , ciphertext ) <EOL> self . assertEqual ( byte_cls , type ( ciphertext ) ) <EOL> plaintext = symmetric . tripledes_cbc_pkcs5_decrypt ( key , ciphertext , iv ) <EOL> self . assertEqual ( data , plaintext ) <EOL> def test_3des_3k_encrypt_decrypt ( self ) : <EOL> key = util . rand_bytes ( <NUM_LIT> ) <EOL> data = b'<STR_LIT>' <EOL> iv , ciphertext = symmetric . tripledes_cbc_pkcs5_encrypt ( key , data , None ) <EOL> self . assertNotEqual ( data , ciphertext ) <EOL> self . assertEqual ( byte_cls , type ( ciphertext ) ) <EOL> plaintext = symmetric . tripledes_cbc_pkcs5_decrypt ( key , ciphertext , iv ) <EOL> self . assertEqual ( data , plaintext ) </s>
