Skip to content

Commit

Permalink
Fixed plaintext padding in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroferretti committed Feb 23, 2019
1 parent 28b1dbf commit 625b5a8
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions tests/rsatools_test.py
Expand Up @@ -28,8 +28,7 @@
import pytest
import random
from Crypto.PublicKey import RSA

from six import binary_type, int2byte
from six import binary_type, int2byte, b


def random_bytes(n):
Expand All @@ -48,7 +47,7 @@ def test_rsa_encrypt_decrypt(seed):
length = random.randrange(10, 255)
plaintext = random_bytes(length)
ciphertext = rsatools.rsa_encrypt(plaintext, e, n)
assert rsatools.rsa_decrypt(ciphertext, d, n) == plaintext
assert rsatools.rsa_decrypt(ciphertext, d, n).rjust(length, int2byte(0)) == plaintext


@pytest.mark.parametrize('seed', range(10))
Expand All @@ -59,7 +58,7 @@ def test_rsa_known_factors(seed):
plaintext = random_bytes(length)
ciphertext = rsatools.rsa_encrypt(plaintext, e, n)
d = rsatools.rsa_find_private_from_factors(p, q, e)
assert rsatools.rsa_decrypt(ciphertext, d, n) == plaintext
assert rsatools.rsa_decrypt(ciphertext, d, n).rjust(length, int2byte(0)) == plaintext


@pytest.mark.parametrize('seed', range(10))
Expand All @@ -69,7 +68,7 @@ def test_rsa_decrypt_cubic_root(seed):
length = random.randrange(10, 80) # 80 < 256 / 3
plaintext = random_bytes(length)
ciphertext = rsatools.rsa_encrypt(plaintext, e, n)
assert rsatools.rsa_decrypt_root(ciphertext, e) == plaintext
assert rsatools.rsa_decrypt_root(ciphertext, e).rjust(length, int2byte(0)) == plaintext


# TODO test common primes

0 comments on commit 625b5a8

Please sign in to comment.