コード例 #1
0
def test_compressed_encrypt_then_decrypt_string():
    plaintext = "X" * 4096
    key = "this is my key"
    ciphertext = crypto.encrypt_string(plaintext, key, compress=True)
    assert_less(len(ciphertext), len(plaintext) / 10)
    plaintext_after = crypto.decrypt_string(ciphertext, key)
    assert_equal(plaintext, plaintext_after)
コード例 #2
0
def test_compressed_encrypt_then_decrypt_random_string():
    plaintext = os.urandom(1024 * 1024)
    key = "this is my key"
    ciphertext = crypto.encrypt_string(plaintext, key, compress=True)
    plaintext_after = crypto.decrypt_string(ciphertext, key)
    assert_equal(plaintext, plaintext_after)
コード例 #3
0
def test_encrypt_then_decrypt_empty_string():
    plaintext = ""
    key = "this is my key"
    ciphertext = crypto.encrypt_string(plaintext, key)
    plaintext_after = crypto.decrypt_string(ciphertext, key)
    assert_equal(plaintext_after, plaintext)
コード例 #4
0
def test_decrypt_with_wrong_password_raises_exception():
    plaintext = "this is some text"
    key = "this is my key"
    ciphertext = crypto.encrypt_string(plaintext, key)
    another_key = "this is my key 2"
    plaintext_after = crypto.decrypt_string(ciphertext, another_key)
コード例 #5
0
def test_decrypt_then_damage_raises_exception():
    plaintext = "this is some text"
    key = "this is my key"
    ciphertext = crypto.encrypt_string(plaintext, key)
    ciphertext = ciphertext[:len(ciphertext)-5]
    plaintext_after = crypto.decrypt_string(ciphertext, key)
コード例 #6
0
def test_encrypt_then_alter_raises_exception():
    plaintext = "this is some text"
    key = "this is my key"
    ciphertext = crypto.encrypt_string(plaintext, key)
    ciphertext = ciphertext[:-len(plaintext)] + '\0' * len(plaintext)
    plaintext_after = crypto.decrypt_string(ciphertext, key)
コード例 #7
0
def test_massive_encrypt_then_decrypt():
    plaintext = "X" * 50 * 1024 * 1024
    key = "this is my key"
    ciphertext = crypto.encrypt_string(plaintext, key)
    plaintext_after = crypto.decrypt_string(ciphertext, key)
    assert_equal(plaintext, plaintext_after)
コード例 #8
0
def test_ciphertext_not_repeated():
    plaintext = "this is some text"
    key = "this is my key"
    all_ciphertexts = [crypto.encrypt_string(plaintext, key) for i in xrange(100)]
    unique_ciphertexts = set(all_ciphertexts)
    assert_equal(len(unique_ciphertexts), len(all_ciphertexts))